Exemplo n.º 1
0
 def portals(obj, create, extracted=None, **kwargs):
     if create:
         if extracted:
             for portal in extracted:
                 obj.portal.add(portal)
         else:
             obj.portal.add(TargetPortalFactory.create())
Exemplo n.º 2
0
 def test_command_post_migration(self, mock_stdout):
     portal = TargetPortalFactory.create(name="Test", title=None)
     self.assertEqual(portal.title_fr, "")
     self.assertEqual(portal.description_fr, "")
     call_command('update_post_migration_languages')
     changed_portal = TargetPortal.objects.get(name="Test")
     self.assertEqual(changed_portal.title_fr, "Geotrek Rando")
     self.assertEqual(
         changed_portal.description_fr,
         "Geotrek est une web app permettant de préparer à "
         "l'avance ses randonnées !")
Exemplo n.º 3
0
    def test_api_filters(self):
        SiteFactory.create(name='site1', published=False)
        SiteFactory.create(name='site2', published=True)
        site3 = SiteFactory.create(name='site3', published=True)
        site3.source.add(RecordSourceFactory.create(name='source1'))
        site3.portal.add(TargetPortalFactory.create(name='portal1'))

        response1 = self.client.get('/api/en/sites.json')
        self.assertEqual(len(response1.json()), 2)
        self.assertEqual(set((site['name'] for site in response1.json())),
                         set(('site2', 'site3')))

        response2 = self.client.get('/api/en/sites.json?source=source1')
        self.assertEqual(len(response2.json()), 1)
        self.assertEqual(response2.json()[0]['name'], 'site3')

        response3 = self.client.get('/api/en/sites.json?portal=portal1')
        self.assertEqual(len(response3.json()), 2)
        self.assertEqual(set((site['name'] for site in response3.json())),
                         set(('site2', 'site3')))

        response4 = self.client.get('/api/en/sites.json?portal=portalX')
        self.assertEqual(len(response4.json()), 1)
        self.assertEqual(response4.json()[0]['name'], 'site2')