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 931ac49
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/exporter/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@
class ViewsTests(TestCase):
def test_download_export_invalid_suffix(self):
with self.assertNumQueries(0):
response = Client().get("/api/download_export?suffix=invalid")
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(0):
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")
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")
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 @@ -46,7 +44,7 @@ def test_download_export_completed(self):
with self.subTest(suffix=suffix):
with self.assertNumQueries(0):
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 931ac49

Please sign in to comment.