コード例 #1
0
    def test_unset_structure_without_structure_keep_pk(self):
        structure = StructureFactory.create(name="Test")
        infratype_no_structure = InfrastructureTypeFactory.create(
            label="type1", structure=None, pictogram=None)
        InfrastructureFactory.create(name='infra1',
                                     type=infratype_no_structure)
        infratype_structure = InfrastructureTypeFactory.create(
            label="type2", structure=structure, pictogram=None)
        InfrastructureFactory.create(name='infra2', type=infratype_structure)

        self.assertEqual(InfrastructureType.objects.count(), 2)
        self.assertIsNone(infratype_no_structure.structure)
        self.assertIsNotNone(infratype_structure.structure)
        old_pk_no_structure = infratype_no_structure.pk
        old_pk_structure = infratype_structure.pk
        call_command('unset_structure', '--all', verbosity=0)
        type1 = InfrastructureType.objects.get(label="type1")
        type2 = InfrastructureType.objects.get(label="type1")
        new_pk_no_structure = type1.pk
        new_pk_structure = type2.pk

        self.assertEqual(old_pk_no_structure, new_pk_no_structure)
        self.assertNotEqual(old_pk_structure, new_pk_structure)

        self.assertIsNone(type1.structure)
        self.assertIsNone(type2.structure)
コード例 #2
0
ファイル: tests.py プロジェクト: Babawah/Geotrek
    def test_manager(self):
        it1 = InfrastructureTypeFactory.create()
        it2 = InfrastructureTypeFactory.create()
        it3 = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.SIGNAGE)

        self.assertNotEqual(InfrastructureType.objects.for_signages(), InfrastructureType.objects.for_infrastructures())
        self.assertItemsEqual(InfrastructureType.objects.for_signages(), [it3])
        self.assertItemsEqual(InfrastructureType.objects.for_infrastructures(), [it1, it2])
        self.assertItemsEqual(InfrastructureType.objects.all(), [it1, it2, it3])
コード例 #3
0
    def test_manager(self):
        it1 = InfrastructureTypeFactory.create()
        it2 = InfrastructureTypeFactory.create()
        it3 = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.SIGNAGE)

        self.assertNotEqual(InfrastructureType.objects.for_signages(),
                            InfrastructureType.objects.for_infrastructures())
        self.assertItemsEqual(InfrastructureType.objects.for_signages(), [it3])
        self.assertItemsEqual(InfrastructureType.objects.for_infrastructures(),
                              [it1, it2])
        self.assertItemsEqual(InfrastructureType.objects.all(), [it1, it2, it3])
コード例 #4
0
    def test_command_unset_structure(self):
        structure1 = StructureFactory.create(name="coucou")
        structure2 = StructureFactory.create(name="coco")

        infratype1 = InfrastructureTypeFactory.create(label="annyeong",
                                                      structure=structure1,
                                                      pictogram=None)
        infratype2 = InfrastructureTypeFactory.create(label="annyeong",
                                                      structure=structure2,
                                                      pictogram=None)

        path = PathFactory.create(name="pass")
        usage1 = UsageFactory.create(usage="hello", structure=structure1)
        usage2 = UsageFactory.create(usage="hello", structure=structure2)
        path.usages.add(usage1)
        path.usages.add(usage2)

        infrastructure1 = InfrastructureFactory.create(name='pissenlit',
                                                       type=infratype1)
        infrastructure2 = InfrastructureFactory.create(name='rhododendron',
                                                       type=infratype2)

        self.assertEqual(InfrastructureType.objects.count(), 2)
        self.assertEqual(Usage.objects.count(), 2)

        self.assertEqual(infrastructure1.type.label, 'annyeong')
        self.assertEqual(infrastructure1.type.structure.name, 'coucou')
        self.assertEqual(infrastructure2.type.label, 'annyeong')
        self.assertEqual(infrastructure2.type.structure.name, 'coco')

        self.assertEqual(path.usages.count(), 2)
        self.assertEqual(usage1.structure.name, 'coucou')
        self.assertEqual(usage2.structure.name, 'coco')
        output = StringIO()
        call_command('unset_structure', '--all', verbosity=2, stdout=output)
        response = output.getvalue()
        self.assertIn("Create hello", response)
        self.assertEqual(InfrastructureType.objects.count(), 1)
        self.assertEqual(Usage.objects.count(), 1)

        infra = Infrastructure.objects.first()

        self.assertEqual(infra.type.label, 'annyeong')
        self.assertEqual(infra.type.structure, None)

        path_usages = Path.objects.first().usages.first()

        self.assertEqual(path_usages.usage, 'hello')
        self.assertEqual(path_usages.structure, None)
