Пример #1
0
 def test_router_get_subresource_not_found(db_session):
     """Test getting an identified subresource fails with bad id."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(ResourceNotFoundError):
         router.get(path="/albums/1/tracks/1000000",
                    query_params=query_params)
Пример #2
0
 def test_router_subquery_parse_error(db_session):
     """Test a get with bad subquery params raises an error."""
     query_params = {"tracks._subquery_": 5}
     resource = AlbumResource(session=db_session)
     router = ModelResourceRouter(session=db_session, resource=resource)
     with raises(BadRequestError):
         router.get(path="/album/1", query_params=query_params)
Пример #3
0
 def test_router_query_filter_parse_error(db_session):
     """Test a get with bad query filters raises an error."""
     resource = AlbumResource(session=db_session)
     query_params = {"query": "[}"}
     router = ModelResourceRouter(session=db_session, resource=resource)
     with raises(BadRequestError):
         router.get(path="/albums", query_params=query_params)
Пример #4
0
 def test_router_get_empty_non_list_child(db_session):
     """Test getting an empty many to one fails."""
     resource = EmployeeResource(session=db_session)
     router = ModelResourceRouter(session=db_session, resource=resource)
     # note that employee 1 has no manager...
     with raises(ResourceNotFoundError):
         router.get(path="/employees/1/manager")
Пример #5
0
 def test_router_get_subresource_attr_not_found(db_session):
     """Test getting a subresource attr fails with bad attr name."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(ResourceNotFoundError):
         router.get(path="/albums/1/tracks/14/dne",
                    query_params=query_params)
