-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #29: Module that retrieves microscope config from Tagarno Open API #44
Issue #29: Module that retrieves microscope config from Tagarno Open API #44
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean code overall and does the job. Just few things to improve testability.
Don't forget to unit test your file.
microscope_info.py
Outdated
] | ||
|
||
MICROSCOPE_URL = os.getenv("MICROSCOPE_URL") | ||
params = {"id": 6969} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest passing the id to the get_microscope_configuration
function as an argument. Then you could do:
if __name__ == "__main__":
try:
microscope_id = 6969
config = get_microscope_configuration(microscope_id)
if config:
print(config)
except OpenApiError as e:
print(f"Error: {e}")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the microscope's ID, it's just an int that indentifies the request. As discussed, I'm generating a UUID instead of a hard-coded value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. In that case, I would create the id on the fly inside the post_request
function.
Example:
def post_request(microscope_url, method, headers=HEADERS):
id = int(uuid.uuid4())
url = f"{microscope_url}?jsonrpc=2.0&method={method}&id={id}"
data = json.dumps({
"jsonrpc": "2.0",
"method": method,
"id": id,
})
...
And if the id's purpose is for verification, then maybe check that the response's id matches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, function parameters are usually lowercase. Same for def get_microscope_configuration(METHODS):. Not a problem per se, but could be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this should be a draft for now?
missing unit tests
Work continue on |
#29