Beispiel #1
0
 def setUp(self):
     self.collector = UserF.create()
     self.owner = UserF.create()
     self.anonymous = UserF.create()
     self.superuser = UserF.create(is_superuser=True)
     self.survey = SurveyF.create(id=1,
                                  collector_user=self.collector,
                                  owner=self.owner)
    def test_LocationSiteFormUpdateView_post_data(self):
        location_context_path = staticfiles_storage.path(
            'data/location_context_document.json')
        location_context_file = open(location_context_path)
        location_context_document = json.load(location_context_file)
        post_data = self.post_data
        post_data['refined_geomorphological_zone'] = ''
        loc_type = LocationTypeF(name='PointObservation',
                                 allowed_geometry='POINT')

        user = UserF.create(id=1)
        self.client.login(
            username=user.username,
            password='******',
        )
        location_site = LocationSiteF.create(
            location_type=loc_type,
            creator=user,
            location_context_document=location_context_document)
        post_data['id'] = location_site.id

        self.client.post('/location-site-form/update/?id={}'.format(
            location_site.id),
                         post_data,
                         follow=True)
        updated_location_site = LocationSite.objects.get(id=location_site.id)
        updated_location_context = LocationContext.objects.filter(
            site=location_site)
        self.assertEqual(updated_location_site.river.name, 'NXAMAGELE')
        self.assertTrue(
            updated_location_context.filter(
                group__key__icontains='catchment_area').exists())
        self.assertTrue(
            updated_location_context.filter(
                group__key='geo_class_recoded').exists())
        self.assertTrue(
            updated_location_context.value_from_key('geo_class_recoded') ==
            'Mountain headwater stream')

        # Test if there are no location context data
        location_site_2 = LocationSiteF.create(
            location_type=loc_type,
            creator=user,
        )
        post_data['id'] = location_site_2.id
        post_request_2 = self.client.post(
            '/location-site-form/update/?id={}'.format(location_site_2.id),
            post_data,
            follow=True)
        updated_location_context_2 = LocationContext.objects.filter(
            site=location_site_2)
        self.assertTrue(
            updated_location_context_2.filter(
                group__key__icontains='catchment_area').exists())
        self.assertTrue(
            updated_location_context_2.value_from_key('geo_class_recoded') ==
            'Mountain headwater stream')
        self.assertTrue(
            post_request_2.redirect_chain[0][0],
            '/location-site-form/update/?id={}'.format(location_site_2.id))
Beispiel #3
0
 def test_merge_users(self):
     """Test a function to merge multiple users"""
     user_1 = UserF.create()
     user_2 = UserF.create()
     BiologicalCollectionRecordF.create(owner=user_1, collector_user=user_2)
     BiologicalCollectionRecordF.create(owner=user_2, collector_user=user_1)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(owner=user_2).exists())
     merge_users(primary_user=user_1, user_list=[user_1.id, user_2.id])
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(owner=user_1).count(), 2)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(
             collector_user=user_1).count(), 2)
     self.assertFalse(
         BiologicalCollectionRecord.objects.filter(owner=user_2).exists())
    def test_LocationSiteFormUpdateView_allow_edit(self):
        user = UserF.create(id=1)
        self.client.login(username=user.username, password='******')
        location_site = LocationSiteF.create(creator=user, )
        post_data = self.post_data
        post_data['id'] = location_site.id
        post_request = self.client.post(
            '/location-site-form/update/?id={}'.format(location_site.id),
            post_data,
            follow=True)
        # Test if user is not the creator
        location_site_2 = LocationSiteF.create()
        post_data['id'] = location_site_2.id
        post_request_2 = self.client.post(
            '/location-site-form/update/?id={}'.format(location_site_2.id),
            self.post_data,
            follow=True)
        # Test if user is the owner but not the creator
        location_site_3 = LocationSiteF.create(owner=user, creator=None)
        post_data['id'] = location_site_3.id
        post_request_3 = self.client.post(
            '/location-site-form/update/?id={}'.format(location_site_3.id),
            self.post_data,
            follow=True)

        self.assertEqual(post_request.status_code, 200)
        self.assertEqual(post_request_2.status_code, 404)
        self.assertEqual(post_request_3.status_code, 200)
