Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
def test_alert_creation_quotas(client):
    """There is a maximum amount of alerts one can create."""

    AlertFactory.create_batch(100, email='*****@*****.**')

    alerts = Alert.objects.all()
    assert alerts.count() == 100

    url = reverse('alert_create_view')
    res = client.post(url,
                      data={
                          'title': 'My new search',
                          'email': '*****@*****.**',
                          'alert_frequency': 'daily',
                          'querystring':
                          'text=Ademe&call_for_projects_only=on',
                      })
    assert res.status_code == 302
    assert alerts.count() == 100
Esempio n. 7
0
def test_delete_alert(client):
    alerts = Alert.objects.all()

    alert = AlertFactory()
    url = reverse('alert_delete_view', args=[alert.token])
    res = client.get(url)
    assert res.status_code == 200
    assert alerts.count() == 1

    res = client.post(url)
    assert res.status_code == 302
    assert alerts.count() == 0
Esempio n. 8
0
def test_command_output_format(mailoutbox):
    AlertFactory(title='Gloubiboukmark', querystring='text=Schtroumpf')
    AidFactory.create(name='Schtroumpf 1')
    AidFactory.create(name='Schtroumpf 2')
    AidFactory.create(name='Schtroumpf 3')
    AidFactory.create(name='Schtroumpf 4')
    call_command('send_alerts')

    content = mailoutbox[0].body
    assert 'Gloubiboukmark' in content
    assert 'Schtroumpf 1' in content
    assert 'Schtroumpf 2' in content
    assert 'Schtroumpf 3' in content

    # Only the first three aids are in the mail
    assert 'Schtroumpf 4' not in content
    assert 'encore d\'autres aides disponibles !' in content
Esempio n. 9
0
def test_alert_validation_url(client):
    alert = AlertFactory(validated=False, date_validated=None)
    assert not alert.validated
    assert alert.date_validated is None

    validation_url = reverse('alert_validate_view', args=[alert.token])
    res = client.get(validation_url)
    assert res.status_code == 200

    alert.refresh_from_db()
    assert not alert.validated

    res = client.post(validation_url)
    alert.refresh_from_db()
    assert res.status_code == 302
    assert alert.validated
    assert alert.date_validated.date() == timezone.now().date()
Esempio n. 10
0
def test_command_output_format(mailoutbox):
    AlertFactory(
        title='Gloubiboukmark',
        querystring='text=Schtroumpf')
    AidFactory.create(name='Schtroumpf 1')
    AidFactory.create(name='Schtroumpf 2')
    AidFactory.create(name='Schtroumpf 3')
    AidFactory.create(name='Schtroumpf 4')
    call_command('send_alerts')

    content = mailoutbox[0].body
    assert 'Gloubiboukmark' in content
    assert 'Schtroumpf 1' in content
    assert 'Schtroumpf 2' in content
    assert 'Schtroumpf 3' in content

    # Only the first three aids are in the mail
    assert 'Schtroumpf 4' not in content
    assert 'encore d\'autres aides disponibles !' in content

    # The "extra search" link should include these parameters
    assert 'published_after=' in content
    assert 'action=alert' in content
Esempio n. 11
0
def test_get_absolute_url_in_minisite():
    alert = AlertFactory(querystring='text=test')
    alert_absolute_url = alert.get_absolute_url(in_minisite=True)
    assert not alert_absolute_url.startswith('/aides/')
Esempio n. 12
0
def test_get_absolute_url():
    alert = AlertFactory(querystring='text=test')
    alert_absolute_url = alert.get_absolute_url()
    assert alert_absolute_url.startswith('/aides/')
Esempio n. 13
0
def test_get_new_aids_with_no_aids(last_month):
    """No aids exist, so no aids can be found."""

    alert = AlertFactory(querystring='text=test')
    aids = alert.get_new_aids()
    assert len(aids) == 0
Esempio n. 14
0
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]
Esempio n. 15
0
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
Esempio n. 16
0
def test_command_with_an_alert_but_no_aids(mailoutbox):
    AlertFactory(querystring='text=Schtroumpf')
    call_command('send_alerts')
    assert len(mailoutbox) == 0