Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing coverage for marketing model, increasing coverage to 33% #524

Merged
merged 2 commits into from
Mar 12, 2018

Conversation

leonprou
Copy link
Contributor

@leonprou leonprou commented Mar 4, 2018

Description

Adding tests to increase code coverage from 28% to 33%. Testing marketing module.

Checklist
  • linter status: 100% pass.
  • changes don't break existing behavior
  • commit message follows commit guidelines
Affected core subsystem(s)

marketing

Testing

This PR is increasing test coverage. Only one little refactor was made.

Refers/Fixes

#408

@leonprou
Copy link
Contributor Author

leonprou commented Mar 5, 2018

@owocki hey, I'd like to merge it but it seems like the tests are failing again with same error as before

_pytest.vendored_packages.pluggy.PluginValidationError: Plugin 'ethereum' could not be loaded: (eth-utils 1.0.0b2 (/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages), Requirement.parse('eth-utils<2.0.0,>=1.0.1'), {'hexbytes', 'eth-abi'})!

@leonprou
Copy link
Contributor Author

leonprou commented Mar 5, 2018

I think expitation_start_work got broken, it's uses created_at here. While Interest class has been changed to have created property. Found it running the tests after merge.

@owocki
Copy link
Contributor

owocki commented Mar 5, 2018

I think expitation_start_work got broken, it's uses created_at here. While Interest class has been changed to have created property. Found it running the tests after merge.

shoot.. you are right.. 9c82c4f should fix that

owocki added a commit that referenced this pull request Mar 5, 2018
@owocki
Copy link
Contributor

owocki commented Mar 5, 2018

@owocki hey, I'd like to merge it but it seems like the tests are failing again with same error as before

IIRC, you and @mbeacom chatted about this on slack already, right?

@owocki
Copy link
Contributor

owocki commented Mar 5, 2018

just poked through the new tests.. 💯 thanks so much!

@leonprou
Copy link
Contributor Author

leonprou commented Mar 6, 2018

IIRC, you and @mbeacom chatted about this on slack already, right?

Yeah, we talked. it's good now 👍

just poked through the new tests.. 💯 thanks so much!

You're welcome 😄, learned a thing or two writing the tests. I think more bounties like this are needed, I communicate some more thoughts later.

For now expiration_start_work implementation changed so the tests not pass, I'll look at that at the evening I guess.

@owocki
Copy link
Contributor

owocki commented Mar 6, 2018

For now expiration_start_work implementation changed so the tests not pass, I'll look at that at the evening I guess.

did you mean that my commit (9c82c4f) broke the tests? or something else?

@leonprou
Copy link
Contributor Author

leonprou commented Mar 6, 2018 via email

@mbeacom mbeacom changed the title writing coverage for marketing model, increasing coverage to 33% WIP: writing coverage for marketing model, increasing coverage to 33% Mar 6, 2018
@mbeacom mbeacom added wip backend This needs backend expertise. labels Mar 6, 2018
@codecov
Copy link

codecov bot commented Mar 6, 2018

Codecov Report

Merging #524 into master will increase coverage by 4.86%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #524      +/-   ##
==========================================
+ Coverage   29.11%   33.98%   +4.86%     
==========================================
  Files          88       88              
  Lines        4880     4882       +2     
  Branches      571      571              
