Skip to content

Commit

Permalink
Fix rename of VisibleDatasetFactory (#387)
Browse files Browse the repository at this point in the history
* Fix rename of VisibleDatasetFactory

* Fix duplicate imports

* Fix lint

* Fix tests

* Fix no index for empty datasets

* add back is_hidden for no robots

* Add back tests for hidden datasets

* Remove no index for empty datasets

* Fix lint

* Add test for archived
  • Loading branch information
ThibaudDauce authored Apr 4, 2024
1 parent 1cc30c4 commit ca06c43
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 50 deletions.
4 changes: 2 additions & 2 deletions udata_front/tests/test_sitemap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from udata.core.dataset.factories import VisibleDatasetFactory
from udata.core.dataset.factories import DatasetFactory
from udata.core.organization.factories import OrganizationFactory
from udata.core.post.factories import PostFactory
from udata.core.reuse.factories import VisibleReuseFactory
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_reuses_within_sitemap(self, sitemap):

def test_datasets_within_sitemap(self, sitemap):
'''It should return a dataset list from the sitemap.'''
datasets = VisibleDatasetFactory.create_batch(3)
datasets = DatasetFactory.create_batch(3)

sitemap.fetch()

Expand Down
14 changes: 7 additions & 7 deletions udata_front/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from feedgenerator.django.utils.feedgenerator import Atom1Feed

from udata.core.dataset.factories import (
DatasetFactory, LicenseFactory, VisibleDatasetFactory
DatasetFactory, LicenseFactory
)
from udata.core.reuse.factories import ReuseFactory
from udata.core.organization.factories import OrganizationFactory
Expand Down Expand Up @@ -481,7 +481,7 @@ def test_render_without_data(self, client):
def test_render_with_data(self, client):
for i in range(3):
badge = Badge(kind=SPD)
VisibleDatasetFactory(badges=[badge])
DatasetFactory(badges=[badge])
response = client.get(url_for('gouvfr.spd'))
assert200(response)

Expand Down Expand Up @@ -667,7 +667,7 @@ def test_datasets_with_dynamic_region(self, client):
paca, bdr, arles = create_geozones_fixtures()
organization = OrganizationFactory()
for _ in range(3):
VisibleDatasetFactory(
DatasetFactory(
organization=organization,
spatial=SpatialCoverageFactory(zones=[paca.id]))

Expand All @@ -680,7 +680,7 @@ def test_datasets_with_dynamic_region_and_size(self, client):
paca, bdr, arles = create_geozones_fixtures()
organization = OrganizationFactory()
for _ in range(3):
VisibleDatasetFactory(
DatasetFactory(
organization=organization,
spatial=SpatialCoverageFactory(zones=[paca.id]))

Expand All @@ -693,7 +693,7 @@ def test_datasets_without_dynamic_region(self, client):
paca, bdr, arles = create_geozones_fixtures()
organization = OrganizationFactory()
for _ in range(3):
VisibleDatasetFactory(
DatasetFactory(
organization=organization,
spatial=SpatialCoverageFactory(zones=[paca.id]))

Expand All @@ -705,7 +705,7 @@ def test_datasets_with_dynamic_county(self, client):
paca, bdr, arles = create_geozones_fixtures()
organization = OrganizationFactory()
for _ in range(3):
VisibleDatasetFactory(
DatasetFactory(
organization=organization,
spatial=SpatialCoverageFactory(zones=[bdr.id]))

Expand All @@ -718,7 +718,7 @@ def test_datasets_with_dynamic_town(self, client):
paca, bdr, arles = create_geozones_fixtures()
organization = OrganizationFactory()
for _ in range(3):
VisibleDatasetFactory(
DatasetFactory(
organization=organization,
spatial=SpatialCoverageFactory(zones=[arles.id]))

Expand Down
7 changes: 3 additions & 4 deletions udata_front/tests/views/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from udata.core.dataset.factories import (
ResourceFactory, DatasetFactory, LicenseFactory, CommunityResourceFactory,
VisibleDatasetFactory
)
from udata.core.user.factories import UserFactory
from udata.core.organization.factories import OrganizationFactory
Expand All @@ -21,7 +20,7 @@ class DatasetBlueprintTest(GouvfrFrontTestCase):

def test_render_display(self):
'''It should render the dataset page'''
dataset = VisibleDatasetFactory()
dataset = DatasetFactory()
url = url_for('datasets.show', dataset=dataset)
response = self.get(url)
self.assert200(response)
Expand Down Expand Up @@ -153,9 +152,9 @@ def test_200_if_deleted_but_authorized(self):
response = self.get(url_for('datasets.show', dataset=dataset))
self.assert200(response)

def test_no_index_on_empty(self):
def test_no_index_on_archived(self):
'''It should prevent crawlers from indexing empty datasets'''
dataset = DatasetFactory()
dataset = DatasetFactory(archived=datetime.utcnow())
response = self.get(url_for('datasets.show', dataset=dataset))
self.assert200(response)
self.assertIn(b'<meta name="robots" content="noindex, nofollow"',
Expand Down
28 changes: 10 additions & 18 deletions udata_front/tests/views/test_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from udata.core.badges.factories import badge_factory

from udata.core.reuse.factories import ReuseFactory, VisibleReuseFactory
from udata.core.dataset.factories import DatasetFactory, VisibleDatasetFactory, ResourceFactory
from udata.core.dataset.factories import DatasetFactory, ResourceFactory
from udata.core.discussions.factories import DiscussionFactory
from udata.core.organization.factories import OrganizationFactory
from udata.core.user.factories import UserFactory, AdminFactory
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_render_display_with_datasets(self):
'''It should render the organization page with some datasets'''
organization = OrganizationFactory()
datasets = [
VisibleDatasetFactory(organization=organization) for _ in range(3)]
DatasetFactory(organization=organization) for _ in range(3)]
response = self.get(url_for('organizations.show', org=organization))

self.assert200(response)
Expand All @@ -77,12 +77,12 @@ def test_render_display_with_datasets(self):
def test_render_display_with_private_assets_only_member(self):
'''It should render the organization page without private assets'''
organization = OrganizationFactory()
datasets = [VisibleDatasetFactory(organization=organization)
datasets = [DatasetFactory(organization=organization)
for _ in range(2)]
reuses = [VisibleReuseFactory(organization=organization)
for _ in range(2)]
for _ in range(2):
VisibleDatasetFactory(organization=organization, private=True)
DatasetFactory(organization=organization, private=True)
ReuseFactory(organization=organization, datasets=[]) # Empty asset
VisibleReuseFactory(organization=organization, private=True)
response = self.get(url_for('organizations.show', org=organization))
Expand Down Expand Up @@ -115,10 +115,8 @@ def test_render_display_with_private_datasets(self):
# We show indexable datasets on the organisation page
# so private datasets are omitted
datasets = [
VisibleDatasetFactory(organization=organization) for _ in range(2)]
empty_datasets = [
DatasetFactory(organization=organization, resources=[]) for _ in range(1)]
[VisibleDatasetFactory(organization=organization, private=True) for _ in range(1)]
DatasetFactory(organization=organization) for _ in range(2)]
[DatasetFactory(organization=organization, private=True) for _ in range(1)]
response = self.get(url_for('organizations.show', org=organization))

self.assert200(response)
Expand All @@ -128,20 +126,14 @@ def test_render_display_with_private_datasets(self):
rendered_private_datasets = [dataset for dataset in rendered_datasets if dataset.private]
self.assertEqual(len(rendered_private_datasets), 0)

rendered_empty_datasets = [
dataset for dataset in rendered_datasets if len(dataset.resources) == 0
]
self.assertEqual(len(rendered_empty_datasets), len(empty_datasets))

self.assertEqual(rendered_datasets.total,
len(datasets) + len(empty_datasets))
self.assertEqual(rendered_datasets.total, len(datasets))

def test_render_display_with_paginated_datasets(self):
'''It should render the organization page with paginated datasets'''
organization = OrganizationFactory()
datasets_len = 21
for _ in range(datasets_len):
VisibleDatasetFactory(organization=organization)
DatasetFactory(organization=organization)
response = self.get(url_for('organizations.show', org=organization))

self.assert200(response)
Expand All @@ -154,7 +146,7 @@ def test_render_display_with_paginated_datasets_on_second_page(self):
second_page_len = 1
datasets_len = 21
for _ in range(datasets_len):
VisibleDatasetFactory(organization=organization)
DatasetFactory(organization=organization)
response = self.get(url_for('organizations.show', org=organization, page=2))

self.assert200(response)
Expand Down Expand Up @@ -284,7 +276,7 @@ def test_resources_csv(self):
for _ in range(3)
]
not_org_dataset = DatasetFactory(resources=[ResourceFactory()])
hidden_dataset = DatasetFactory()
hidden_dataset = DatasetFactory(private=True)

response = self.get(
url_for('organizations.datasets_resources_csv', org=org))
Expand Down
4 changes: 2 additions & 2 deletions udata_front/tests/views/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_datasets_csv(self):
self.app.config['EXPORT_CSV_MODELS'] = []
datasets = [DatasetFactory(resources=[ResourceFactory()])
for _ in range(5)]
hidden_dataset = DatasetFactory()
hidden_dataset = DatasetFactory(private=True)

response = self.get(url_for('site.datasets_csv'))

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_datasets_csv_with_filters(self):
for _ in range(6)]
datasets = [DatasetFactory(resources=[ResourceFactory()])
for _ in range(3)]
hidden_dataset = DatasetFactory()
hidden_dataset = DatasetFactory(private=True)

response = self.get(
url_for(
Expand Down
28 changes: 14 additions & 14 deletions udata_front/tests/views/test_territories.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from flask import url_for

from udata.core.dataset.factories import VisibleDatasetFactory
from udata.core.dataset.factories import DatasetFactory
from udata.core.organization.factories import OrganizationFactory
from udata.core.spatial.factories import SpatialCoverageFactory
from udata.models import Member
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_regions_with_default_base_datasets(self):

def test_towns_with_other_datasets(self):
organization = OrganizationFactory()
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.arles.id]))
response = self.client.get(
Expand All @@ -88,7 +88,7 @@ def test_towns_with_other_datasets(self):

def test_counties_with_other_datasets(self):
organization = OrganizationFactory()
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.bdr.id]))
response = self.client.get(
Expand All @@ -110,7 +110,7 @@ def test_counties_with_other_datasets(self):

def test_regions_with_other_datasets(self):
organization = OrganizationFactory()
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.paca.id]))
response = self.client.get(
Expand All @@ -133,7 +133,7 @@ def test_regions_with_other_datasets(self):
def test_towns_with_other_datasets_logged_in(self):
self.login()
organization = OrganizationFactory()
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.arles.id]))
response = self.client.get(
Expand All @@ -150,7 +150,7 @@ def test_towns_with_other_datasets_logged_in(self):
def test_counties_with_other_datasets_logged_in(self):
self.login()
organization = OrganizationFactory()
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.bdr.id]))
response = self.client.get(
Expand All @@ -167,7 +167,7 @@ def test_counties_with_other_datasets_logged_in(self):
def test_regions_with_other_datasets_logged_in(self):
self.login()
organization = OrganizationFactory()
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.paca.id]))
response = self.client.get(
Expand All @@ -185,7 +185,7 @@ def test_towns_with_other_datasets_and_pertinent_ones(self):
user = self.login()
member = Member(user=user, role='admin')
organization = OrganizationFactory(members=[member])
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.arles.id]))
response = self.client.get(
Expand All @@ -209,7 +209,7 @@ def test_counties_with_other_datasets_and_pertinent_ones(self):
user = self.login()
member = Member(user=user, role='admin')
organization = OrganizationFactory(members=[member])
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.bdr.id]))
response = self.client.get(
Expand All @@ -233,7 +233,7 @@ def test_regions_with_other_datasets_and_pertinent_ones(self):
user = self.login()
member = Member(user=user, role='admin')
organization = OrganizationFactory(members=[member])
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.paca.id]))
response = self.client.get(
Expand All @@ -254,7 +254,7 @@ def test_regions_with_other_datasets_and_pertinent_ones(self):

def test_with_town_datasets(self):
organization = OrganizationFactory(zone=self.arles.id)
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.arles.id]))
response = self.client.get(
Expand All @@ -276,7 +276,7 @@ def test_with_town_datasets(self):

def test_with_county_datasets(self):
organization = OrganizationFactory(zone=self.bdr.id)
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.bdr.id]))
response = self.client.get(
Expand All @@ -298,7 +298,7 @@ def test_with_county_datasets(self):

def test_with_region_datasets(self):
organization = OrganizationFactory(zone=self.paca.id)
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[self.paca.id]))
response = self.client.get(
Expand All @@ -322,7 +322,7 @@ def test_with_old_region_datasets(self):
lr, occitanie = create_old_new_regions_fixtures()
for region in [lr, occitanie]:
organization = OrganizationFactory(zone=region.id)
VisibleDatasetFactory.create_batch(
DatasetFactory.create_batch(
3, organization=organization,
spatial=SpatialCoverageFactory(zones=[region.id]))
response = self.client.get(
Expand Down
6 changes: 3 additions & 3 deletions udata_front/tests/views/test_topic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from flask import url_for

# from udata.core.dataset.factories import VisibleDatasetFactory
# from udata.core.dataset.factories import DatasetFactory
# from udata.core.reuse.factories import VisibleReuseFactory
# from udata.core.topic.factories import TopicFactory
# from udata_front.tests import GouvFrSettings
Expand All @@ -16,7 +16,7 @@
# with self.autoindex():
# reuses = [VisibleReuseFactory(tags=['tag-{0}'.format(i)])
# for i in range(3)]
# datasets = [VisibleDatasetFactory(tags=['tag-{0}'.format(i)])
# datasets = [DatasetFactory(tags=['tag-{0}'.format(i)])
# for i in range(3)]
# topic = TopicFactory(
# tags=['tag-0', 'tag-2'], datasets=datasets, reuses=reuses)
Expand All @@ -35,7 +35,7 @@
# def test_render_datasets(self):
# '''It should render a topic datasets page'''
# with self.autoindex():
# [VisibleDatasetFactory(tags=['tag-{0}'.format(i)])
# [DatasetFactory(tags=['tag-{0}'.format(i)])
# for i in range(3)]
# topic = TopicFactory(tags=['tag-0', 'tag-2'])

Expand Down

0 comments on commit ca06c43

Please sign in to comment.