コード例 #1
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')

    request_get_urlencoded = (
        "drafts=True&call_for_projects_only=False"
        "&targeted_audiences=department"
        f"&perimeter={perimeters['montpellier'].id_slug}"
        f"&themes={theme_1.slug}&themes={theme_2.slug}"
        f"&categories={category_1.slug}&categories=&apply_before=")
    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.results_count == results_count
    assert event.source == 'francemobilites'
コード例 #2
0
def test_log_aid_search_event_empty(perimeters):

    request_get_urlencoded = ""

    log_aidsearchevent(querystring=request_get_urlencoded)

    event = AidSearchEvent.objects.last()

    assert event.targeted_audiences is None
    assert event.perimeter is None
    assert event.themes.count() == 0
    assert event.categories.count() == 0
    assert event.results_count == 0
    assert event.source == ''
コード例 #3
0
def test_log_aid_search_event_with_pages(perimeters):
    # empty 'page' should work
    request_get_urlencoded = 'page='
    event_count_before = AidSearchEvent.objects.count()
    log_aidsearchevent(querystring=request_get_urlencoded)
    event_count_after = AidSearchEvent.objects.count()
    assert event_count_after == event_count_before + 1

    # 'page=1' should work
    request_get_urlencoded = 'page=1'
    event_count_before = AidSearchEvent.objects.count()
    log_aidsearchevent(querystring=request_get_urlencoded)
    event_count_after = AidSearchEvent.objects.count()
    assert event_count_after == event_count_before + 1

    # 'page=2' should not work
    request_get_urlencoded = 'page=2'
    event_count_before = AidSearchEvent.objects.count()
    log_aidsearchevent(querystring=request_get_urlencoded)
    event_count_after = AidSearchEvent.objects.count()
    assert event_count_after == event_count_before

    # strange 'page=' should not work
    request_get_urlencoded = 'page=coucou'
    event_count_before = AidSearchEvent.objects.count()
    log_aidsearchevent(querystring=request_get_urlencoded)
    event_count_after = AidSearchEvent.objects.count()
    assert event_count_after == event_count_before
コード例 #4
0
def test_log_aid_search_event_with_internal(perimeters):
    theme_1 = ThemeFactory(name='Nature environnement risques')
    theme_2 = ThemeFactory(name='Developpement economique')
    category_1 = CategoryFactory(name='economie circulaire')

    request_get_urlencoded = (
        "drafts=True&call_for_projects_only=False"
        "&targeted_audiences=department"
        f"&perimeter={perimeters['montpellier'].id_slug}"
        f"&themes={theme_1.slug}&themes={theme_2.slug}"
        f"&categories={category_1.slug}&categories=&apply_before="
        "&internal=True")

    event_count_before = AidSearchEvent.objects.count()

    log_aidsearchevent(querystring=request_get_urlencoded)

    event_count_after = AidSearchEvent.objects.count()

    assert event_count_before == event_count_after
コード例 #5
0
def test_log_aid_search_event_with_wrong_targeted_audiences(perimeters):
    # wrong targeted_audiences
    request_get_urlencoded = "targeted_audiences=coucou"

    event_count_before = AidSearchEvent.objects.count()

    log_aidsearchevent(querystring=request_get_urlencoded)

    event_count_after = AidSearchEvent.objects.count()

    assert event_count_after == event_count_before

    # wrong targeted_audiences (real example)
    request_get_urlencoded = (
        "integration=test&text=test&perimeter=test"
        "&targeted_audiences=test&targeted_audiences=test"
        "&targeted_audiences=test&targeted_audiences=test"
        "&apply_before=test&call_for_projects_only=test"
        "&order_by=test+ORDER+BY+5040%23")

    event_count_before = AidSearchEvent.objects.count()

    log_aidsearchevent(querystring=request_get_urlencoded)

    event_count_after = AidSearchEvent.objects.count()

    assert event_count_after == event_count_before

    # accepted targeted_audiences
    request_get_urlencoded = "targeted_audiences="

    event_count_before = AidSearchEvent.objects.count()

    log_aidsearchevent(querystring=request_get_urlencoded)

    event_count_after = AidSearchEvent.objects.count()

    assert event_count_after == event_count_before + 1

    # accepted targeted_audiences
    request_get_urlencoded = ""

    event_count_before = AidSearchEvent.objects.count()

    log_aidsearchevent(querystring=request_get_urlencoded)

    event_count_after = AidSearchEvent.objects.count()

    assert event_count_after == event_count_before + 1