def test_get_previous_renewal_multiple(self, month, expected_date): setup = factories.GeneralSetupFactory(valid_from=date(2017, 1, 1), renewal_month=month) factories.GeneralSetupFactory(valid_from=date(2015, 6, 1), renewal_month=7) assert setup.get_previous_renewal(datetime(2017, 1, 1)) == expected_date
def test_get_next_pass(self): now = datetime.utcnow() setup1 = factories.GeneralSetupFactory(valid_from=now - timedelta(days=30)) setup2 = factories.GeneralSetupFactory(valid_from=now) setup3 = factories.GeneralSetupFactory(valid_from=now + timedelta(days=15)) assert models.GeneralSetup.get_next(now - timedelta(days=31)) == setup1 assert models.GeneralSetup.get_next(now - timedelta(days=15)) == setup2 assert models.GeneralSetup.get_next(datetime.utcnow()) == setup3 assert models.GeneralSetup.get_next(datetime.utcnow() + timedelta(days=30)) is None
def test_eligible_for_vote_filter_fails(create_general_setup, invalid_date_format): if create_general_setup: factories.GeneralSetupFactory(valid_from=date(2015, 1, 1)) vote_filter = EligibleForVoteParticipantFilter( request=None, params={ EligibleForVoteParticipantFilter.parameter_name: date(2019, 11, 1).strftime(invalid_date_format) }, model=None, model_admin=None, ) vote_filter_qs = vote_filter.queryset(None, models.Participant.objects.all()) assert list(vote_filter_qs) == []
def test_eligible_for_vote_filter_full_pass(vote_date, is_id_expected): factories.GeneralSetupFactory( valid_from=date(2015, 1, 1), time_to_vote_since_membership=3, time_unit_to_vote_since_membership=TimeUnit.MONTHS.value, minimum_age_to_vote=18, renewal_month=1, ) participant = factories.ParticipantFactory(date_of_birth=date(1990, 12, 1)) tier = factories.TierFactory(needs_renewal=True, usable_from=date(2015, 1, 1)) membership = factories.MembershipFactory( participant=participant, tier=tier, effective_from=date(2019, 11, 8), form_filled=date(2019, 11, 8), ) assert membership.effective_until == date(2019, 12, 31) membership = factories.MembershipFactory( participant=participant, tier=tier, effective_from=date(2020, 1, 1), form_filled=date(2020, 1, 1), ) assert membership.effective_until == date(2020, 12, 31) vote_filter = EligibleForVoteParticipantFilter( request=None, params={ EligibleForVoteParticipantFilter.parameter_name: vote_date.strftime('%d/%m/%Y') }, model=None, model_admin=None, ) vote_filter_qs = vote_filter.queryset(None, models.Participant.objects.all()) assert (participant in list(vote_filter_qs)) is is_id_expected
def test_get_current_pass(self): now = datetime.utcnow() factories.GeneralSetupFactory(valid_from=now + timedelta(days=30)) setup = factories.GeneralSetupFactory(valid_from=now) factories.GeneralSetupFactory(valid_from=now - timedelta(days=30)) assert models.GeneralSetup.get_current() == setup
def general_setup(self): return factories.GeneralSetupFactory(valid_from=date(2015, 1, 1), renewal_month=1)
def test_get_next_renewal_single(self, month, expected_date): setup = factories.GeneralSetupFactory(valid_from=date(2017, 1, 1), renewal_month=month) assert setup.get_next_renewal(datetime(2019, 12, 1)) == expected_date