Пример #1
0
    def setUp(self):
        self.site = LearningSiteFactory()

        grp = GroupFactory(name='Editor')

        self.editor = UserFactory()
        self.editor.groups.add(grp)

        self.creator = UserFactory()
        self.creator.groups.add(grp)

        self.site = LearningSiteFactory(created_by=self.creator)
        self.url = reverse('site-delete-view', kwargs={'pk': self.site.id})
Пример #2
0
    def setUp(self):
        self.site = LearningSiteFactory()
        self.parent = LearningSiteFactory()

        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')
Пример #3
0
    def test_editor(self):
        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')
        response = self.client.get(self.create_url)
        self.assertEquals(response.status_code, 200)
        response = self.client.get(self.edit_url)
        self.assertEquals(response.status_code, 200)
        response = self.client.get(self.delete_url)
        self.assertEquals(response.status_code, 200)

        response = self.client.post(self.create_url, {
            'ordinal': 2,
            'note': 'Something'
        })
        self.assertEquals(response.status_code, 302)
        self.assertEquals(self.site.footnotes.count(), 2)

        response = self.client.post(self.edit_url, {
            'ordinal': 2,
            'note': 'Changed'
        })
        self.assertEquals(response.status_code, 302)
        self.footnote.refresh_from_db()
        self.assertEquals(self.footnote.note, 'Changed')

        response = self.client.post(self.delete_url, {})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(self.site.footnotes.count(), 1)
        self.assertEquals(self.site.footnotes.first().note, 'Something')
Пример #4
0
    def test_create(self):
        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 200)

        data = {
            'collection_title': 'New',
            'description': '',
            'finding_aid_url': '',
            'repository': '{}'.format(self.repository.id),
            'linear_feet': '',
            'inclusive-start-millenium1': '2',
            'inclusive-start-century1': '0',
            'inclusive-start-decade1': '0',
            'inclusive-start-year1': '0',
            'inclusive-end-millenium1': '2',
            'inclusive-end-century1': '0',
            'inclusive-end-decade1': '0',
            'inclusive-end-year1': '1',
        }
        response = self.client.post(self.url, data)
        self.assertEquals(response.status_code, 302)

        collection = ArchivalCollection.objects.get(collection_title='New')
        self.assertTrue(
            collection.learning_sites.filter(title=self.site.title).exists())
        self.assertEquals(collection.inclusive_start.edtf_format, '2000')
        self.assertEquals(collection.inclusive_end.edtf_format, '2001')
Пример #5
0
    def test_anonymous(self):
        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 302)

        user = UserFactory()
        self.client.login(username=user.username, password='******')
        response = self.client.post(self.url)
        self.assertEquals(response.status_code, 302)
Пример #6
0
 def test_non_editor(self):
     user = UserFactory()
     self.client.login(username=user.username, password='******')
     response = self.client.get(self.create_url)
     self.assertEquals(response.status_code, 302)
     response = self.client.get(self.edit_url)
     self.assertEquals(response.status_code, 302)
     response = self.client.get(self.delete_url)
     self.assertEquals(response.status_code, 302)
Пример #7
0
    def test_delete(self):
        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(self.url, {})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(self.site.archivalcollection_set.count(), 0)
Пример #8
0
    def test_django_settings(self):
        request = RequestFactory()
        request.user = UserFactory()

        ctx = django_settings(request)
        self.assertEquals(ctx['settings']['GOOGLE_MAP_API'], '123456')
        self.assertFalse(ctx['is_editor'])

        request.user.groups.add(GroupFactory(name='Editor'))
        ctx = django_settings(request)
        self.assertTrue(ctx['is_editor'])
Пример #9
0
    def test_restricted_access(self):
        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 302)

        user = UserFactory()  # random user
        self.client.login(username=user.username, password='******')
        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 302)

        self.client.login(username=self.editor.username, password='******')
        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 302)
Пример #10
0
    def test_editor(self):
        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')
        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 200)

        view = DigitalObjectCreateView()
        view.request = RequestFactory()
        view.request.method = 'GET'
        view.kwargs = {'parent': self.site.id}
        view.parent = self.site
        view.object = None

        ctx = view.get_context_data()
        self.assertEquals(ctx['parent'], self.site)
Пример #11
0
    def test_link_and_unlink(self):
        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')

        response = self.client.get(self.link_url)
        self.assertEquals(response.status_code, 200)

        response = self.client.post(self.link_url,
                                    {'collection': self.collection.id})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(self.site.archivalcollection_set.count(), 1)
        self.assertEquals(self.site.archivalcollection_set.first(),
                          self.collection)

        response = self.client.get(self.unlink_url)
        self.assertEquals(response.status_code, 200)
        response = self.client.post(self.unlink_url, {})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(self.site.archivalcollection_set.count(), 0)
Пример #12
0
    def test_update(self):
        editor = UserFactory()
        editor.groups.add(GroupFactory(name='Editor'))
        self.client.login(username=editor.username, password='******')

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, 200)

        data = {
            'repository': self.collection.repository.id,
            'repository_title': 'foobarbaz',
            'title': 'Bar',
            'latlng': 'SRID=4326;POINT(1 1)',
            'collection_title': 'Updated',
            'description': '',
            'finding_aid_url': '',
            'linear_feet': '',
            'inclusive-start-millenium1': '2',
            'inclusive-start-century1': '0',
            'inclusive-start-decade1': '0',
            'inclusive-start-year1': '0',
            'inclusive-end-millenium1': '2',
            'inclusive-end-century1': '0',
            'inclusive-end-decade1': '0',
            'inclusive-end-year1': '1',
        }
        response = self.client.post(self.url, data)
        self.assertEquals(response.status_code, 302)

        self.collection.refresh_from_db()
        self.assertEquals(self.collection.collection_title, 'Updated')
        self.assertEquals(self.collection.inclusive_start.edtf_format, '2000')
        self.assertEquals(self.collection.inclusive_end.edtf_format, '2001')

        self.collection.repository.refresh_from_db()
        self.assertEquals(self.collection.repository.title, 'foobarbaz')
        self.collection.repository.place.refresh_from_db()
        self.assertEquals(self.collection.repository.place.title, 'Bar')
        self.assertEquals(self.collection.repository.place.latitude(), 1.0)
        self.assertEquals(self.collection.repository.place.longitude(), 1.0)
Пример #13
0
 def setUp(self):
     self.user = UserFactory(username='******')
     self.site1 = LearningSiteFactory(title='foo', created_by=self.user)
     self.site2 = LearningSiteFactory(title='bar')
Пример #14
0
 def setUp(self):
     self.user = UserFactory(username='******')
     self.coll1 = ArchivalCollectionFactory(collection_title='alpha')
     self.coll2 = ArchivalCollectionFactory(collection_title='beta')
Пример #15
0
 def setUp(self):
     super(TestCase, self).setUp()
     self.user = UserFactory()
Пример #16
0
    def setUp(self):
        self.user = UserFactory()
        self.user.groups.add(GroupFactory(name='Editor'))

        self.site = LearningSiteFactory()
        self.repository = ArchivalRepositoryFactory()
Пример #17
0
 def setUp(self):
     self.user = UserFactory()
     self.editor = GroupFactory(name='Editor')
     self.mapper = EditorMapper()
Пример #18
0
 def test_editor(self):
     editor = UserFactory()
     editor.groups.add(GroupFactory(name='Editor'))
     self.client.login(username=editor.username, password='******')
     response = self.client.get(self.url)
     self.assertEquals(response.status_code, 200)