From 0ca37c1957a798a257016b29a8224ef7d6f2b8f7 Mon Sep 17 00:00:00 2001 From: Travis Briggs Date: Sat, 17 Aug 2024 13:18:09 -0700 Subject: [PATCH] Add more tests --- wp1/credentials.py.example | 5 +++++ wp1/scores_test.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/wp1/credentials.py.example b/wp1/credentials.py.example index 2241d668..e15c4af9 100644 --- a/wp1/credentials.py.example +++ b/wp1/credentials.py.example @@ -178,6 +178,11 @@ CREDENTIALS = { 'password': 'farmpass', 'hook_token': 'hook-token-abc', } + + 'FILE_PATH': { + # Path where pageviews.bz2 file (~3GB) will be downloaded. + 'pageviews': '/tmp/pageviews', + } }, # EDIT: Remove the next line after you've provided actual production credentials. diff --git a/wp1/scores_test.py b/wp1/scores_test.py index 40ccc19f..ff796560 100644 --- a/wp1/scores_test.py +++ b/wp1/scores_test.py @@ -226,3 +226,37 @@ def test_update_db_pageviews_existing(self): self.assertEqual(result['ps_article'], b'Statue_of_Liberty') self.assertEqual(result['ps_page_id'], 1234) self.assertEqual(result['ps_views'], 200) + + @patch('wp1.scores.download_pageviews') + @patch('wp1.scores.pageview_components') + def test_update_pageviews(self, mock_components, mock_download): + mock_components.return_value = ( + (b'en', b'Statue_of_Liberty', 100, 100), + (b'en', b'Eiffel_Tower', 200, 200), + (b'fr', b'George-\xc3\x89tienne_Cartier_Monument', 300, 300), + ) + + scores.update_pageviews() + + mock_download.assert_called_once() + with self.wp10db.cursor() as cursor: + cursor.execute('SELECT COUNT(*) as cnt FROM page_scores') + n = cursor.fetchone()['cnt'] + self.assertEqual(3, n) + + @patch('wp1.scores.download_pageviews') + @patch('wp1.scores.pageview_components') + def test_update_pageviews_filter(self, mock_components, mock_download): + mock_components.return_value = ( + (b'en', b'Statue_of_Liberty', 100, 100), + (b'en', b'Eiffel_Tower', 200, 200), + (b'fr', b'George-\xc3\x89tienne_Cartier_Monument', 300, 300), + ) + + scores.update_pageviews(filter_lang='fr') + + mock_download.assert_called_once() + with self.wp10db.cursor() as cursor: + cursor.execute('SELECT COUNT(*) as cnt FROM page_scores') + n = cursor.fetchone()['cnt'] + self.assertEqual(1, n)