예제 #1
0
 def test_filter_category_search_by_page(self, rf):
     """Test pagination of category filtering"""
     category_type = choice(CATEGORY_TYPES)[0]
     # Test the second page
     CategoryFactory.create_batch(26, category=category_type)
     request = rf.get(f"item/api/v1/category/{category_type}/", {"page": 2})
     response = search_category(request, category_type)
     assert response.status_code == 200
     data = json.loads(response.content)
     assert (
         len(data["data"]) == 1
     ), "The paginator should show only 1 organization since page size is 25."
예제 #2
0
    def test_filter_by_category(self, rf):
        category_type = CATEGORY_TYPES[0][0]
        # Created a random category just to make sure it wasn't jumbled in
        CategoryFactory.create(category=category_type + 1)
        categories = CategoryFactory.create_batch(3, category=category_type)
        request = rf.get(f"item/api/v1/category/{category_type}/")
        response = search_category(request, category_type)

        assert response.status_code == 200
        data = json.loads(response.content)
        assert len(data["data"]) == 3
        # Make sure the data is correct.
        _assert_org_list_eq(data["data"], categories)
예제 #3
0
 def test_error_on_invalid_category_type(self, rf, category_type):
     request = rf.get(f"item/api/v1/category/{category_type}/")
     # Error on 404 since typical user shouldn't really get this path.
     with pytest.raises(Http404):
         search_category(request, category_type)