Beispiel #5
0
    def test_get_unvalidated_records_as_validator(self):
        view = GetNonValidatedRecords.as_view()
        BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 1',
            site=self.location_site,
            validated=False,
            ready_for_validation=True,
            taxonomy=self.taxonomy_1)
        BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 2',
            site=self.location_site,
            validated=False,
            ready_for_validation=True,
            taxonomy=self.taxonomy_2)
        user = UserF.create()
        content_type = ContentTypeF.create(app_label='bims', model='bims')
        permission = PermissionF.create(name='Can validate Aves',
                                        content_type=content_type,
                                        codename='can_validate_aves')
        group = GroupF.create()
        group.permissions.add(permission)
        user.groups.add(group)

        request = self.factory.get(reverse('get-unvalidated-records'))
        request.user = user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data['data']), 2)
 def test_LocationSiteFormView_delete(self):
     loc_type = LocationTypeF(name='PointObservation',
                              allowed_geometry='POINT')
     user = UserF.create(id=1)
     location_site_2 = LocationSiteF.create(
         location_type=loc_type,
         creator=user,
     )
     self.client.login(
         username=user.username,
         password='******',
     )
     post_data = {}
     post_request_2 = self.client.post(
         '/location-site-form/delete/{}/'.format(location_site_2.id),
         post_data,
         follow=True)
     self.assertFalse(
         LocationSite.objects.filter(id=location_site_2.id).exists())
     self.assertEqual(post_request_2.redirect_chain[0][0],
                      reverse('location-site-form'))
     location_site_3 = LocationSiteF.create(location_type=loc_type, )
     self.client.post('/location-site-form/delete/{}/'.format(
         location_site_3.id),
                      post_data,
                      follow=True)
     self.assertTrue(
         LocationSite.objects.filter(id=location_site_3.id).exists())
 def test_owner_user_delete_site_visit(self):
     """Test owner user deleting site visit"""
     user = UserF.create()
     self.client.login(username=user.username, password='******')
     site_visit = SiteVisitF.create(owner=user)
     self.client.post('/sass/delete/{}/'.format(site_visit.id))
     self.assertFalse(SiteVisit.objects.filter(id=site_visit.id).exists())
 def test_LocationSiteFormView_logged_in_user_access(self):
     """
     Tests open form for logged in user
     """
     user = UserF.create()
     self.client.login(username=user.username, password='******')
     response = self.client.get('/location-site-form/add/')
     self.assertEqual(response.status_code, 200)
 def test_common_user_delete_collection_record(self):
     """Test common user deleting collection record"""
     user = UserF.create()
     self.client.login(username=user.username, password='******')
     col = BiologicalCollectionRecordF.create()
     response = self.client.post(
         reverse('collection-delete', kwargs={'col_id': col.id}))
     self.assertEqual(response.status_code, 403)
     self.assertTrue(
         BiologicalCollectionRecord.objects.filter(id=col.id).exists())
 def test_super_user_delete_collection_record(self):
     user = UserF.create(is_superuser=True)
     self.client.login(username=user.username, password='******')
     col = BiologicalCollectionRecordF.create()
     response = self.client.post('{url}?next={next}'.format(
         url=reverse('collection-delete', kwargs={'col_id': col.id}),
         next=reverse('nonvalidated-user-list')))
     self.assertEqual(response.url, reverse('nonvalidated-user-list'))
     self.assertFalse(
         BiologicalCollectionRecord.objects.filter(id=col.id).exists())
 def test_LocationSiteFormView_post_data(self):
     """
     Test post data to LocationSiteFormView
     """
     user = UserF.create(id=1)
     self.client.login(username=user.username, password='******')
     self.client.post('/location-site-form/add/',
                      self.post_data,
                      follow=True)
     location_sites = LocationSite.objects.filter(
         site_code=self.post_data['site_code'])
     self.assertTrue(location_sites.exists())
 def setUp(self):
     self.factory = APIRequestFactory()
     self.location_site = LocationSiteF.create(
         pk=1, location_context_document='""')
     self.fish_collection_1 = BiologicalCollectionRecordF.create(
         pk=1,
         original_species_name=u'Test fish species name 1',
         site=self.location_site)
     self.fish_collection_2 = BiologicalCollectionRecordF.create(
         pk=2,
         original_species_name=u'Test fish species name 2',
         site=self.location_site)
     self.admin_user = UserF.create(is_superuser=True, is_staff=True)
    def test_get_unvalidated_records_as_validator(self):
        view = GetNonValidatedRecords.as_view()
        user = UserF.create()
        content_type = ContentTypeF.create(app_label='bims', model='bims')
        permission = PermissionF.create(name='Can validate data',
                                        content_type=content_type,
                                        codename='can_validate_data')
        group = GroupF.create()
        group.permissions.add(permission)
        user.groups.add(group)

        request = self.factory.get(reverse('get-unvalidated-records'))
        request.user = user
        response = view(request)
        self.assertEqual(response.status_code, 200)
