diff options
| author | A Farzat <a@farzat.xyz> | 2025-10-12 08:04:44 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-10-12 08:24:06 +0300 |
| commit | 01c082ce9de0061eaac183ffc22f86e739a9484f (patch) | |
| tree | 207b2ce4ef0c7c8d91bcff75b01f4ad6fb0472c6 | |
| parent | e65ca281f59b47937f9cf5f1560d1f520efcac20 (diff) | |
| download | csca5028-01c082ce9de0061eaac183ffc22f86e739a9484f.tar.gz csca5028-01c082ce9de0061eaac183ffc22f86e739a9484f.zip | |
Add integration tests including collector and analyser
| -rw-r--r-- | tests/integration/integration.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/integration/integration.py b/tests/integration/integration.py new file mode 100644 index 0000000..e3b103c --- /dev/null +++ b/tests/integration/integration.py @@ -0,0 +1,47 @@ +from os import getenv +from unittest import TestCase + +from components.database import subscriptions +from data_analyser.utils import analyse_collection +from data_collector.utils import collect_data +from wsgi import app + +class TestIntegration(TestCase): + def setUp(self) -> None: + app.config['TESTING'] = True + self.client = app.test_client() + subscriptions.delete_many({}) + self.client.post("/add-sub/", data={ + 'url': "https://www.youtube.com/playlist?list=PLZmiPrHYOIsRtlMRPjLd5WhmM8BddIdj0", + 'time_between_fetches': 1, + }) + + def test_collection_and_analyses(self) -> None: + # Confirm that the playlist exists but there are not videos stored yet. + response = self.client.get("/vid-from-link/yt:playlist:PLZmiPrHYOIsRtlMRPjLd5WhmM8BddIdj0") + self.assertEqual(response.status_code, 200) + response_data = response.get_json() + self.assertListEqual(response_data, []) + + collect_data(subscriptions) + # Confirm that the videos now exist but are not analysed yet. + response = self.client.get("/vid-from-link/yt:playlist:PLZmiPrHYOIsRtlMRPjLd5WhmM8BddIdj0") + self.assertEqual(response.status_code, 200) + response_data = response.get_json() + self.assertEqual(len(response_data), 1) + for vid in response_data: + self.assertFalse(vid["analysed"]) + + self.assertEqual(1, analyse_collection(subscriptions, getenv("YOUTUBE_API_KEY") or '') +) + # Confirm that the videos now exist and has a valid duration. + response = self.client.get("/vid-from-link/yt:playlist:PLZmiPrHYOIsRtlMRPjLd5WhmM8BddIdj0") + self.assertEqual(response.status_code, 200) + response_data = response.get_json() + self.assertEqual(len(response_data), 1) + for vid in response_data: + self.assertTrue(vid["analysed"]) + self.assertGreaterEqual(vid["duration"], 0) + + def tearDown(self) -> None: + subscriptions.delete_many({}) |
