Exemple #1
0
    def test_group(self):
        groups = (
            Group.objects.get(name=auth_models.GROUP_EDITOR),
            Group.objects.get(name=auth_models.GROUP_PATH_MANAGER),
            Group.objects.get(name=auth_models.GROUP_TREKKING_MANAGER),
        )
        user = UserFactory()
        self.assertFalse(user.profile.is_editor)
        self.assertFalse(user.profile.is_path_manager)
        self.assertFalse(user.profile.is_trekking_manager)

        user = UserFactory(groups=groups)
        self.assertTrue(user.profile.is_editor)
        self.assertTrue(user.profile.is_path_manager)
        self.assertTrue(user.profile.is_trekking_manager)
    def test_paths_bystructure(self):
        user = UserFactory()
        p1 = PathFactory()
        p2 = PathFactory(structure=Structure.objects.create(name="other"))

        self.assertEqual(user.profile.structure, p1.structure)
        self.assertNotEqual(user.profile.structure, p2.structure)

        self.assertEqual(len(Structure.objects.all()), 2)
        self.assertEqual(len(Path.objects.all()), 2)

        self.assertTrue(p1 in Path.objects.filter(
            structure=user.profile.structure))
        self.assertFalse(p2 in Path.objects.filter(
            structure=user.profile.structure))

        # Change user structure on-the-fly
        profile = user.profile
        profile.structure = p2.structure
        profile.save()

        self.assertEqual(user.profile.structure.name, "other")
        self.assertFalse(p1 in Path.objects.filter(
            structure=user.profile.structure))
        self.assertTrue(p2 in Path.objects.filter(
            structure=user.profile.structure))
Exemple #3
0
    def test_paths_bystructure(self):
        PathFactory(length=1)
        PathFactory(length=70)
        
        password = '******'
        user = UserFactory(password=password)
        result = self.client.login(username=user.username, password=password)
        self.assertTrue(result, u"The client successfully logged in")

        response = self.client.get(reverse('core:path_list'))
        self.assertEquals(response.status_code, 200)

        def create_form_params(range_start='', range_end=''):
            """Return range form parameter as used in geotrek.core.filters.PathFilter"""
            return { 'length_0': range_end, 'length_1': range_start }

        def test_response_content(length_range, queryset):
            response = self.client.get(reverse('core:path_json_list'), data=create_form_params(*length_range))
            self.assertEquals(response.status_code, 200)
            # We check the 'map_obj_pk' json attribute that should contain the paths' pk (used by map)
            jsondict = json.loads(response.content)
            # The JSON should only contain filtered paths
            self.assertListEqual(
                    sorted(jsondict['map_obj_pk']),
                    sorted(list(queryset.values_list('pk', flat=True))),
            )

        # Simulate ajax call to populate the list
        # The path returned as json should be all paths
        test_response_content(['', ''], Path.objects.all())

        # Simulate ajax call to populate the list, but this time with a range filter
        length_range = [50, 100]
        test_response_content(length_range, Path.objects.filter(length__range=length_range))
Exemple #4
0
 def test_save_form_when_topology_has_not_changed(self):
     user = UserFactory()
     topo = TrailFactory()
     form = TrailForm(instance=topo, user=user)
     self.assertEqual(topo, form.instance)
     form.cleaned_data = {'topology': topo}
     form.save()
     self.assertEqual(topo, form.instance)
Exemple #5
0
class UserProfileTest(TestCase):
    def setUp(self):
        self.user = UserFactory(password=u"Bar")

    def test_profile(self):
        self.assertTrue(isinstance(self.user.profile, UserProfile))
        self.assertEqual(self.user.profile, self.user.get_profile())

        self.assertEqual(self.user.profile.structure.name, settings.DEFAULT_STRUCTURE_NAME)
        self.assertEqual(self.user.profile.language, settings.LANGUAGE_CODE)

    def test_language(self):
        success = self.client.login(username=self.user.username, password=u"Bar")
        self.assertTrue(success)
        response = self.client.get(reverse('core:path_list'))
        self.assertEqual(200, response.status_code)
        self.assertTrue(str(_("Logout")) in response.content)

        # Change user lang
        self.assertNotEqual(settings.LANGUAGE_CODE, u"en")
        userprofile = UserProfile.objects.get(user=self.user)
        userprofile.language = u"en"
        userprofile.save()
        self.assertEqual(self.user.profile.language, u"en")
        # No effect if no logout
        response = self.client.get(reverse('core:path_list'))
        self.assertTrue(str(_("Logout")) in response.content)

        self.client.logout()

        self.client.login(username=self.user.username, password=u"Bar")
        response = self.client.get(reverse('core:path_list'))
        self.assertEqual(self.client.session['django_language'], u"en")
        self.assertTrue("Logout" in response.content)

    def test_admin(self):
        self.assertFalse(self.user.is_staff)
        success = self.client.login(username=self.user.username, password=u"Bar")
        self.assertTrue(success)
        response = self.client.get(reverse('core:path_list'))
        self.assertFalse(_("Admin") in response.content)

        self.user.is_staff = True
        self.user.save()
        response = self.client.get(reverse('core:path_list'))
        self.assertTrue(_("Admin") in response.content)