Пример #6
0
 def test_router_get_subresource_attr(db_session):
     """Test getting an identified subresource attr works."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks/14/name",
                         query_params=query_params)
     assert result == "Spellbound"
Пример #7
0
 def test_router_get_subresource_collection_ordered(db_session):
     """Test getting an ordered subresource collection via router."""
     query_params = {"sort": "-track_id,name"}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     assert len(result) == 10
     assert result[0]["track_id"] == 14
Пример #8
0
 def test_router_get_resource_collection_first_page(db_session):
     """Test getting the first page of a resource collection."""
     query_params = {"sort": "album_id", "limit": 30}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums", query_params=query_params)
     assert len(result) == 30
     assert result[0]["album_id"] == 1
Пример #9
0
 def test_router_get_subresource_collection_second_page(db_session):
     """Test getting the second page of a subresource collection."""
     query_params = {"sort": "track_id", "limit": 5, "page": "2"}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     assert len(result) == 5
     assert result[0]["track_id"] == 10
Пример #10
0
 def test_router_get_resource_collection_ordered(db_session):
     """Test getting an ordered resource collection via a router."""
     query_params = {"sort": "-album_id,title"}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums", query_params=query_params)
     assert len(result) == 347
     assert result[0]["album_id"] == 347
Пример #11
0
 def test_router_get_subresource_only_child(self):
     """Test getting an only child subresource works."""
     query_params = {}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/artist", query_params=query_params)
     self.assertTrue(
         result["artist_id"] == 1
     )
Пример #12
0
 def test_router_get_subresource_collection_offset_no_strict(db_session):
     """Providing a bad offset subresource query_param ignored."""
     query_params = {"offset": "test"}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks",
                         query_params=query_params,
                         strict=False)
     assert result[0]["track_id"] == 1
Пример #13
0
 def test_router_get_attr(self):
     """Test getting an identified resource attr works."""
     query_params = {}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/title", query_params=query_params)
     self.assertTrue(
         result == "For Those About To Rock We Salute You"
     )
Пример #14
0
 def test_router_get_subresource(self):
     """Test getting an identified subresource works."""
     query_params = {}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/tracks/14", query_params=query_params)
     self.assertTrue(
         result["track_id"] == 14
     )
Пример #15
0
 def test_router_subquery_parse_error_ignore(db_session):
     """Test bad subquery params are ignored (non strict)."""
     query_params = {"tracks._subquery_": 5}
     resource = AlbumResource(session=db_session)
     router = ModelResourceRouter(session=db_session, resource=resource)
     result = router.get(path="/album/1",
                         query_params=query_params,
                         strict=False)
     assert result.get("album_id") == 1
Пример #16
0
 def test_router_get_subresource_attr(self):
     """Test getting an identified subresource attr works."""
     query_params = {}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/tracks/14/name",
                         query_params=query_params)
     self.assertTrue(
         result == "Spellbound"
     )
Пример #17
0
 def test_router_query_filter_parse_error_ignore(db_session):
     """Test a get with bad query filters is ignored (non strict)."""
     resource = AlbumResource(session=db_session)
     query_params = {"query": "[}"}
     router = ModelResourceRouter(session=db_session, resource=resource)
     result = router.get(path="/albums",
                         query_params=query_params,
                         strict=False)
     assert len(result) == 347
Пример #18
0
 def test_router_get_resource_collection_ordered(self):
     """Test getting an ordered resource collection via a router."""
     query_params = {
         "sort": "-album_id,title"
     }
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums", query_params=query_params)
     self.assertTrue(
         len(result) == 347 and
         result[0]["album_id"] == 347)
Пример #19
0
 def test_router_get_subresource_collection_ordered(self):
     """Test getting an ordered subresource collection via router."""
     query_params = {
         "sort": "-track_id,name"
     }
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     self.assertTrue(
         len(result) == 10 and
         result[0]["track_id"] == 14)
Пример #20
0
 def test_router_get_subresource_collection_first_page(self):
     """Test getting the first page of a subresource collection."""
     query_params = {
         "sort": "track_id",
         "limit": 5
     }
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     self.assertTrue(
         len(result) == 5 and
         result[0]["track_id"] == 1)
Пример #21
0
 def test_router_get_resource_collection_second_page(self):
     """Test getting the second page of a resource collection."""
     query_params = {
         "sort": "album_id",
         "limit": 30,
         "page": "2"
     }
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums", query_params=query_params)
     self.assertTrue(
         len(result) == 30 and
         result[0]["album_id"] == 31)
Пример #22
0
 def test_router_get_collection_filtered(db_session):
     """Test getting a resource collection via a router works."""
     query_params = {
         "album_id-lt": "10",
         "title-like": "Big",
         "album_id-gt": 4,
         "album_id-gte": 5,
         "album_id-lte": 5,
         "album_id-eq": 5,
         "album_id": 5,
         "album_id-ne": 6,
         "query": json.dumps({"title": "Big Ones"})
     }
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums", query_params=query_params)
     assert len(result) == 1
     assert result[0]["album_id"] == 5
Пример #23
0
 def test_router_get_subresource_collection_filtered(db_session):
     """Test getting a subresource collection via a router works."""
     query_params = {
         "track_id-lt": "10",
         "name-like": "Finger",
         "track_id-gt": 5,
         "track_id-gte": 6,
         "track_id-lte": 6,
         "track_id-eq": 6,
         "track_id": 6,
         "track_id-ne": 7,
         "query": json.dumps({"name": "Put The Finger On You"})
     }
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     assert len(result) == 1
     assert result[0]["track_id"] == 6
Пример #24
0
 def test_router_get_subresource_collection_filtered(self):
     """Test getting a subresource collection via a router works."""
     query_params = {
         "track_id-lt": "10",
         "name-like": "Finger",
         "track_id-gt": 5,
         "track_id-gte": 6,
         "track_id-lte": 6,
         "track_id-eq": 6,
         "track_id": 6,
         "track_id-ne": 7,
         "query": json.dumps({"name": "Put The Finger On You"})
     }
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     self.assertTrue(
         len(result) == 1 and
         result[0]["track_id"] == 6
     )
Пример #25
0
 def test_router_get_collection_filtered(self):
     """Test getting a resource collection via a router works."""
     query_params = {
         "album_id-lt": "10",
         "title-like": "Big",
         "album_id-gt": 4,
         "album_id-gte": 5,
         "album_id-lte": 5,
         "album_id-eq": 5,
         "album_id": 5,
         "album_id-ne": 6,
         "query": json.dumps({"title": "Big Ones"})
     }
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums", query_params=query_params)
     self.assertTrue(
         len(result) == 1 and
         result[0]["album_id"] == 5
     )
Пример #26
0
 def test_router_get_composite_bad_id(db_session):
     """Test too few identifiers on a composite key fails."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(ResourceNotFoundError):
         router.get(path="/compositeNode/1", query_params=query_params)
