示例#1
0
    def setUp(self):
        self.admin = UserFactory.create()

        self.project1 = ProjectFactory(add_admins=[self.admin])
        self.project2 = ProjectFactory(add_admins=[self.admin])
        self.public_location = LocationFactory(**{
            'private': False
        })
        self.private_location = LocationFactory(**{
            'private': True
        })
        self.private_for_project_location = LocationFactory(**{
            'private': True,
            'private_for_project': self.project1
        })
示例#2
0
    def test_contribute_with_wrong_project_location(self):
        project = ProjectFactory()
        location = LocationFactory(**{
            'private': True,
            'private_for_project': project
        })

        data = {
            "type": "Feature",
            "geometry": location.geometry.geojson,
            "location": {
                "id": location.id,
                "name": location.name,
                "description": location.description,
                "private": location.private
            },
            "properties": {
                "key_1": "value 1",
                "key_2": 12
            },
            "meta": {
                "category": self.category.id,
            }
        }

        response = self._post(data, self.admin)
        self.assertEqual(response.status_code, 400)
示例#3
0
    def test_create_with_wrong_location(self):
        project = ProjectFactory()
        location = LocationFactory(**{
            'private': True,
            'private_for_project': project
        })

        data = {
            "properties": {
                "key_1": "value 1",
                "key_2": 12
            },
            "meta": {
                "category": self.category.id
            },
            "location": {
                "id": location.id,
                "geometry": location.geometry.geojson
            }
        }
        serializer = ContributionSerializer(data=data,
                                            context={
                                                'user': self.contributor,
                                                'project': self.project
                                            })
        serializer.is_valid(raise_exception=True)
示例#4
0
 def setUp(self):
     self.contributor = UserFactory.create()
     self.admin = UserFactory.create()
     self.non_member = UserFactory.create()
     self.project = ProjectFactory(
         add_admins=[self.admin],
         add_contributors=[self.contributor]
     )
     self.contribution = ObservationFactory.create(**{
         'project': self.project,
         'creator': self.contributor
     })
     comment = CommentFactory.create(**{
         'commentto': self.contribution
     })
     response = CommentFactory.create(**{
         'commentto': self.contribution,
         'respondsto': comment
     })
     CommentFactory.create(**{
         'commentto': self.contribution,
         'respondsto': response
     })
     CommentFactory.create(**{
         'commentto': self.contribution,
         'respondsto': comment
     })
     CommentFactory.create(**{
         'commentto': self.contribution
     })
示例#5
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create(**{
            'project': project
        })
        comment = CommentFactory.create()

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (project.id, contribution.id),
            {
                'text': 'Response to a comment',
                'respondsto': comment.id
            }
        )
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(
            request,
            project_id=project.id,
            contribution_id=contribution.id
        ).render()

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            json.loads(response.content).get('error'),
            'The comment you try to respond to is not a comment to the '
            'contribution.'
        )
示例#6
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.admin = UserFactory.create()
     self.creator = UserFactory.create()
     self.moderator = UserFactory.create()
     self.commenter = UserFactory.create()
     self.project = ProjectFactory(
         add_admins=[self.admin],
         add_contributors=[self.creator, self.commenter])
     self.moderators = UserGroupFactory(add_users=[self.moderator],
                                        **{
                                            'project': self.project,
                                            'can_moderate': True
                                        })
     self.contribution = ObservationFactory.create(**{
         'project': self.project,
         'creator': self.creator,
         'status': 'review'
     })
     self.comment = CommentFactory.create(
         **{
             'commentto': self.contribution,
             'creator': self.commenter,
             'review_status': 'open'
         })
示例#7
0
 def setUp(self):
     self.admin = UserFactory.create()
     self.creator = UserFactory.create()
     self.project = ProjectFactory(add_admins=[self.admin],
                                   add_contributors=[self.creator])
     self.contribution = ObservationFactory.create(**{
         'project': self.project,
         'creator': self.creator
     })
示例#8
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.project = ProjectFactory()
        LocationFactory.create(**{'name': 'Hyde Park'})
        LocationFactory.create(**{'description': 'hyde'})
        LocationFactory.create(**{'name': 'hyde park'})
        LocationFactory.create(**{'name': 'Regents Park'})

        self.url = reverse('api:project_locations',
                           kwargs={'project_id': self.project.id})
示例#9
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.regular_user = UserFactory.create()
        self.anonymous_user = AnonymousUser()
        self.project = ProjectFactory(add_admins=[self.admin])
        self.sapelli_project = SapelliProjectFactory.create(
            **{'geokey_project': self.project})

        self.file_name = 'Collector_2015-01-20T18.02.12.log'
        self.file = get_test_file(self.file_name)