Exemple #6
0
 def test_external_public_document_pdf(self):
     content = TouristicContentFactory.create(published=True)
     Attachment.objects.create(
         filetype=FileType.objects.create(type="Topoguide"),
         content_object=content,
         creator=UserFactory.create(),
         attachment_file=SimpleUploadedFile('external.pdf',
                                            b'External PDF'))
     rmtree(settings.MEDIA_ROOT)
     url = '/api/en/touristiccontents/{pk}/slug.pdf'.format(pk=content.pk)
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         response['X-Accel-Redirect'],
         '/media_secure/paperclip/tourism_touristiccontent/{}/external.pdf'.
         format(content.pk))
Exemple #7
0
 def test_ratings_save(self):
     user = UserFactory()
     rating = RatingFactory()
     site = SiteFactory(practice=rating.scale.practice)
     form = SiteForm(
         user=user,
         instance=site,
         data={
             'name_en': 'Site',
             'geom':
             '{"type": "GeometryCollection", "geometries": [{"type": "Point", "coordinates": [3, 45]}]}',
             'practice': str(rating.scale.practice.pk),
             'rating_scale_min{}'.format(rating.scale.pk): str(rating.pk),
         })
     self.assertTrue(form.is_valid())
     form.save()
     self.assertQuerysetEqual(site.ratings_min.all(), ['<Rating: Rating>'])
     self.assertQuerysetEqual(site.ratings_max.all(), [])
Exemple #8
0
    def test_path_manager_restricted(self):
        p = PathFactory()
        # Try to edit path as user
        user = UserFactory(password="******")
        self.assertFalse(user.profile.is_path_manager)
        success = self.client.login(username=user.username, password="******")
        self.assertTrue(success)
        response = self.client.get(p.get_update_url())
        self.assertEqual(response.status_code, 302)
        self.client.logout()

        # Try to edit path as manager
        manager = PathManagerFactory(password="******")
        self.assertTrue(manager.profile.is_path_manager)
        success = self.client.login(username=manager.username, password="******")
        self.assertTrue(success)
        response = self.client.get(p.get_update_url())
        self.assertEqual(response.status_code, 200)
Exemple #9
0
 def test_overlapping_path(self):
     user = UserFactory()
     PathFactory.create(geom='SRID=4326;LINESTRING(3 45, 3 46)')
     # Just intersecting
     form1 = PathForm(
         user=user,
         data={
             'geom':
             '{"geom": "LINESTRING(2.5 45.5, 3.5 45.5)", "snap": [null, null]}'
         })
     self.assertTrue(form1.is_valid(), str(form1.errors))
     # Overlapping
     form2 = PathForm(
         user=user,
         data={
             'geom':
             '{"geom": "LINESTRING(3 45.5, 3 46.5)", "snap": [null, null]}'
         })
     self.assertFalse(form2.is_valid(), str(form2.errors))
Exemple #10
0
 def setUpTestData(cls):
     cls.user = UserFactory()
     cls.rating = RatingFactory()
     cls.course = CourseFactory(site__practice=cls.rating.scale.practice)
Exemple #11
0
 def setUp(self):
     self.user = UserFactory(password=u"Bar")
 def setUp(self):
     self.user = UserFactory(password='******')
Exemple #13
0
 def setUp(self):
     self.user = UserFactory()
     self.trek1 = TrekFactory(name="1")
     self.trek2 = TrekFactory(name="2")
     self.trek3 = TrekFactory(name="3")
 def setUp(self):
     self.user = UserFactory()
     self.signage = SignageFactory()