Пример #27
0
 def test_router_get_resource_collection_offset_fail(db_session):
     """Providing a bad offset query_param fails via a router."""
     query_params = {"offset": "test"}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(BadRequestError):
         router.get(path="/albums", query_params=query_params)
Пример #28
0
 def test_router_get_attr_extra_part(db_session):
     """Test getting an attr fails with an extra path part."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(ResourceNotFoundError):
         router.get(path="/albums/1/title/bad", query_params=query_params)
Пример #29
0
 def test_router_get_attr(db_session):
     """Test getting an identified resource attr works."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/title", query_params=query_params)
     assert result == "For Those About To Rock We Salute You"
Пример #30
0
 def test_router_get_resource_collection_offset(self):
     """Providing an offset query_param works via a router."""
     query_params = {"offset": "1"}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums", query_params=query_params)
     self.assertTrue(result[0]["album_id"] == 2)
Пример #31
0
 def test_router_get_resource_collection_limit_no_strict(self):
     """Providing a bad limit query_param ignored via a router."""
     query_params = {"limit": "abcd"}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums", query_params=query_params, strict=False)
     self.assertTrue(result[0]["album_id"] == 1)
Пример #32
0
 def test_router_get_subresource(db_session):
     """Test getting an identified subresource works."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks/14", query_params=query_params)
     assert result["track_id"] == 14
Пример #33
0
 def test_router_get_subresource_only_child(db_session):
     """Test getting an only child subresource works."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/artist", query_params=query_params)
     assert result["artist_id"] == 1
Пример #34
0
 def test_router_get_composite(db_session):
     """Test getting a resource with a composite key works."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/compositeNode/1/1", query_params=query_params)
     assert result["composite_id"] == 1
Пример #35
0
 def test_router_get_path_after_missing(db_session):
     """Test a path with a part after an unfound instance fails."""
     resource = AlbumResource(session=db_session)
     router = ModelResourceRouter(session=db_session, resource=resource)
     with raises(ResourceNotFoundError):
         router.get(path="/albums/9999999/tracks/")
Пример #36
0
 def test_router_get_subresource_collection_offset_no_strict(self):
     """Providing a bad offset subresource query_param ignored."""
     query_params = {"offset": "abcd"}
     router = ModelResourceRouter(session=self.db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params, strict=False)
     self.assertTrue(result[0]["track_id"] == 1)
Пример #37
0
 def test_router_get_subresource_collection_limit_fail(db_session):
     """Providing a bad limit subresource query_param fails."""
     query_params = {"limit": "test"}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(BadRequestError):
         router.get(path="/albums/1/tracks", query_params=query_params)
Пример #38
0
 def test_router_get_resource_collection_limit_no_strict(db_session):
     """Providing a bad limit query_param ignored via a router."""
     query_params = {"limit": "test"}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums", query_params=query_params, strict=False)
     assert result[0]["album_id"] == 1
Пример #39
0
 def test_router_get_subresource_collection_offset(db_session):
     """Providing an offset subresource query_param works."""
     query_params = {"offset": "1"}
     router = ModelResourceRouter(session=db_session, context={})
     result = router.get("/albums/1/tracks", query_params=query_params)
     assert result[0]["track_id"] == 6
Пример #40
0
 def test_router_get_subresource_collection_bad_page_fail(db_session):
     """Providing a bad subresource page fails via a router."""
     query_params = {"page": "2"}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(BadRequestError):
         router.get(path="/albums/1/tracks", query_params=query_params)
Пример #41
0
 def test_router_get_path_parts_too_long(db_session):
     """Test a path with a part after an attr fails."""
     resource = AlbumResource(session=db_session)
     router = ModelResourceRouter(session=db_session, resource=resource)
     with raises(ResourceNotFoundError):
         router.get(path="/albums/1/album_id/toolong")
Пример #42
0
 def test_router_get_subresource_only_child_not_found(db_session):
     """Test getting only child subresource fails when not found."""
     query_params = {}
     router = ModelResourceRouter(session=db_session, context={})
     with raises(ResourceNotFoundError):
         router.get("/employees/1/parent", query_params=query_params)