def test_get_new_aids_with_matching_aids(yesterday): """Matching aids are found.""" alert = AlertFactory(querystring='text=test') AidFactory.create_batch(5, name='Test', date_published=yesterday) aids = alert.get_new_aids() assert len(aids) == 5
def test_get_new_aids_with_no_old_aids(last_month): """Matching aids are older than the requested threshold.""" alert = AlertFactory(querystring='text=test') AidFactory.create_batch(5, name='Test', date_published=last_month) aids = alert.get_new_aids() assert len(aids) == 0
def test_get_new_aids_with_no_matching_aids(yesterday): """Existing aids do not match.""" alert = AlertFactory(querystring='text=Gloubiboulga') AidFactory.create_batch(5, name='Test', date_published=yesterday) aids = alert.get_new_aids() assert len(aids) == 0
def test_command_with_unvalidated_address(mailoutbox): AlertFactory( validated=False, querystring='text=Schtroumpf') AidFactory.create_batch(5, name='Schtroumpf') call_command('send_alerts') assert len(mailoutbox) == 0
def test_get_new_aids_with_unpublished_aids(yesterday): """Matching aids are not published.""" alert = AlertFactory(querystring='text=test') AidFactory.create_batch(5, name='Test', date_published=yesterday, status='draft') aids = alert.get_new_aids() assert len(aids) == 0
def test_share_button_is_hidden_for_anonymous_users(client): AidFactory.create_batch(3) url = reverse('search_view') res = client.get(url) assert res.status_code == 200 content = res.content.decode('utf-8') assert 'envoyer ces résultats par e-mail' in content assert '<form id="send-results-by-email-form" method="post"' not in content
def test_share_button_is_displayed_for_logged_users(client, user): AidFactory.create_batch(3) client.force_login(user) assert user.is_authenticated url = reverse('search_view') res = client.get(url) assert res.status_code == 200 content = res.content.decode('utf-8') assert 'envoyer ces résultats par e-mail' in content assert '<form id="send-results-by-email-form" method="post"' in content
def test_expired_aids_are_not_listed(client): url = reverse('search_view') AidFactory.create_batch(2) res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 2 today = timezone.now().date() tomorrow = today + timedelta(days=1) yesterday = today - timedelta(days=1) AidFactory.create_batch(3, submission_deadline=tomorrow) res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 5 AidFactory.create_batch(5, submission_deadline=today) res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 10 AidFactory.create_batch(7, submission_deadline=yesterday) res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 10
def test_only_published_aids_are_listed(client): """Test that unpublished aids are not shown.""" AidFactory.create_batch(3) url = reverse('search_view') res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 3 # Let's create some non published aids, to check that the list # of objects passed to the context does not change AidFactory.create_batch(5, status='draft') AidFactory.create_batch(7, status='reviewable') res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 3 # Let's add some more published aids, to check that the limit does not # come from pagination parameters AidFactory.create_batch(11) url = reverse('search_view') res = client.get(url) assert res.status_code == 200 assert len(res.context['aids']) == 14
def aids(perimeters): aids = [ AidFactory(perimeter=perimeters['europe']), *AidFactory.create_batch(2, perimeter=perimeters['france']), *AidFactory.create_batch(3, perimeter=perimeters['occitanie']), *AidFactory.create_batch(4, perimeter=perimeters['herault']), *AidFactory.create_batch(5, perimeter=perimeters['montpellier']), *AidFactory.create_batch(6, perimeter=perimeters['vic']), *AidFactory.create_batch(7, perimeter=perimeters['aveyron']), *AidFactory.create_batch(8, perimeter=perimeters['rodez']), *AidFactory.create_batch(9, perimeter=perimeters['normandie']), *AidFactory.create_batch(10, perimeter=perimeters['eure']), *AidFactory.create_batch(11, perimeter=perimeters['st-cyr']), *AidFactory.create_batch(12, perimeter=perimeters['adour-garonne']), *AidFactory.create_batch( 13, perimeter=perimeters['rhone-mediterannee']), # noqa *AidFactory.create_batch(14, perimeter=perimeters['fort-de-france']), *AidFactory.create_batch(15, perimeter=perimeters['outre-mer']), ] return aids
def test_command_with_matching_aids(mailoutbox): alert = AlertFactory(querystring='text=Schtroumpf') AidFactory.create_batch(5, name='Schtroumpf') call_command('send_alerts') assert len(mailoutbox) == 1 assert list(mailoutbox[0].to) == [alert.email]
def test_command_with_an_alert_but_no_matching_aids(mailoutbox): AlertFactory(querystring='text=Schtroumpf') AidFactory.create_batch(5, name='Gloubiboulga') call_command('send_alerts') assert len(mailoutbox) == 0