コード例 #5
0
 def test_unset_structure_without_structure(self):
     infratype = InfrastructureTypeFactory.create(label="annyeong",
                                                  structure=None,
                                                  pictogram=None)
     self.assertEqual(InfrastructureType.objects.count(), 1)
     self.assertIsNone(infratype.structure)
     call_command('unset_structure', '--all', verbosity=0)
     self.assertIsNone(infratype.structure)
コード例 #6
0
ファイル: test_views.py プロジェクト: makinacorpus/Geotrek
 def test_check_structure_or_none_related_are_visible(self):
     self.login()
     infratype = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING, structure=None)
     response = self.client.get(self.model.get_add_url())
     self.assertEqual(response.status_code, 200)
     self.assertTrue('form' in response.context)
     form = response.context['form']
     type = form.fields['type']
     self.assertTrue((infratype.pk, unicode(infratype)) in type.choices)
コード例 #7
0
ファイル: tests.py プロジェクト: Babawah/Geotrek
 def get_good_data(self):
     path = PathFactory.create()
     return {
         "name": "test",
         "description": "oh",
         "structure": default_structure().pk,
         "type": InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         "topology": '{"paths": [%s]}' % path.pk,
     }
コード例 #8
0
 def get_good_data(self):
     PathFactory.create()
     return {
         'name': 'test',
         'description': 'oh',
         'structure': default_structure().pk,
         'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         'topology': '{"lat": 0.42, "lng": 0.666}'
     }
コード例 #9
0
ファイル: tests.py プロジェクト: adrianmo/Geotrek
 def get_good_data(self):
     PathFactory.create()
     return {
         'name': 'test',
         'description': 'oh',
         'structure': default_structure().pk,
         'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         'topology': '{"lat": 0.42, "lng": 0.666}'
     }
コード例 #10
0
ファイル: tests.py プロジェクト: Babawah/Geotrek
 def get_good_data(self):
     PathFactory.create()
     return {
         "name": "test",
         "description": "oh",
         "structure": default_structure().pk,
         "type": InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         "topology": '{"lat": 0.42, "lng": 0.666}',
     }
コード例 #11
0
 def get_good_data(self):
     path = PathFactory.create()
     return {
         'name': 'test',
         'description': 'oh',
         'structure': default_structure().pk,
         'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         'topology': '{"paths": [%s]}' % path.pk,
     }
コード例 #12
0
ファイル: tests.py プロジェクト: adrianmo/Geotrek
 def get_good_data(self):
     path = PathFactory.create()
     return {
         'name': 'test',
         'description': 'oh',
         'structure': default_structure().pk,
         'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         'topology': '{"paths": [%s]}' % path.pk,
     }
コード例 #13
0
ファイル: test_admin.py プロジェクト: makinacorpus/Geotrek
    def test_infrastructuretype_cannot_be_change_not_same_structure(self):
        self.login()
        structure = StructureFactory(name="Other")
        infra = InfrastructureTypeFactory.create(structure=structure)
        change_url = reverse('admin:infrastructure_infrastructuretype_change', args=[infra.pk])
        response = self.client.get(change_url)
        self.assertEquals(response.status_code, 302)
        self.assertEqual(InfrastructureType.objects.get(pk=self.infra.pk).label, self.infra.label)

        self.assertEqual(response.url, '/admin/')
コード例 #14
0
 def test_check_structure_or_none_related_are_visible(self):
     self.login()
     infratype = InfrastructureTypeFactory.create(
         type=INFRASTRUCTURE_TYPES.BUILDING, structure=None)
     response = self.client.get(self.model.get_add_url())
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, 'form')
     form = response.context['form']
     type = form.fields['type']
     self.assertTrue((infratype.pk, str(infratype)) in type.choices)
コード例 #15
0
ファイル: test_command.py プロジェクト: makinacorpus/Geotrek
    def test_command_unset_structure(self):
        structure1 = StructureFactory.create(name="coucou")
        structure2 = StructureFactory.create(name="coco")

        infratype1 = InfrastructureTypeFactory.create(label="annyeong", structure=structure1, pictogram=None)
        infratype2 = InfrastructureTypeFactory.create(label="annyeong", structure=structure2, pictogram=None)

        path = PathFactory.create(name="pass")
        usage1 = UsageFactory.create(usage="hello", structure=structure1)
        usage2 = UsageFactory.create(usage="hello", structure=structure2)
        path.usages.add(usage1)
        path.usages.add(usage2)

        infrastructure1 = InfrastructureFactory.create(name='pissenlit', type=infratype1)
        infrastructure2 = InfrastructureFactory.create(name='rhododendron', type=infratype2)

        self.assertEqual(InfrastructureType.objects.count(), 2)
        self.assertEqual(Usage.objects.count(), 2)

        self.assertEqual(infrastructure1.type.label, 'annyeong')
        self.assertEqual(infrastructure1.type.structure.name, 'coucou')
        self.assertEqual(infrastructure2.type.label, 'annyeong')
        self.assertEqual(infrastructure2.type.structure.name, 'coco')

        self.assertEqual(path.usages.count(), 2)
        self.assertEqual(usage1.structure.name, 'coucou')
        self.assertEqual(usage2.structure.name, 'coco')
        output = StringIO()
        call_command('unset_structure', '--all', verbosity=2, stdout=output)
        response = output.getvalue()
        self.assertIn("Create hello", response)
        self.assertEqual(InfrastructureType.objects.count(), 1)
        self.assertEqual(Usage.objects.count(), 1)

        infra = Infrastructure.objects.first()

        self.assertEqual(infra.type.label, 'annyeong')
        self.assertEqual(infra.type.structure, None)

        path_usages = Path.objects.first().usages.first()

        self.assertEqual(path_usages.usage, 'hello')
        self.assertEqual(path_usages.structure, None)