示例#10
0
 def setUp(self):
     self.contributor = UserFactory.create()
     self.admin = UserFactory.create()
     self.non_member = UserFactory.create()
     self.project = ProjectFactory(add_admins=[self.admin],
                                   add_contributors=[self.contributor],
                                   **{'isprivate': False})
     self.contribution = ObservationFactory.create(
         **{
             'project': self.project,
             'creator': self.contributor
         })
示例#11
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )

        self.category = CategoryFactory(**{
            'status': 'active',
            'project': self.project
        })

        TextFieldFactory.create(**{
            'key': 'key_1',
            'category': self.category,
            'required': True,
            'order': 1
        })
        NumericFieldFactory.create(**{
            'key': 'key_2',
            'category': self.category,
            'minval': 0,
            'maxval': 1000,
            'order': 2
        })

        self.data = {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -0.13404607772827148,
                    51.52439200896907
                ]
            },
            "properties": {
                "key_1": "value 1",
                "key_2": 12
            },
            "meta": {
                "category": self.category.id,
            },
            "location": {
                "name": "UCL",
                "description": "UCL's main quad",
                "private": True
            }
        }
示例#12
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.creator = UserFactory.create()
        self.viewer = UserFactory.create()
        self.project = ProjectFactory(add_admins=[self.admin],
                                      add_contributors=[self.creator])

        self.contribution = ObservationFactory.create(**{
            'project': self.project,
            'creator': self.creator
        })

        ImageFileFactory.create_batch(5, **{'contribution': self.contribution})
示例#13
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.view_member = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory(add_admins=[self.admin],
                                      add_contributors=[self.contributor])

        self.location = LocationFactory(**{
            'private': True,
            'private_for_project': self.project
        })
示例#14
0
    def test(self):
        admin = UserFactory.create()
        project = ProjectFactory(add_admins=[admin])
        contribution = ObservationFactory.create()

        factory = APIRequestFactory()
        request = factory.post(
            '/api/projects/%s/contributions/%s/comments/' %
            (project.id, contribution.id),
            {'text': 'A comment to the contribution.'})
        force_authenticate(request, user=admin)
        view = CommentsAPIView.as_view()
        response = view(request,
                        project_id=project.id,
                        contribution_id=contribution.id).render()
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
示例#15
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
        self.category = CategoryFactory(**{
            'status': 'active',
            'project': self.project
        })

        TextFieldFactory.create(**{
            'key': 'key_1',
            'category': self.category,
            'order': 0
        })
        NumericFieldFactory.create(**{
            'key': 'key_2',
            'category': self.category,
            'order': 1
        })

        location = LocationFactory()

        self.observation = ObservationFactory.create(**{
            'properties': {
                "key_1": "value 1",
                "key_2": 12,
            },
            'category': self.category,
            'project': self.project,
            'location': location,
            'creator': self.admin,
            'status': 'active'
        })

        self.update_data = {
            "properties": {
                "version": 1,
                "key_2": 15
            }
        }
示例#16
0
 def setUp(self):
     self.factory = APIRequestFactory()
     self.admin = UserFactory.create()
     self.creator = UserFactory.create()
     self.moderator = UserFactory.create()
     self.viewer = UserFactory.create()
     self.project = ProjectFactory(add_admins=[self.admin],
                                   add_contributors=[self.creator],
                                   add_viewer=[self.viewer])
     self.moderators = UserGroupFactory(add_users=[self.moderator],
                                        **{
                                            'project': self.project,
                                            'can_moderate': True
                                        })
     self.observation = ObservationFactory.create(**{
         'project': self.project,
         'creator': self.creator,
         'status': 'active'
     })
示例#17
0
    def setUp(self):
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory(add_admins=[self.admin],
                                      add_contributors=[self.contributor])
        self.category = CategoryFactory(**{
            'status': 'active',
            'project': self.project
        })

        TextFieldFactory.create(**{
            'key': 'key_1',
            'category': self.category,
            'order': 0
        })
        NumericFieldFactory.create(**{
            'key': 'key_2',
            'category': self.category,
            'order': 1
        })
示例#18
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory(add_admins=[self.admin],
                                      add_contributors=[self.contributor])
        self.other_project = ProjectFactory.create()

        # Create 20 locations, 10 should be accessible for the project
        for x in range(0, 5):
            LocationFactory()
            LocationFactory(**{
                'private': True,
                'private_for_project': self.other_project
            })
            LocationFactory(**{
                'private': True,
                'private_for_project': self.project
            })
            LocationFactory(**{'private': True})