I have a simple FastAPI application that uses python-jenkins to make custom calls to our Jenkins instance.
Here are a couple of examples:
@app.get("/jenkins_data")
async def get_jenkins_nodes() -> list:
server = jenkins.Jenkins(url, user, key)
try:
nodes = server.get_nodes()
return get_nodes_and_states(nodes)
except jenkins.JenkinsException:
nodes = []
return nodes
Or I might have something like this:
@app.get("/job/{node_name}")
def get_current_jenkins_job(node_name: str) -> str:
server = jenkins.Jenkins(url, user, key)
node = server.get_node_info(f"{node_name}", 2)
if node["executors"][0]["currentExecutable"] is not None:
display_name = node["executors"][0]["currentExecutable"]["displayName"]
else:
display_name = "No Jobs Running"
return display_name
How do I go about mocking the Jenkin's object so I can properly test these methods with pytest? I want to write a test that causes Jenkins to raise jenkins.JenkinsException
in the first example or mock it to set the "currentExecutable" for the second.
Thanks!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745592705a4634926.html
评论列表(0条)