Beispiel #14
0
 def setUp(self):
     self.admin_user = UserF.create(is_superuser=True, is_staff=True)
     self.journal_title = 'test title'
     self.doi = '10.1111/GCCE.2018.1111111'
     self.factory = APIRequestFactory()
     self.journal = JournalF.create(pk=1, name='journal')
     self.author = AuthorF.create(
         pk=1,
         first_name='First',
         last_name='Last',
     )
     self.entry = EntryF.create(pk=1,
                                title=self.journal_title,
                                journal=self.journal,
                                doi=self.doi)
Beispiel #15
0
    def test_only_get_aves_collection(self):
        from django.contrib.auth.models import Permission
        view = GetNonValidatedRecords.as_view()
        BiologicalCollectionRecordF.create(site=self.location_site,
                                           taxonomy=self.taxonomy_class_1,
                                           validated=False)
        user = UserF.create()
        permission = Permission.objects.filter(codename='can_validate_aves')[0]
        group = GroupF.create()
        group.permissions.add(permission)
        user.groups.add(group)

        request = self.factory.get(reverse('get-unvalidated-records'))
        request.user = user
        response = view(request)
        self.assertEqual(response.status_code, 200)
    def test_owner_collector_user_delete_collection_record(self):
        """Test owner or collector user deleting collection record"""
        user = UserF.create()
        self.client.login(username=user.username, password='******')
        col = BiologicalCollectionRecordF.create(owner=user)
        self.client.post(
            reverse('collection-delete', kwargs={'col_id': col.id}))
        self.assertFalse(
            BiologicalCollectionRecord.objects.filter(id=col.id).exists())

        # Collector
        col = BiologicalCollectionRecordF.create(collector_user=user)
        self.assertTrue(
            BiologicalCollectionRecord.objects.filter(id=col.id).exists())
        self.client.post(
            reverse('collection-delete', kwargs={'col_id': col.id}))
        self.assertFalse(
            BiologicalCollectionRecord.objects.filter(id=col.id).exists())
Beispiel #17
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.location_site = LocationSiteF.create(
            pk=1, location_context_document='""')

        self.taxonomy_class_1 = TaxonomyF.create(scientific_name='Aves',
                                                 rank=TaxonomicRank.CLASS.name)
        self.taxonomy_1 = TaxonomyF.create(scientific_name='Some aves name 1',
                                           canonical_name='aves name 1',
                                           rank=TaxonomicRank.SPECIES.name,
                                           parent=self.taxonomy_class_1)
        self.taxonomy_2 = TaxonomyF.create(scientific_name='Some aves name 2',
                                           canonical_name='aves name 2',
                                           rank=TaxonomicRank.SPECIES.name,
                                           parent=self.taxonomy_class_1)
        self.aves_collection_1 = BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 1',
            site=self.location_site,
            validated=True,
            ready_for_validation=True,
            taxonomy=self.taxonomy_1)
        self.aves_collection_2 = BiologicalCollectionRecordF.create(
            original_species_name=u'Aves collection 2',
            site=self.location_site,
            validated=True,
            ready_for_validation=True,
            taxonomy=self.taxonomy_2)

        self.fish_collection_1 = BiologicalCollectionRecordF.create(
            original_species_name=u'Test fish species name 1',
            site=self.location_site,
            validated=True)
        self.fish_collection_2 = BiologicalCollectionRecordF.create(
            original_species_name=u'Test fish species name 2',
            site=self.location_site,
            validated=True)
        self.admin_user = UserF.create(is_superuser=True, is_staff=True)
        self.rebuild_index()
Beispiel #18
0
 def setUp(self):
     self.owner = UserF.create(
         first_name='dimas'
     )