コード例 #16
0
    def test_infrastructuretype_cannot_be_change_not_same_structure(self):
        self.login()
        structure = StructureFactory(name="Other")
        infra = InfrastructureTypeFactory.create(structure=structure)
        change_url = reverse('admin:infrastructure_infrastructuretype_change', args=[infra.pk])
        response = self.client.get(change_url)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(InfrastructureType.objects.get(pk=self.infra.pk).label, self.infra.label)

        self.assertEqual(response.url, '/admin/')
コード例 #17
0
 def setUp(self):
     self.user = UserFactory.create(password='******')
     self.client.login(username=self.user.username, password='******')
     self.user.user_permissions.add(Permission.objects.get(codename='add_draft_path'))
     for perm in Permission.objects.exclude(codename='can_bypass_structure'):
         self.user.user_permissions.add(perm)
     self.user.is_staff = True
     self.user.save()
     p = self.user.profile
     structure = StructureFactory(name="This")
     p.structure = structure
     p.save()
     self.infra = InfrastructureTypeFactory.create(structure=structure)
コード例 #18
0
ファイル: test_admin.py プロジェクト: makinacorpus/Geotrek
 def setUp(self):
     self.user = UserFactory.create(password='******')
     self.client.login(username=self.user.username, password='******')
     self.user.user_permissions.add(Permission.objects.get(codename='add_draft_path'))
     for perm in Permission.objects.exclude(codename='can_bypass_structure'):
         self.user.user_permissions.add(perm)
     self.user.is_staff = True
     self.user.save()
     p = self.user.profile
     structure = StructureFactory(name="This")
     p.structure = structure
     p.save()
     self.infra = InfrastructureTypeFactory.create(structure=structure)
コード例 #19
0
 def get_good_data(self):
     good_data = {
         'name':
         'test',
         'description':
         'oh',
         'type':
         InfrastructureTypeFactory.create(
             type=INFRASTRUCTURE_TYPES.BUILDING).pk,
         'condition':
         InfrastructureConditionFactory.create().pk,
     }
     if settings.TREKKING_TOPOLOGY_ENABLED:
         path = PathFactory.create()
         good_data['topology'] = '{"paths": [%s]}' % path.pk
     else:
         good_data['geom'] = 'LINESTRING (0.0 0.0, 1.0 1.0)'
     return good_data
コード例 #20
0
 def test_unset_structure_fail_no_model_not_all(self):
     InfrastructureTypeFactory.create(label="annyeong",
                                      structure=None,
                                      pictogram=None)
     with self.assertRaisesRegexp(CommandError, "You should specify model"):
         call_command('unset_structure', verbosity=0)
コード例 #21
0
 def get_good_data(self):
     data = super(SignageViewsTest, self).get_good_data()
     data['type'] = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.SIGNAGE).pk
     data['condition'] = InfrastructureConditionFactory.create().pk
     return data
コード例 #22
0
ファイル: tests.py プロジェクト: amandine-sahl/Geotrek
 def get_good_data(self):
     data = super(SignageViewsTest, self).get_good_data()
     data['type'] = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.SIGNAGE).pk
     data['condition'] = InfrastructureConditionFactory.create().pk
     return data
コード例 #23
0
ファイル: test_command.py プロジェクト: makinacorpus/Geotrek
 def test_unset_structure_without_structure(self):
     infratype = InfrastructureTypeFactory.create(label="annyeong", structure=None, pictogram=None)
     self.assertEqual(InfrastructureType.objects.count(), 1)
     self.assertIsNone(infratype.structure)
     call_command('unset_structure', '--all', verbosity=0)
     self.assertIsNone(infratype.structure)
コード例 #24
0
 def setUp(self):
     self.user = SuperUserFactory.create(password='******')
     self.infra = InfrastructureTypeFactory.create()
コード例 #25
0
ファイル: test_admin.py プロジェクト: makinacorpus/Geotrek
 def setUp(self):
     self.user = SuperUserFactory.create(password='******')
     self.infra = InfrastructureTypeFactory.create()