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

Fixes Month Change Bug in Unit Tests for #1690 #2063

Closed
wants to merge 3 commits into from

Conversation

krtkvrm
Copy link
Member

@krtkvrm krtkvrm commented Feb 2, 2019

Fixes: #2064
The Test test_get_remaining_submission_when_submission_made_three_days_back was failing for expected remaining_submissions_this_month_count as change in month because of

self.submission1.submitted_at = timezone.now() - timedelta(days=3)

The change in month was not taken into account while making the Tests for Fix #1690: Add support for setting submission limit per month per team for a challenge.

GetRemainingSubmissionTest.test_get_remaining_submission_when_submission_made_three_days_back 
self = <tests.unit.jobs.test_views.GetRemainingSubmissionTest testMethod=test_get_remaining_submission_when_submission_made_three_days_back>
    def test_get_remaining_submission_when_submission_made_three_days_back(self):
        self.url = reverse_lazy('jobs:get_remaining_submissions',
                                kwargs={
                                    'challenge_phase_pk': self.challenge_phase.pk,
                                    'challenge_pk': self.challenge.pk
                                })
        expected = {
            'remaining_submissions_today_count': 9,
            'remaining_submissions_this_month_count': 18,
            'remaining_submissions': 98
        }
    
        self.challenge.participant_teams.add(self.participant_team)
        self.challenge.save()
        self.submission1.submitted_at = timezone.now() - timedelta(days=3)
        self.submission1.save()
        response = self.client.get(self.url, {})
>       self.assertEqual(response.data, expected)
E       AssertionError: {'rem[15 chars]ons_this_month_count': 19, 'remaining_submissi[44 chars]: 98} != {'rem[15 chars]ons_today_count': 9, 'remaining_submissions_th[44 chars]: 98}
E         {'remaining_submissions': 98,
E       -  'remaining_submissions_this_month_count': 19,
E       ?                                             ^
E       
E       +  'remaining_submissions_this_month_count': 18,
E       ?                                             ^
E       
E          'remaining_submissions_today_count': 9}

The Issue is resolved by

expected_remaining_submissions_this_month_count = 18
if 1 <= timezone.now().day <= 3:
            expected_remaining_submissions_this_month_count = 19

This ensures that if because of timedelta(days=3), self.submission1.submitted_at.month is still the last month, expected_remaining_submissions_this_month_count will not take submission1 into count.

Thank You!

@krtkvrm
Copy link
Member Author

krtkvrm commented Feb 2, 2019

@RishabhJain2018 @deshraj Please Review!

@RishabhJain2018
Copy link
Member

RishabhJain2018 commented Mar 1, 2019

@vkartik97 Thanks for the effort but I think the approach you're using isn't a standard one. I've fixed it here since it is failing in this PR (because of the dates in this month 😛 ) https://github.com/Cloud-CV/EvalAI/pull/2156/files#diff-c6268b43fc26de9e08ed355975be069bR592

@RishabhJain2018
Copy link
Member

Closing this one since it is already fixed! Thanks for the PR @vkartik97 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Travis Failing Tests Because of bug in GetRemainingSubmissionTest
2 participants