==========================================
+ Hits         1421     1659     +238     
+ Misses       3412     3157     -255     
- Partials       47       66      +19
Impacted Files Coverage Δ
...ing/management/commands/send_subscription_mails.py 100% <ø> (+100%) ⬆️
...eting/management/commands/expiration_start_work.py 84.31% <ø> (+84.31%) ⬆️
...eting/management/commands/assemble_leaderboards.py 51.78% <100%> (+51.78%) ⬆️
app/dashboard/notifications.py 14.7% <0%> (+0.32%) ⬆️
app/marketing/models.py 86.58% <0%> (+1.21%) ⬆️
app/dashboard/models.py 71.55% <0%> (+3.23%) ⬆️
app/dashboard/signals.py 55% <0%> (+25%) ⬆️
app/marketing/utils.py 66.66% <0%> (+37.03%) ⬆️
...pp/marketing/management/commands/remarket_tweet.py 66.66% <0%> (+66.66%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6c5a33...63b2cbd. Read the comment docs.

@owocki
Copy link
Contributor

owocki commented Mar 7, 2018

Oh no, some logic was changed before.. I assumed it was intentionally

The logic that was changed in 9c82c4f is just that if a comment happens before the 'start work' button is clicked it is disregarded..

Let me know if you have other questions to get the tests working agin

@leonprou
Copy link
Contributor Author

leonprou commented Mar 7, 2018

The logic that was changed in 9c82c4f is just that if a comment happens before the 'start work' button is clicked it is disregarded..

Yes I solved that. Ok I think that this can be merged 😄, the last thing is about the linter? Which one you are using?

@mbeacom
Copy link
Contributor

mbeacom commented Mar 7, 2018

@leonprou I regularly use flake8, pylint, and pydocstyle along with a combination of plugins.

@owocki
Copy link
Contributor

owocki commented Mar 7, 2018

i use

isort --recursive --atomic

but i'm not as good of a citizen as @mbeacom

@mbeacom maybe we should update the readme with some agreed-upon linting commands so that maintainers can be expected to lint their own PRs?

@mbeacom
Copy link
Contributor

mbeacom commented Mar 7, 2018

@owocki I'm all for updating the docs to reflect a standard linting practice. I've been meaning to ask you about your thoughts on: https://stickler-ci.com/ - It's free for OSS. We could simply use their linter without using the fixer functionality to identify spots throughout a PR that don't adhere to the linting configuration for both python (flake8) and js (eslint).

@owocki
Copy link
Contributor

owocki commented Mar 7, 2018

certainly open to trying it.. hopefully between travis + codecov + stickler its not too overwhelming for new contributors

@leonprou leonprou closed this Mar 7, 2018
@leonprou leonprou reopened this Mar 7, 2018
@leonprou leonprou force-pushed the increase_code_coverage branch 2 times, most recently from 9165fc0 to 79623c6 Compare March 9, 2018 14:03
@mbeacom
Copy link
Contributor

mbeacom commented Mar 9, 2018

@leonprou Is this ready to review and test?

@leonprou
Copy link
Contributor Author

leonprou commented Mar 9, 2018 via email

@mbeacom
Copy link
Contributor

mbeacom commented Mar 9, 2018

@leonprou Yeah, that's fine... It's an isort failure on an import in sync_slack.py - All good.

Reviewing this now.

@mbeacom mbeacom changed the title WIP: writing coverage for marketing model, increasing coverage to 33% Writing coverage for marketing model, increasing coverage to 33% Mar 9, 2018
"""Define tests for roundup send subscription mails."""

def test_handle(self):
"""Test command send subscription mails."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to call Command().handle()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, forgot to test that one 👍

"""Test the marketing util get_or_save_email_subscriber method."""
assert get_or_save_email_subscriber('emailSubscriber1@gitcoin.co', 'mysource') == 'priv1'

emailSubscriber1SecondSource = EmailSubscriber.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you camel_case this variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it's unused variable)

'all_earners': {},
}
def default_ranks():
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

idx_status='submitted',
current_bounty=True
)
bounty_fulfillment = BountyFulfillment.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the unused assignment of bounty_fulfillment here?

assert assemble_leaderboards.ranks['monthly_all']['fred'] == 3
assert assemble_leaderboards.ranks['yearly_all']['fred'] == 3

assert len(assemble_leaderboards.ranks['weekly_fulfilled']) == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opposed to len(), can you use either assert any(dict) is False or assert not dict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,
buy why you don't like len()?

bounty=bounty
)

bounty_fulfillment = BountyFulfillment.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the unused assignment here?

class TestSyncKeywords(TestCase):
"""Define tests for sync keywords."""

def setUp(test):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you switch this to def setUp(self): ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure 👍

def test_get_stat(self):
"""Test the marketing util get_stat method."""
assert get_stat('mykey') == 2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another new line between these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to separate the classes by 2 lines, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @leonprou - Two new lines between module level classes and methods.

import thing


class Example:
    """Some docstring."""

    def test(self):
        """Some test."""
        return 'test'

    def test_again(self):
        """Some test again."""
        return 'test again'


class ExampleAgain:
    """Some docstring again."""

    def test(self):
        """Some test."""
        return 'test'


def some_test():
    """Some test."""
    return 'some test'


def test_should_suppress_notification_email(self):
"""Test the marketing util test_should_suppress_notification_email method."""
assert should_suppress_notification_email('emailSubscriber1@gitcoin.co') == False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change these boolean assertions to assert func() is False and assert func() is True or assert func() and assert not func()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, thanks 👍

def test_save_get_or_save_email_subscriber_get(self):
"""Test the marketing util get_or_save_email_subscriber method."""
self.assertIsNotNone(get_or_save_email_subscriber('newemail@gitcoin.co',
'mysource', send_slack_invite=False))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you carry this indent over to hang below (get_or_save?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never use how to indent it right, but I fixed and flake is not complaining

@mbeacom
Copy link
Contributor

mbeacom commented Mar 9, 2018

Overall, lgtm - Just a few miscellaneous syntax changes. Thanks for the contribution @leonprou !

Copy link
Contributor Author

@leonprou leonprou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think I made all the changes, also ran flake myself on all tests files


def test_should_suppress_notification_email(self):
"""Test the marketing util test_should_suppress_notification_email method."""
assert should_suppress_notification_email('emailSubscriber1@gitcoin.co') == False
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, thanks 👍

"""Test the marketing util get_or_save_email_subscriber method."""
assert get_or_save_email_subscriber('emailSubscriber1@gitcoin.co', 'mysource') == 'priv1'

emailSubscriber1SecondSource = EmailSubscriber.objects.create(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it's unused variable)

def test_save_get_or_save_email_subscriber_get(self):
"""Test the marketing util get_or_save_email_subscriber method."""
self.assertIsNotNone(get_or_save_email_subscriber('newemail@gitcoin.co',
'mysource', send_slack_invite=False))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never use how to indent it right, but I fixed and flake is not complaining

assert assemble_leaderboards.ranks['monthly_all']['fred'] == 3
assert assemble_leaderboards.ranks['yearly_all']['fred'] == 3

assert len(assemble_leaderboards.ranks['weekly_fulfilled']) == 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done,
buy why you don't like len()?

"""Define tests for roundup send subscription mails."""

def test_handle(self):
"""Test command send subscription mails."""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, forgot to test that one 👍

@owocki
Copy link
Contributor

owocki commented Mar 12, 2018

lets get this shipped this week!

Copy link
Contributor

@mbeacom mbeacom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :shipit:

Thanks for the contribution and updates @leonprou !

@mbeacom mbeacom merged commit 7c467aa into gitcoinco:master Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend This needs backend expertise.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants