예제 #1
0
def test_api_with_q_filter(client, api_url):
    BackerFactory(name='ADEME')
    BackerFactory(name='BPI')
    BackerFactory(name='DINUM')

    res = client.get(f'{api_url}?q=ade')
    assert res.status_code == 200
    content = json.loads(res.content.decode())
    assert content['count'] == 1
예제 #2
0
def test_api(client, api_url):
    BackerFactory(name='ADEME')
    BackerFactory(name='Bpifrance')
    BackerFactory(name='DINUM')

    res = client.get(api_url)
    assert res.status_code == 200
    content = json.loads(res.content.decode())
    assert content['count'] == 3
예제 #3
0
def test_backer_filtering():

    BackerFactory()
    aid_draft = AidFactory(status=AidWorkflow.states.draft)
    BackerFactory(financed_aids=[aid_draft])
    aid_published_1 = AidFactory(status=AidWorkflow.states.published)
    aid_published_2 = AidFactory(status=AidWorkflow.states.published)
    BackerFactory(financed_aids=[aid_published_1, aid_published_2])

    assert Backer.objects.count() == 3
    assert Backer.objects.has_financed_aids().count() == 2
    assert Backer.objects.has_published_financed_aids().count() == 1
예제 #4
0
def test_log_aid_search_event(perimeters):
    theme_1 = ThemeFactory(name='Nature environnement risques')
    theme_2 = ThemeFactory(name='Developpement economique')
    category_1 = CategoryFactory(name='economie circulaire')
    # category_2 = CategoryFactory(name='musee')
    backer_1 = BackerFactory(name='ADEME')
    program_1 = ProgramFactory(name='Programme')

    request_get_urlencoded = (
        "drafts=True&call_for_projects_only=False&apply_before="
        "&targeted_audiences=department"
        f"&perimeter={perimeters['montpellier'].id_slug}"
        f"&themes={theme_1.slug}&themes={theme_2.slug}"
        f"&categories={category_1.slug}&categories="
        f"&backers={backer_1.id}-{backer_1.slug}"
        f"&programs={program_1.slug}")
    results_count = 15
    host = "francemobilites.aides-territoires.beta.gouv.fr"

    log_aidsearchevent(querystring=request_get_urlencoded,
                       results_count=results_count,
                       source=host)

    event = AidSearchEvent.objects.last()

    assert len(event.targeted_audiences) == 1
    assert event.targeted_audiences[0] == Aid.AUDIENCES.department
    assert event.perimeter == perimeters['montpellier']
    assert event.themes.count() == 2
    assert event.categories.count() == 1
    assert event.backers.count() == 1
    assert event.programs.count() == 1
    assert event.results_count == results_count
    assert event.source == 'francemobilites'
예제 #5
0
def test_get_querystring_backers_with_db():
    ademe = BackerFactory(name='ADEME')
    bpi = BackerFactory(name='Bpi France')

    assert list(get_querystring_backers(f"backers={ademe.slug}")) == []
    assert len(get_querystring_backers(f"backers={ademe.id}")) == 1
    assert get_querystring_backers(f"backers={ademe.id}")[0] == ademe
    assert get_querystring_backers(
        f"backers={ademe.id}-{ademe.slug}")[0] == ademe  # noqa
    assert len(get_querystring_backers(f"backers={ademe.id}&backers=")) == 1
    assert len(get_querystring_backers(
        f"backers={ademe.id}&backers={bpi.id}")) == 2  # noqa
    assert get_querystring_backers(
        f"backers={ademe.id}&backers={bpi.id}")[1] == bpi  # noqa
    assert get_querystring_backers(f"backers={bpi.id}&backers={ademe.id}"
                                   )[1] == bpi  # ordered by id  # noqa
예제 #6
0
def test_api_with_financed_aids_filters(client, api_url):
    BackerFactory()
    aid_draft = AidFactory(status=AidWorkflow.states.draft)
    BackerFactory(financed_aids=[aid_draft])
    aid_published_1 = AidFactory(status=AidWorkflow.states.published)
    aid_published_2 = AidFactory(status=AidWorkflow.states.published)
    BackerFactory(financed_aids=[aid_published_1, aid_published_2])

    res = client.get(f'{api_url}?has_financed_aids=true')
    assert res.status_code == 200
    content = json.loads(res.content.decode())
    assert content['count'] == 2

    res = client.get(f'{api_url}?has_published_financed_aids=true')
    assert res.status_code == 200
    content = json.loads(res.content.decode())
    assert content['count'] == 1
def test_importing_new_aids():
    """The import commands create the aids from provided data."""

    financer = BackerFactory()
    # Use aid factory to gather valid aid data
    aids = AidFactory.build_batch(5)
    for aid in aids:
        aid.set_slug()

    stub = ImportStub(aids=aids, financer=financer)

    aids = Aid.objects.all()
    assert aids.count() == 0

    stub.handle()
    assert aids.count() == 5
def test_importing_existing_aids():
    """Import only update aids that already exist."""

    financer = BackerFactory()
    aids = AidFactory.build_batch(5)
    for aid in aids:
        aid.set_slug()

    # The first import task will save aid data to the db
    stub = ImportStub(aids=aids, financer=financer)
    stub.handle()

    aids = Aid.objects.all()
    assert aids.count() == 5

    # On the second run, since aid with those unique id already exist,
    # no new aid are created
    stub.handle()
    assert aids.count() == 5
예제 #9
0
def backer():
    """Generates a valid Backer."""

    backer = BackerFactory()
    return backer
예제 #10
0
def test_backer_slug():
    new_backer = BackerFactory(name="New Backer")

    assert new_backer.slug == 'new-backer'
예제 #11
0
def test_backer_details_page_loads(client, contributor):
    backer = BackerFactory(name='Some Backer', slug='some-backer')
    url = reverse('backer_detail_view', args=[backer.pk, backer.slug])
    response = client.get(url)
    assert response.status_code == 200
    assert 'Some Backer' in str(response.content)