Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yolile committed Nov 3, 2023
1 parent 2bc86a5 commit f687d82
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions tests/exporter/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@
@override_settings(EXPORTER_DIR=os.path.join("tests", "fixtures"))
class ViewsTests(TestCase):
def test_download_export_invalid_suffix(self):
with self.assertNumQueries(0):
response = Client().get("/api/download_export?suffix=invalid")
with self.assertNumQueries(1):
response = Client().get("/publication/1/download?name=invalid")

self.assertEqual(response.status_code, 400)
self.assertEqual(response.content, b"Suffix not recognized")

def test_download_export_empty_parameter(self):
for parameter in ("job_id", "year"):
with self.subTest(parameter=parameter):
with self.assertNumQueries(0):
response = Client().get(f"/api/download_export?suffix=jsonl.gz&{parameter}=")
with self.assertNumQueries(1):
response = Client().get("/publication/1/download?name=")

self.assertEqual(response.status_code, 404)
self.assertEqual(response.content, b"File not found")
self.assertEqual(response.status_code, 404)
self.assertEqual(response.content, b"File not found")

def test_download_export_waiting(self):
with self.assertNumQueries(0):
response = Client().get("/api/download_export?suffix=jsonl.gz&year=2000&job_id=0")
with self.assertNumQueries(1):
response = Client().get("/publication/1/download?name=2000.jsonl.gz")

self.assertEqual(response.status_code, 404)
self.assertEqual(response.content, b"File not found")

@patch("exporter.util.Export.lockfile", new_callable=PropertyMock)
def test_download_export_running(self, exists):
with self.assertNumQueries(0):
response = Client().get("/api/download_export?suffix=jsonl.gz&year=2000&job_id=1")
with self.assertNumQueries(1):
response = Client().get("/publication/1/download?name=2000.jsonl.gz")

self.assertEqual(response.status_code, 404)
self.assertEqual(response.content, b"File not found")
Expand All @@ -44,9 +42,9 @@ def test_download_export_completed(self):
("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
):
with self.subTest(suffix=suffix):
with self.assertNumQueries(0):
with self.assertNumQueries(1):
response = Client().get(
f"/api/download_export?suffix={suffix}&year=2000&job_id=1&spider=abc",
f"/publication/1/download?name=2000.{suffix}",
HTTP_ACCEPT_ENCODING="gzip",
)

Expand Down

0 comments on commit f687d82

Please sign in to comment.