def test_with_anonymous(self): admin = UserF.create() email_user = AnonymousUser() project = ProjectF.create( add_admins=[admin], **{'isprivate': False} ) GroupingFactory.create(**{ 'isprivate': False, 'project': project }) view = ProjectContactAdmins.as_view() url = reverse( 'api:project_contact_admins', kwargs={ 'project_id': project.id } ) request = APIRequestFactory().post( url, json.dumps({'email_text': 'Blah Blah'}), content_type='application/json' ) force_authenticate(request, user=email_user) response = view(request, project_id=project.id).render() self.assertEqual(response.status_code, 401) self.assertEquals(len(mail.outbox), 0)
def test_get_comments_with_view_member(self): view_member = UserF.create() GroupingFactory.create( add_viewers=[view_member], **{'project': self.project} ) response = self.get_response(view_member) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def setUp(self): self.factory = APIRequestFactory() self.admin = UserF.create() self.creator = UserF.create() self.viewer = UserF.create() self.project = ProjectF( add_admins=[self.admin], add_contributors=[self.creator] ) self.contribution = ObservationFactory.create( **{'project': self.project, 'creator': self.creator} ) self.viewer = UserF.create() self.grouping = GroupingFactory.create( add_viewers=[self.viewer], **{'project': self.project} ) RuleFactory.create(**{ 'grouping': self.grouping, 'category': self.contribution.category }) self.image_file = ImageFileFactory.create( **{'contribution': self.contribution, 'creator': self.creator} )
def setUp(self): self.factory = APIRequestFactory() self.admin = UserF.create() self.creator = UserF.create() self.viewer = UserF.create() self.project = ProjectF(add_admins=[self.admin], add_contributors=[self.creator]) self.contribution = ObservationFactory.create(**{ 'project': self.project, 'creator': self.creator }) self.viewer = UserF.create() self.grouping = GroupingFactory.create(add_viewers=[self.viewer], **{'project': self.project}) RuleFactory.create(**{ 'grouping': self.grouping, 'category': self.contribution.category }) self.image_file = ImageFileFactory.create(**{ 'contribution': self.contribution, 'creator': self.creator })
def test_delete_image_with_viewer(self): viewer = UserF.create() dataview = GroupingFactory.create(add_viewers=[viewer], **{'project': self.project}) RuleFactory.create(**{ 'grouping': dataview, 'category': self.contribution.category }) response = self.delete(viewer) self.assertEqual(response.status_code, 404)
def test_delete_image_with_viewer(self): viewer = UserF.create() dataview = GroupingFactory.create( add_viewers=[viewer], **{'project': self.project} ) RuleFactory.create(**{ 'grouping': dataview, 'category': self.contribution.category }) response = self.delete(viewer) self.assertEqual(response.status_code, 404)
def test_delete_with_grouping(self): category = CategoryFactory.create() grouping = GroupingFactory.create() rule = RuleFactory(**{ 'grouping': grouping, 'status': 'active', 'category': category }) category.delete() Category.objects.get(pk=category.id) Rule.objects.get(pk=rule.id)
def test_post_images_with_anonymous_to_public(self): self.project.isprivate = False self.project.everyone_contributes = True self.project.save() grouping = GroupingFactory.create( **{'project': self.project, 'isprivate': False} ) RuleFactory.create(**{ 'grouping': grouping, 'category': self.contribution.category }) response = self.post(AnonymousUser()) self.assertEqual(response.status_code, 201)
def test_delete_with_rule(self): category = CategoryFactory() field = Field.create( 'name', 'key', 'description', False, category, 'TextField' ) grouping = GroupingFactory.create() rule = RuleFactory(**{ 'grouping': grouping, 'status': 'active', 'category': category, 'filters': { field.key: 'Blah', 'other-key': 'blubb' } }) field.delete() reference_rule = Rule.objects.get(pk=rule.id) self.assertEquals(reference_rule.filters.get('key'), None)
def test_delete_not_existing_viewgroup(self): response = self.delete( self.admin, view_to_delete=GroupingFactory.create() ) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_add_not_existing_view(self): view = GroupingFactory.create() response = self.post(self.admin, grouping_id=view.id) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_delete_not_existing_viewgroup(self): response = self.delete(self.admin, view_to_delete=GroupingFactory.create()) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_add_not_existing_view(self): view = GroupingFactory.create() response = self.post(self.admin, grouping_id=view.id) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)