Skip to content

Commit

Permalink
test: For updates in create collection rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Sep 10, 2024
1 parent 8118b77 commit b6ca7c5
Showing 1 changed file with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,16 @@ def test_create_library_collection(self):
"""
Test creating a Content Library Collection
"""
post_data = {
"key": "COL4",
post_data = {
"title": "Collection 4",
"description": "Description for Collection 4",
}
resp = self.client.post(
URL_LIB_COLLECTIONS.format(lib_key=self.lib1.library_key), post_data, format="json"
)

# Check that the new Content Library Collection is returned in response and created in DB
assert resp.status_code == 200
post_data["key"] = 'collection-4'
self.assertDictContainsEntries(resp.data, post_data)

created_collection = Collection.objects.get(id=resp.data["id"])
Expand All @@ -182,8 +181,7 @@ def test_create_library_collection(self):
self._add_user_by_email(self.lib1.library_key, reader.email, access_level="read")

with self.as_user(reader):
post_data = {
"key": "COL5",
post_data = {
"title": "Collection 5",
"description": "Description for Collection 5",
}
Expand All @@ -193,6 +191,31 @@ def test_create_library_collection(self):

assert resp.status_code == 403

def test_create_collection_same_key(self):
"""
Test collection creation with same key
"""
post_data = {
"title": "Same Collection",
"description": "Description for Collection 4",
}
self.client.post(
URL_LIB_COLLECTIONS.format(lib_key=self.lib1.library_key), post_data, format="json"
)

for i in range(0, 100):
resp = self.client.post(
URL_LIB_COLLECTIONS.format(lib_key=self.lib1.library_key), post_data, format="json"
)
expected_data = {
"key": f"same-collection-{i + 1}",
"title": "Same Collection",
"description": "Description for Collection 4",
}

assert resp.status_code == 200
self.assertDictContainsEntries(resp.data, expected_data)

def test_create_invalid_library_collection(self):
"""
Test creating an invalid Content Library Collection
Expand Down

0 comments on commit b6ca7c5

Please sign in to comment.