Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed Aug 17, 2024
1 parent 455b45f commit 0ca37c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wp1/credentials.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 34 additions & 0 deletions wp1/scores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0ca37c1

Please sign in to comment.