Commit 8fa8b209 by David Ormsbee

Remove query counts from Bookmarks HTTP API tests.

Query counts already happen at the model and Python API test layers.
Having query counts in the HTTP API tests makes things more brittle
because that includes middleware that this code should not be aware
of. We don't want to have to revisit these tests every time
another piece of middleware is added or removed.
parent be25bb8a
......@@ -95,13 +95,11 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
if check_all_fields:
query_parameters += '&fields=path,display_name'
with self.assertNumQueries(12): # 2 queries for bookmark table.
response = self.send_get(
client=self.client,
url=reverse('bookmarks'),
query_parameters=query_parameters,
)
bookmarks_data = response.data['results']
self.assertEqual(len(bookmarks_data), len(bookmarks))
......@@ -138,13 +136,11 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
page_size = 5
query_parameters = 'course_id={}&page_size={}'.format(urllib.quote(unicode(course.id)), page_size)
with self.assertNumQueries(12): # 2 queries for bookmark table.
response = self.send_get(
client=self.client,
url=reverse('bookmarks'),
query_parameters=query_parameters
)
bookmarks_data = response.data['results']
# Pagination assertions.
......@@ -171,7 +167,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
Test that requesting bookmarks with invalid data returns 0 records.
"""
# Invalid course id.
with self.assertNumQueries(10): # No queries for bookmark table.
response = self.send_get(
client=self.client,
url=reverse('bookmarks'),
......@@ -188,8 +183,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
Test that requesting bookmarks returns all records for that user.
"""
# Without course id we would return all the bookmarks for that user.
with self.assertNumQueries(12): # 2 queries for bookmark table.
response = self.send_get(
client=self.client,
url=reverse('bookmarks')
......@@ -214,15 +207,12 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
Test that an anonymous client (not logged in) cannot call GET or POST.
"""
query_parameters = 'course_id={}'.format(self.course_id)
with self.assertNumQueries(7): # No queries for bookmark table.
self.send_get(
client=self.anonymous_client,
url=reverse('bookmarks'),
query_parameters=query_parameters,
expected_status=401
)
with self.assertNumQueries(4): # No queries for bookmark table.
self.send_post(
client=self.anonymous_client,
url=reverse('bookmarks'),
......@@ -234,7 +224,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
"""
Test that posting a bookmark successfully returns newly created data with 201 code.
"""
with self.assertNumQueries(19):
response = self.send_post(
client=self.client,
url=reverse('bookmarks'),
......@@ -258,7 +247,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
3) With empty request.data
"""
# Send usage_id with invalid format.
with self.assertNumQueries(10): # No queries for bookmark table.
response = self.send_post(
client=self.client,
url=reverse('bookmarks'),
......@@ -268,7 +256,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
self.assertEqual(response.data['user_message'], u'An error has occurred. Please try again.')
# Send data without usage_id.
with self.assertNumQueries(6): # No queries for bookmark table.
response = self.send_post(
client=self.client,
url=reverse('bookmarks'),
......@@ -293,7 +280,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
"""
Test that posting a bookmark for a block that does not exist returns a 400.
"""
with self.assertNumQueries(10): # No queries for bookmark table.
response = self.send_post(
client=self.client,
url=reverse('bookmarks'),
......@@ -317,7 +303,6 @@ class BookmarksListViewTests(BookmarksViewsTestsBase):
max_bookmarks = settings.MAX_BOOKMARKS_PER_COURSE
__, blocks, __ = self.create_course_with_bookmarks_count(max_bookmarks)
with self.assertNumQueries(11): # No queries for bookmark table.
response = self.send_post(
client=self.client,
url=reverse('bookmarks'),
......@@ -397,7 +382,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that requesting bookmark returns data with 200 code.
"""
with self.assertNumQueries(11): # 1 query for bookmark table.
response = self.send_get(
client=self.client,
url=reverse(
......@@ -414,7 +398,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that requesting bookmark that belongs to other user returns 404 status code.
"""
with self.assertNumQueries(11): # No queries for bookmark table.
self.send_get(
client=self.client,
url=reverse(
......@@ -428,7 +411,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that requesting bookmark that does not exist returns 404 status code.
"""
with self.assertNumQueries(11): # 1 query for bookmark table.
response = self.send_get(
client=self.client,
url=reverse(
......@@ -450,7 +432,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that requesting bookmark with invalid usage id returns 400.
"""
with self.assertNumQueries(10): # No queries for bookmark table.
response = self.send_get(
client=self.client,
url=reverse(
......@@ -466,14 +447,11 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
Test that an anonymous client (not logged in) cannot call GET or DELETE.
"""
url = reverse('bookmarks_detail', kwargs={'username': self.user.username, 'usage_id': 'i4x'})
with self.assertNumQueries(7): # No queries for bookmark table.
self.send_get(
client=self.anonymous_client,
url=url,
expected_status=401
)
with self.assertNumQueries(4):
self.send_delete(
client=self.anonymous_client,
url=url,
......@@ -489,7 +467,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
bookmarks_data = response.data['results']
self.assertEqual(len(bookmarks_data), 2)
with self.assertNumQueries(9): # 2 queries for bookmark table.
self.send_delete(
client=self.client,
url=reverse(
......@@ -506,7 +483,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that delete bookmark that belongs to other user returns 404.
"""
with self.assertNumQueries(11): # No queries for bookmark table.
self.send_delete(
client=self.client,
url=reverse(
......@@ -520,7 +496,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that delete bookmark that does not exist returns 404.
"""
with self.assertNumQueries(11): # 1 query for bookmark table.
response = self.send_delete(
client=self.client,
url=reverse(
......@@ -542,7 +517,6 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
Test that delete bookmark with invalid usage id returns 400.
"""
with self.assertNumQueries(10): # No queries for bookmark table.
response = self.send_delete(
client=self.client,
url=reverse(
......@@ -559,8 +533,5 @@ class BookmarksDetailViewTests(BookmarksViewsTestsBase):
"""
url = reverse('bookmarks_detail', kwargs={'username': self.user.username, 'usage_id': 'i4x'})
self.client.login(username=self.user.username, password=self.TEST_PASSWORD)
with self.assertNumQueries(11): # No queries for bookmark table.
self.assertEqual(405, self.client.put(url).status_code)
with self.assertNumQueries(7):
self.assertEqual(405, self.client.post(url).status_code)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment