Ejemplo n.º 1
0
 def test_structure_restricted(self):
     p = PathFactory()
     # Login
     user = PathManagerFactory(password="******")
     success = self.client.login(username=user.username, password="******")
     self.assertTrue(success)
     # Try to edit path from same structure
     response = self.client.get(p.get_update_url())
     self.assertEqual(response.status_code, 200)
     # Try to edit path from other structure
     p.structure = StructureFactory(name="Other")
     p.save()
     self.assertNotEqual(p.structure, user.profile.structure)
     response = self.client.get(p.get_update_url())
     self.assertEqual(response.status_code, 302)
Ejemplo n.º 2
0
 def test_structure_restricted(self):
     p = PathFactory()
     # Login
     user = PathManagerFactory(password="******")
     success = self.client.login(username=user.username, password="******")
     self.assertTrue(success)
     # Try to edit path from same structure
     response = self.client.get(p.get_update_url())
     self.assertEqual(response.status_code, 200)
     # Try to edit path from other structure
     p.structure = StructureFactory(name="Other")
     p.save()
     self.assertNotEqual(p.structure, user.profile.structure)
     response = self.client.get(p.get_update_url())
     self.assertEqual(response.status_code, 302)
Ejemplo n.º 3
0
    def test_upload(self):
        path = PathFactory(length=1)
        response = self.client.get(path.get_update_url())

        f = get_dummy_uploaded_image()
        data = {
            'filetype': FileTypeFactory().pk,
            'title': 'title1',
            'legend': 'legend1',
            'attachment_file': f,
        }

        response = self.client.post(add_url_for_obj(path), data=data)
        self.assertEquals(response.status_code, 302)

        att = Attachment.objects.attachments_for_object(path).get()
        self.assertEqual(att.title, data['title'])
        self.assertEqual(att.legend, data['legend'])
        self.assertEqual(att.filetype.pk, data['filetype'])

        f.open()
        self.assertEqual(att.attachment_file.readlines(), f.readlines())

        # Check that if title is given, filename is title
        self.assertTrue(att.attachment_file.name, 'title1')

        # Check that if no title is give, filename is original name
        data['title'] = ''
        response = self.client.post(add_url_for_obj(path), data=data)
        att = Attachment.objects.attachments_for_object(path)[0]
        self.assertTrue(att.attachment_file.name, 'image')
Ejemplo n.º 4
0
    def test_upload(self):
        path = PathFactory(length=1)
        response = self.client.get(path.get_update_url())

        f = get_dummy_uploaded_image()
        data = {"filetype": FileTypeFactory().pk, "title": "title1", "legend": "legend1", "attachment_file": f}

        response = self.client.post(add_url_for_obj(path), data=data)
        self.assertEquals(response.status_code, 302)

        att = Attachment.objects.attachments_for_object(path).get()
        self.assertEqual(att.title, data["title"])
        self.assertEqual(att.legend, data["legend"])
        self.assertEqual(att.filetype.pk, data["filetype"])

        f.open()
        self.assertEqual(att.attachment_file.readlines(), f.readlines())

        # Check that if title is given, filename is title
        self.assertTrue(att.attachment_file.name, "title1")

        # Check that if no title is give, filename is original name
        data["title"] = ""
        response = self.client.post(add_url_for_obj(path), data=data)
        att = Attachment.objects.attachments_for_object(path)[0]
        self.assertTrue(att.attachment_file.name, "image")
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def test_draft_permission_detail(self):
     path = PathFactory(name="DRAFT_PATH", draft=True)
     user = UserFactory(password='******')
     p = user.profile
     p.save()
     perm_add_draft_path = Permission.objects.get(codename='add_draft_path')
     perm_delete_draft_path = Permission.objects.get(codename='delete_draft_path')
     perm_change_draft_path = Permission.objects.get(codename='change_draft_path')
     perm_read_path = Permission.objects.get(codename='read_path')
     user.user_permissions.add(perm_delete_draft_path)
     user.user_permissions.add(perm_read_path)
     user.user_permissions.add(perm_change_draft_path)
     user.user_permissions.add(perm_add_draft_path)
     self.client.login(username=user.username, password='******')
     response = self.client.get(path.get_update_url())
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, path.get_delete_url())