-
Notifications
You must be signed in to change notification settings - Fork 1
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
SFR-1639/setUp_restApi_test #368
Conversation
@@ -1,7 +1,9 @@ | |||
# CHANGELOG |
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.
Were these intended?
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 only added the following line.
- implement restApi testing using pytest
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.
Do you have a changelog formatter installed?
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.
nope
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.
Ah ok all good. the extra newlines won't hurt anything.
tests/restApi/test_get_request.py
Outdated
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.
let's use snake case throughout naming.
Is this file name explicit enough?
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 will change it to snake case
and change the test file to test_singel_collection_get_request.py
If that's cool
tests/restApi/test_get_request.py
Outdated
response = requests.get(url) | ||
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}" |
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.
For readability, I recommend using the following format. By separating the chunks with new lines, it's easier to parse.
test setup
api call under test
assertions/expectations
tests/restApi/test_get_request.py
Outdated
response = requests.get(url) | ||
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}" | ||
|
||
# Parse the JSON response |
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.
are these comments necessary?
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.
can remove. I put it for my own readability
tests/restApi/test_get_request.py
Outdated
data = response.json() | ||
|
||
# Validate "numberOfItems" is 2 | ||
assert data.get('metadata', {}).get('numberOfItems') == 2, f"Expected 'numberOfItems' to be 2, but got {data.get('metadata', {}).get('numberOfItems')}" |
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.
What happens if the numberOfItems
changes?
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 haven't started UPDATE calls yet. Will be addressed in future PRs
For now it won't change as I have created this collection only for testing
tests/restApi/test_get_request.py
Outdated
assert data.get('metadata', {}).get('numberOfItems') == 2, f"Expected 'numberOfItems' to be 2, but got {data.get('metadata', {}).get('numberOfItems')}" | ||
|
||
# Validate the first title is "New Mexico magazine " | ||
first_publication_title = data.get('publications', [])[0].get('metadata', {}).get('title') |
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.
What happens if the first publication changes?
tests/restApi/test_get_request.py
Outdated
assert actual_title == expected_title, f"Expected title '{expected_title}', but got '{actual_title}'" | ||
|
||
|
||
def test_validate_json_fields(): |
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.
Could we just simply have 1 test with our expectations for a GET request that returns successfully?
f"Response text: {response.text[:100]}..." | ||
) | ||
|
||
data = response.json() |
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.
Let's add an assertion to check this is not null
This pr does the following