Skip to content

Commit

Permalink
fixe tests with correct language
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Nov 15, 2023
1 parent 79910d6 commit b4ac5a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
5 changes: 3 additions & 2 deletions geotrek/trekking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ def __str__(self):
def get_map_image_url(self):
return reverse('trekking:trek_map_image', args=[str(self.pk), get_language()])

def get_map_image_path(self):
def get_map_image_path(self, language=None):
lang = language or get_language()
basefolder = os.path.join(settings.MEDIA_ROOT, 'maps')
if not os.path.exists(basefolder):
os.makedirs(basefolder)
return os.path.join(basefolder, '%s-%s-%s.png' % (self._meta.model_name, self.pk, get_language()))
return os.path.join(basefolder, '%s-%s-%s.png' % (self._meta.model_name, self.pk, lang))

def get_map_image_extent(self, srid=settings.API_SRID):
extent = list(super().get_map_image_extent(srid))
Expand Down
62 changes: 30 additions & 32 deletions geotrek/trekking/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,86 +1574,84 @@ def test_detail(self):
})


class TestDepublishSignagesRemovedFromPDF(TestCase):

class TrekPDFChangeAlongLinkedSignages(TestCase):
def setUp(self):
self.trek = TrekWithSignagesFactory.create()

@mock.patch('mapentity.helpers.requests.get')
def test_depublish_signage_refreshes_pdf(self, mock_get):
def test_unpublish_signage_refreshes_pdf(self, mock_get):
# Mock map screenshot
mock_get.return_value.status_code = 200
mock_get.return_value.content = b'xxx'
# Assert first access to PDF will trigger screenshot
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path(), self.trek.get_date_update()))
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
self.client.get(
reverse('trekking:trek_printable', kwargs={'lang': 'fr', 'pk': self.trek.pk, 'slug': self.trek.slug}))
# Assert second access to PDF will not trigger screenshot
trek = Trek.objects.get(pk=self.trek.pk)
self.assertTrue(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.refresh_from_db()
self.assertTrue(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
# Assert access to PDF if signages were changed will trigger screenshot
trek.signages[0].published = False
trek.signages[0].save()
trek = Trek.objects.get(pk=self.trek.pk)
self.assertFalse(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.signages[0].published = False
self.trek.signages[0].save()
self.trek.refresh_from_db()
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))

@mock.patch('mapentity.helpers.requests.get')
def test_delete_signage_refreshes_pdf(self, mock_get):
# Mock map screenshot
mock_get.return_value.status_code = 200
mock_get.return_value.content = b'xxx'
# Assert first access to PDF will trigger screenshot
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path(), self.trek.get_date_update()))
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
self.client.get(
reverse('trekking:trek_printable', kwargs={'lang': 'fr', 'pk': self.trek.pk, 'slug': self.trek.slug}))
# Assert second access to PDF will not trigger screenshot
trek = Trek.objects.get(pk=self.trek.pk)
self.assertTrue(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.refresh_from_db()
self.assertTrue(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
# Assert access to PDF if signage was deleted will trigger screenshot
trek.signages[0].delete()
trek = Trek.objects.get(pk=self.trek.pk)
self.assertFalse(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))

self.trek.signages[0].delete()
self.trek.refresh_from_db()
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))

class TestDepublishInfrastructuresRemovedFromPDF(TestCase):

class TrekPDFChangeAlongLinkedInfrastructures(TestCase):
def setUp(self):
self.trek = TrekWithInfrastructuresFactory.create()

@mock.patch('mapentity.helpers.requests.get')
def test_depublish_infrastructure_refreshes_pdf(self, mock_get):
def test_unpublish_infrastructure_refreshes_pdf(self, mock_get):
# Mock map screenshot
mock_get.return_value.status_code = 200
mock_get.return_value.content = b'xxx'
# Assert first access to PDF will trigger screenshot
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path(), self.trek.get_date_update()))
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
self.client.get(
reverse('trekking:trek_printable', kwargs={'lang': 'fr', 'pk': self.trek.pk, 'slug': self.trek.slug}))
# Assert second access to PDF will not trigger screenshot
trek = Trek.objects.get(pk=self.trek.pk)
self.assertTrue(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.refresh_from_db()
self.assertTrue(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
# Assert access to PDF if signages were changed will trigger screenshot
trek.infrastructures[0].published = False
trek.infrastructures[0].save()
trek = Trek.objects.get(pk=self.trek.pk)
self.assertFalse(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.infrastructures[0].published = False
self.trek.infrastructures[0].save()
self.trek.refresh_from_db()
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))

@mock.patch('mapentity.helpers.requests.get')
def test_delete_infrastructure_refreshes_pdf(self, mock_get):
# Mock map screenshot
mock_get.return_value.status_code = 200
mock_get.return_value.content = b'xxx'
# Assert first access to PDF will trigger screenshot
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path(), self.trek.get_date_update()))
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
self.client.get(
reverse('trekking:trek_printable', kwargs={'lang': 'fr', 'pk': self.trek.pk, 'slug': self.trek.slug}))
# Assert second access to PDF will not trigger screenshot
trek = Trek.objects.get(pk=self.trek.pk)
self.assertTrue(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.refresh_from_db()
self.assertTrue(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))
# Assert access to PDF if signage was deleted will trigger screenshot
trek.infrastructures[0].delete()
trek = Trek.objects.get(pk=self.trek.pk)
self.assertFalse(is_file_uptodate(trek.get_map_image_path(), trek.get_date_update()))
self.trek.infrastructures[0].delete()
self.trek.refresh_from_db()
self.assertFalse(is_file_uptodate(self.trek.get_map_image_path('fr'), self.trek.get_date_update()))


class TrekFilterTest(TestCase):
Expand Down

0 comments on commit b4ac5a1

Please sign in to comment.