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

Product API refactor #90

Merged
merged 18 commits into from
Mar 10, 2024
Merged

Product API refactor #90

merged 18 commits into from
Mar 10, 2024

Conversation

yanazPL
Copy link
Contributor

@yanazPL yanazPL commented Mar 9, 2024

Pagination for products ViewSet has been added and tested.

ProductViewSet is now read-only - behavior has been tested.

pytest.ini settings force pagination with size 5 right now.

Collection of fixtures: for login and for data has been added - some were improved.

@yanazPL yanazPL requested a review from jacoor March 9, 2024 17:36
Copy link
Contributor

@jacoor jacoor left a comment

Choose a reason for hiding this comment

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

Good job, small changes needed.

Dshop/apps/products_catalogue/tests/test_api_products.py Outdated Show resolved Hide resolved
Dshop/apps/products_catalogue/tests/test_api_products.py Outdated Show resolved Hide resolved


def test_pagination_size_in_tests():
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove fixture since we moved to settings_tests.

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 want to know if settings_tests are changed. So we know the cause of test's failures

@pytest.mark.django_db
def test_product_detail(tv_product):
url = reverse('products-api-detail', kwargs={'pk': tv_product.id})
response = APIClient().get(url)
Copy link
Contributor

Choose a reason for hiding this comment

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

After this change, this test is only checking response code, not details. Please bring back ID and other details tests - the one removed. Or use a function to test product details.
Testing just response code is not enough.
Actually, this test_product_detail_with_images test, after changing to not authenticated user, would make the current one test not needed no? They both check the same thing.

Copy link
Contributor Author

@yanazPL yanazPL Mar 10, 2024

Choose a reason for hiding this comment

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

Assert added. Also test_product_detail_with_images doesn't need authentication any more.

I still think it may be beneficial to have separate tests for image related behavior and general object retrieve.
Especially since separate tests are already there. They don't overlap.

Dshop/apps/products_catalogue/tests/test_api_products.py Outdated Show resolved Hide resolved
return APIClient()

@pytest.fixture
def api_client_authed():
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please change to full name? api_client_authenticated? It makes it more readable.
Also, the previous fixture, authenticated_api_client - why it is not used anymore? Seemed ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

authenticated_api_client caused integrity error - unique constraint violated in this place.
With my fixture test passed.

Also my fixture is simpler - no playing with Token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also authenticated_api_client (old) is not located in a good place. It's hard to share it across different apps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding fixtures --> there is little bit of mess here.

There are knop-k's fixtures:
create_active_product
create_inactive_product

mkrzminski's:
tv_product

my:
inactive_product

Also there are:
api_client (bare) in Dshop/conftest.py
api_client (authed)Dshop/apps/products_catalogue/tests/conftest.py

yours
products in Dshop/apps/products_catalogue/tests/conftest.py

mine:
ten_tv_products in Dshop/conftest.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need ALWAYS to check existing fixtures before creating new ones

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, so what is your final response? I see a lot of text, but I don't see anything actionable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reponse is:
I'll change name.
I'd like to remove old authenticated_api_client fixture

I'm asking what to do about other duplicated fixtures (probably in new PR)

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove not needed code, new pr is ok.

jacoor
jacoor previously approved these changes Mar 10, 2024
@yanazPL yanazPL merged commit a8e760b into dev Mar 10, 2024
2 checks passed
@yanazPL yanazPL deleted the refactor/api-products-catalogue branch March 10, 2024 18:47
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.

3 participants