def test_search_page_admin_can_upload_an_image(client, user): SearchPageFactory(title='Test PP', administrator=user) client.force_login(user) count_before = UploadImage.objects.count() upload_image(client) count_after = UploadImage.objects.count() assert count_after == count_before + 1
def test_search_page_administrator_has_specific_menu(client): user_admin_pp = UserFactory(is_contributor=False) SearchPageFactory(title='Test PP', administrator=user_admin_pp) client.force_login(user_admin_pp) home = reverse('home') res = client.get(home) assert 'Test PP' in res.content.decode()
def test_search_page_display(client): """Is the seach page slug correctly found from the url?.""" page = SearchPageFactory(title='Gloubiboulga page') page_url = reverse('search_page', args=[page.slug]) res = client.get(page_url) assert res.status_code == 200 assert 'Gloubiboulga page' in res.content.decode()
def test_user_role_search_page_admin(): """Users with linked Search Pages are considered as Search Page administrators.""" # user UserFactory(is_contributor=False) # search page administrator search_page_administrator = UserFactory(is_contributor=False) SearchPageFactory(administrator=search_page_administrator) assert User.objects.count() == 2 assert User.objects.search_page_admins().count() == 1
def test_search_page_results(client): """Test that the saved search query is applied.""" AidFactory(name="Un repas sans fromage, c'est dommage") AidFactory(name="Une soirée sans vin, ce n'est pas malin") page = SearchPageFactory(title='Gloubiboulga page', search_querystring='text=fromage') page_url = reverse('search_page', args=[page.slug]) res = client.get(page_url) assert res.status_code == 200 assert 'fromage' in res.content.decode() assert 'malin' not in res.content.decode()
def test_search_query_overriding(client): """Test that manual filters override saved ones.""" AidFactory(name="Un repas sans fromage, c'est dommage") AidFactory(name="Une soirée sans vin, ce n'est pas malin") page = SearchPageFactory(title='Gloubiboulga page', search_querystring='text=fromage') page_url = reverse('search_page', args=[page.slug]) full_url = '{}?text=vin'.format(page_url) res = client.get(full_url) assert res.status_code == 200 assert 'fromage' not in res.content.decode() assert 'malin' in res.content.decode()
def test_user_can_have_multiple_roles(): """Roles are not exclusive. A user can have multiple roles.""" multi_role_user = UserFactory(is_contributor=True) SearchPageFactory(administrator=multi_role_user) guadeloupe = PerimeterFactory(name='Guadeloupe', scale=Perimeter.SCALES.region) multi_role_user.animator_perimeter = guadeloupe multi_role_user.save() Token.objects.get_or_create(user=multi_role_user) assert User.objects.count() == 1 assert User.objects.contributors().count() == 1 assert User.objects.search_page_admins().count() == 1 assert User.objects.animators().count() == 1 assert User.objects.with_api_token().count() == 1
def test_search_page_with_excluded_aids_results(client): """Test that the excluded_aids are filtered out.""" AidFactory(name="Un repas sans fromage, c'est dommage") AidFactory(name="Une soirée sans vin, ce n'est pas malin") aid_to_exclude = AidFactory(name="Du fromage sans vin, ce n'est pas sain") page = SearchPageFactory(title='Gloubiboulga page', search_querystring='text=fromage') page.excluded_aids.set([aid_to_exclude]) page_url = reverse('search_page', args=[page.slug]) res = client.get(page_url) assert res.status_code == 200 assert 'fromage' in res.content.decode() assert 'malin' not in res.content.decode() assert 'sain' not in res.content.decode()
def test_alert_from_search_page(client, mailoutbox): """The search perimeter is displayed in the validation email.""" perimeter = PerimeterFactory.create(name='Bretagne') perimeter_id = '{}-{}'.format(perimeter.id, perimeter.code) page = SearchPageFactory( title='Minisite', search_querystring='perimeter={}'.format(perimeter_id)) url = reverse('alert_create_view') res = client.post(url, data={ 'title': 'Test', 'email': '*****@*****.**', 'alert_frequency': 'daily', 'querystring': '', 'source': page.slug }) assert res.status_code == 302 assert len(mailoutbox) == 1 assert perimeter_id in Alert.objects.last().querystring
def test_search_page_with_highlighted_aids_results(client, last_week, next_week, next_month): # noqa """Test that the highlighted_aids are moved up.""" AidFactory(name="Un repas sans fromage, c'est dommage", submission_deadline=next_week) AidFactory(name="Une soirée sans vin, ce n'est pas malin") aid_to_highlight_1 = AidFactory( name="Du fromage sans vin, ce n'est pas sain", submission_deadline=next_month) aid_to_highlight_2 = AidFactory(name="Un autre fromage", submission_deadline=last_week) page = SearchPageFactory(title='Gloubiboulga page', search_querystring='text=fromage') page_url = reverse('search_page', args=[page.slug]) res = client.get(page_url) assert res.status_code == 200 aid_1_index = res.content.decode().index('Un repas sans fromage') aid_2_index = res.content.decode().index('Du fromage sans vin') assert aid_1_index < aid_2_index page.highlighted_aids.set([aid_to_highlight_1, aid_to_highlight_2]) page_url = reverse('search_page', args=[page.slug]) res = client.get(page_url) # highlighted aid should appear first assert res.status_code == 200 aid_1_index = res.content.decode().index('Un repas sans fromage') aid_2_index = res.content.decode().index('Du fromage sans vin') assert aid_2_index < aid_1_index # expired aids (even if highlighted) should not appear assert 'Un autre fromage' not in res.content.decode()