Skip to content
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

Conversation

RussellJimmies
Copy link
Contributor

#29

Copy link
Member

@k-allagbe k-allagbe left a 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 Show resolved Hide resolved
]

MICROSCOPE_URL = os.getenv("MICROSCOPE_URL")
params = {"id": 6969}
Copy link
Member

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}")

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

microscope_info.py Outdated Show resolved Hide resolved
microscope_info.py Outdated Show resolved Hide resolved
microscope_info.py Outdated Show resolved Hide resolved
microscope_info.py Outdated Show resolved Hide resolved
microscope_info.py Outdated Show resolved Hide resolved
custom_exceptions.py Outdated Show resolved Hide resolved
microscope_info.py Outdated Show resolved Hide resolved
Copy link

@rngadam rngadam left a 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

@RussellJimmies RussellJimmies marked this pull request as draft January 16, 2024 21:48
@MaxenceGui
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Develop API to interface with Tagarno microscope API
4 participants