Page MenuHomePhabricator

[Recurring] Unit tests for the awmd-stats tool
Open, Needs TriagePublic

Description

This task is about a tool at https://tools.wmflabs.org/awmd-stats/ running on Toolforge:

Unit tests are scripts to test the functionality of the Awmd Stats tool.

All methods of the codebase should be tested so that tests coverage can be 100%.

For now ~10 methods are yet to be covered by tests.

A GCI student should choose two methods and add a comment here in https://phabricator.wikimedia.org/T205450 which two methods the student will work on (so another student does not work on the same methods!)

To add a comment here you need a Phabricator account (see https://www.mediawiki.org/wiki/Phabricator/Help#Creating_your_account ) and for a Phabricator account you will need a Wikimedia account (if you do not have a Wikimedia account yet, go to https://www.mediawiki.org and click the "Create account" link at the top).

You are expected to provide a patch in Wikimedia Gerrit. See https://www.mediawiki.org/wiki/Gerrit/Tutorial for how to set up Git and Gerrit.

GCI Criteria
2 tests = one GCI task instance

Related Objects

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 25 2018, 3:51 PM
samuelguebo updated the task description. (Show Details)Sep 25 2018, 3:51 PM
Aklapper updated the task description. (Show Details)Oct 3 2018, 6:39 PM

Change 473183 had a related patch set uploaded (by Rafidaslam; owner: Rafid Aslam):
[labs/tools/awmd-stats@master] test_utils: Add tests for incrementMonth and monthToDate

https://gerrit.wikimedia.org/r/473183

Change 473183 merged by jenkins-bot:
[labs/tools/awmd-stats@master] test_utils: Add tests for incrementMonth and monthToDate

https://gerrit.wikimedia.org/r/473183

Arcayn added a subscriber: Arcayn.Nov 18 2018, 9:12 PM

Add tests for decrementMonth and getDb

Change 474555 had a related patch set uploaded (by Arcayn; owner: Arcayn):
[labs/tools/awmd-stats@master] Add tests for decrementMonth and getDb

https://gerrit.wikimedia.org/r/474555

Change 474555 merged by jenkins-bot:
[labs/tools/awmd-stats@master] Add tests for decrementMonth() and getDb() methods

https://gerrit.wikimedia.org/r/474555

Stibba added a subscriber: Stibba.Dec 10 2018, 1:47 AM

Hi,
I wanted to add tests but I got somewhat confused because testGetContributors was added however it looks to me like it's testing getStatsFromDb instead of getContributors, or am I missing something?

Hey @Stibba,
You have it all right. For now testGetContributors isn't performing what it's intended, it only test getStatsFromDb. You should alter the method, add what's missing, so that it tests getContributors.

What's the way forward of this per its parent T202231. We're already having 93% for app.py and 98% for utils.py and 100% for others but 0% for settings.py and manage.py (we can leave these 2 for now).

I think 100% is the target. Short term goals should be to cover app.py and utils.py at 100% and then move on to the others. Plus, I suppose tests are low-hanging fruits and a good idea could be to keep few of those tests available for newcomers or starters.

Change 497311 had a related patch set uploaded (by Jeropbrendawm; owner: Jeropbrendawm):
[labs/tools/awmd-stats@master] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/497311

Change 497311 had a related patch set uploaded (by Jeropbrendawm; owner: Jeropbrendawm):
[labs/tools/awmd-stats@master] [IMPR] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/497311

Change 497311 merged by jenkins-bot:
[labs/tools/awmd-stats@master] [IMPR] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/497311

As of today

collected 23 items

tests/test_app.py ........                                                                                                                                                    [ 34%]
tests/test_utils.py ...............                                                                                                                                           [100%]

---------- coverage: platform darwin, python 3.7.2-final-0 -----------
Name                    Stmts   Miss  Cover
-------------------------------------------
awmdstats/__init__.py       0      0   100%
awmdstats/app.py          103      7    93%
awmdstats/settings.py      10     10     0%
awmdstats/utils.py         87      2    98%
manage.py                   8      8     0%
tests/__init__.py           0      0   100%
tests/conftest.py           6      0   100%
tests/test_app.py          26      0   100%
tests/test_utils.py        58      0   100%
-------------------------------------------
TOTAL                     298     27    91%

Change 500546 had a related patch set uploaded (by Jeropbrendawm; owner: Jeropbrendawm):
[labs/tools/awmd-stats@master] [IMPR] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/500546

Change 500546 merged by jenkins-bot:
[labs/tools/awmd-stats@master] [IMPR] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/500546

D3r1ck01 awarded a token.

Change 501402 had a related patch set uploaded (by Jeropbrendawm; owner: Jeropbrendawm):
[labs/tools/awmd-stats@master] [IMPR] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/501402

@D3r1ck01 @samuelguebo I'm trying to cover line 161 with tests but the tests fail when I try:

#  Test the /month-rank/<month> route response status_code if month is not specified
def test_rank_by_month_route_without_month(self, testapp):
    response = testapp.get('/month-rank/')
    assert response.status_code == 200

Doing https://tools.wmflabs.org/awmd-stats/month-rank/ also returns a 404.
How should I pass in an empty month?

Change 501402 merged by jenkins-bot:
[labs/tools/awmd-stats@master] [IMPR] Add unit tests for the awmd-stats tool

https://gerrit.wikimedia.org/r/501402