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

SFR-1639/setUp_restApi_test #368

Merged
merged 4 commits into from
Sep 17, 2024
Merged

SFR-1639/setUp_restApi_test #368

merged 4 commits into from
Sep 17, 2024

Conversation

ayan1229
Copy link
Contributor

This pr does the following

  • intoduces restApi testing in QA ennvironment
  • validates response for GET request for a collection
  • validates the collection name and titles within the collection

@@ -1,7 +1,9 @@
# CHANGELOG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these intended?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 9 to 10
response = requests.get(url)
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}"
Copy link
Contributor

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

response = requests.get(url)
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}"

# Parse the JSON response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these comments necessary?

Copy link
Contributor Author

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

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')}"
Copy link
Contributor

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?

Copy link
Contributor Author

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

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')
Copy link
Contributor

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?

assert actual_title == expected_title, f"Expected title '{expected_title}', but got '{actual_title}'"


def test_validate_json_fields():
Copy link
Contributor

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()
Copy link
Contributor

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

@ayan1229 ayan1229 merged commit 8fa20a8 into main Sep 17, 2024
2 checks passed
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.

2 participants