summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2025-10-11 10:46:46 +0300
committerA Farzat <a@farzat.xyz>2025-10-11 10:46:46 +0300
commit6c1506eb67d62f754ae80a44243c11191c818b22 (patch)
tree363a2f418d7e751406653e7fdb0b56ba6fd5cedd
parent9990217ce2794021693d88a852857dfad3d28e41 (diff)
downloadcsca5028-6c1506eb67d62f754ae80a44243c11191c818b22.tar.gz
csca5028-6c1506eb67d62f754ae80a44243c11191c818b22.zip
Add tests for APIs which fetch info
-rw-r--r--tests/integration/wsgi.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/integration/wsgi.py b/tests/integration/wsgi.py
index 4fbcd34..1f9ae70 100644
--- a/tests/integration/wsgi.py
+++ b/tests/integration/wsgi.py
@@ -65,5 +65,50 @@ class TestFlask(TestCase):
})
self.assertEqual(response.status_code, 409)
+ def test_subs_info(self) -> None:
+ # Should be empty at start.
+ response = self.client.get("/subs-info")
+ self.assertEqual(response.status_code, 200)
+ response_data = response.get_json()
+ self.assertListEqual(response_data, [])
+ # Fetching any individual subscription now should fail.
+ response = self.client.get("/sub-info/yt:channel:Ba659QWEk1AI4Tg--mrJ2A")
+ self.assertEqual(response.status_code, 404)
+ # Fetching the videos of an individual subscription should also fail.
+ response = self.client.get("/vid-from-link/yt:channel:Ba659QWEk1AI4Tg--mrJ2A")
+ self.assertEqual(response.status_code, 404)
+ # Now add some data to test on...
+ self.client.post("/add-sub/", data={
+ 'url': "https://www.youtube.com/channel/UCBa659QWEk1AI4Tg--mrJ2A",
+ 'time_between_fetches': 1,
+ })
+ self.client.post("/add-sub/", data={
+ 'url': "https://www.youtube.com/playlist?list=PLZHQObOWTQDMsr9K-rj53DwVRMYO3t5Yr",
+ 'time_between_fetches': 1,
+ })
+ # Now should contain 2 subscriptions.
+ response = self.client.get("/subs-info")
+ self.assertEqual(response.status_code, 200)
+ response_data = response.get_json()
+ self.assertEqual(len(response_data), 2)
+ for sub_info in response_data:
+ self.assertEqual(sub_info["videos"], 0)
+ # Now fetching an added subscriptions should work.
+ response = self.client.get("/sub-info/yt:channel:Ba659QWEk1AI4Tg--mrJ2A")
+ self.assertEqual(response.status_code, 200)
+ response_data = response.get_json()
+ self.assertEqual(response_data["_id"], "yt:channel:Ba659QWEk1AI4Tg--mrJ2A")
+ # Same for its videos - though they should still be empty.
+ response = self.client.get("/vid-from-link/yt:channel:Ba659QWEk1AI4Tg--mrJ2A")
+ self.assertEqual(response.status_code, 200)
+ response_data = response.get_json()
+ self.assertListEqual(response_data, [])
+ # Subscriptions not added should still not work.
+ response = self.client.get("/sub-info/yt:channel:7YOGHUfC1Tb6E4pudI9STA")
+ self.assertEqual(response.status_code, 404)
+ # Same for for their videos.
+ response = self.client.get("/vid-from-link/yt:channel:7YOGHUfC1Tb6E4pudI9STA")
+ self.assertEqual(response.status_code, 404)
+
def tearDown(self) -> None:
subscriptions.delete_many({})