Пример #1
0
 def test_community_resource_api_create_as_org(self):
     '''It should create a community resource as org from the API'''
     user = self.login()
     with self.autoindex():
         resource = ResourceFactory()
         org = OrganizationFactory(
             members=[Member(user=user, role='admin')])
         dataset = DatasetFactory(resources=[resource])
     response = self.post(url_for('api.upload_community_resources',
                                  dataset=dataset),
                          {'file': (StringIO(b'aaa'), 'test.txt')},
                          json=False)
     self.assertStatus(response, 201)
     data = json.loads(response.data)
     self.assertEqual(data['title'], 'test.txt')
     resource_id = data['id']
     data['organization'] = str(org.id)
     response = self.put(
         url_for('api.community_resource', community=resource_id), data)
     self.assertStatus(response, 200)
     self.assertEqual(CommunityResource.objects.count(), 1)
     community_resource = CommunityResource.objects.first()
     self.assertEqual(community_resource.organization, org)
     self.assertIsNone(community_resource.owner)
Пример #2
0
    def test_my_org_issues(self):
        user = self.login()
        member = Member(user=user, role='editor')
        organization = OrganizationFactory(members=[member])
        reuse = ReuseFactory(owner=user)
        org_reuse = ReuseFactory(organization=organization)
        dataset = VisibleDatasetFactory(owner=user)
        org_dataset = VisibleDatasetFactory(organization=organization)

        sender = UserFactory()
        issues = [
            Issue.objects.create(subject=s, title='', user=sender)
            for s in (dataset, org_dataset, reuse, org_reuse)
        ]

        # Should not be listed
        Issue.objects.create(subject=VisibleDatasetFactory(),
                             title='',
                             user=sender)
        Issue.objects.create(subject=ReuseFactory(), title='', user=sender)

        response = self.get(url_for('api.my_org_issues'))
        self.assert200(response)
        self.assertEqual(len(response.json), len(issues))
Пример #3
0
 def test_counties_with_other_datasets_and_pertinent_ones(self):
     user = self.login()
     with self.autoindex():
         member = Member(user=user, role='admin')
         organization = OrganizationFactory(members=[member])
         VisibleDatasetFactory.create_batch(
             3,
             organization=organization,
             spatial=SpatialCoverageFactory(zones=[self.bdr.id]))
     response = self.client.get(
         url_for('territories.territory', territory=self.bdr))
     self.assert200(response)
     data = response.data.decode('utf-8')
     self.assertIn(self.bdr.name, data)
     base_datasets = self.get_context_variable('base_datasets')
     self.assertEqual(len(base_datasets), 0)
     other_datasets = self.get_context_variable('other_datasets')
     self.assertEqual(len(other_datasets), 3)
     for dataset in other_datasets:
         self.assertIn(
             '<div data-udata-dataset-id="{dataset.id}"'.format(
                 dataset=dataset), data)
     self.assertEqual(self.get_context_variable('territory_datasets'), [])
     self.assertIn('If you want your datasets to appear in that list', data)
Пример #4
0
    def test_delete(self):
        '''It should delete the connected user'''
        user = self.login()
        self.assertIsNone(user.deleted)
        other_user = UserFactory()
        members = [Member(user=user), Member(user=other_user)]
        organization = OrganizationFactory(members=members)
        disc_msg_content = faker.sentence()
        disc_msg = DiscMsg(content=disc_msg_content, posted_by=user)
        other_disc_msg_content = faker.sentence()
        other_disc_msg = DiscMsg(content=other_disc_msg_content,
                                 posted_by=other_user)
        discussion = DiscussionFactory(user=user,
                                       discussion=[disc_msg, other_disc_msg])
        issue_msg_content = faker.sentence()
        issue_msg = IssueMsg(content=issue_msg_content, posted_by=user)
        other_issue_msg_content = faker.sentence()
        other_issue_msg = IssueMsg(content=other_issue_msg_content,
                                   posted_by=other_user)
        issue = IssueFactory(user=user,
                             discussion=[issue_msg, other_issue_msg])
        dataset = DatasetFactory(owner=user)
        reuse = ReuseFactory(owner=user)
        resource = CommunityResourceFactory(owner=user)
        activity = UserCreatedDataset.objects().create(actor=user,
                                                       related_to=dataset)

        following = Follow.objects().create(follower=user,
                                            following=other_user)
        followed = Follow.objects().create(follower=other_user, following=user)

        with capture_mails() as mails:
            response = self.delete(url_for('api.me'))
        self.assertEqual(len(mails), 1)
        self.assertEqual(mails[0].send_to, set([user.email]))
        self.assertEqual(mails[0].subject, _('Account deletion'))
        self.assert204(response)

        user.reload()
        organization.reload()
        discussion.reload()
        issue.reload()
        dataset.reload()
        reuse.reload()
        resource.reload()
        activity.reload()

        # The following are deleted
        with self.assertRaises(Follow.DoesNotExist):
            following.reload()
        # The followers are deleted
        with self.assertRaises(Follow.DoesNotExist):
            followed.reload()

        # The personal data of the user are anonymized
        self.assertEqual(user.email, '{}@deleted'.format(user.id))
        self.assertEqual(user.password, None)
        self.assertEqual(user.active, False)
        self.assertEqual(user.first_name, 'DELETED')
        self.assertEqual(user.last_name, 'DELETED')
        self.assertFalse(bool(user.avatar))
        self.assertEqual(user.avatar_url, None)
        self.assertEqual(user.website, None)
        self.assertEqual(user.about, None)

        # The user is marked as deleted
        self.assertIsNotNone(user.deleted)

        # The user is removed from his organizations
        self.assertEqual(len(organization.members), 1)
        self.assertEqual(organization.members[0].user.id, other_user.id)

        # The discussions are kept but the messages are anonymized
        self.assertEqual(len(discussion.discussion), 2)
        self.assertEqual(discussion.discussion[0].content, 'DELETED')
        self.assertEqual(discussion.discussion[1].content,
                         other_disc_msg_content)

        # The issues are kept and the messages are not anonymized
        self.assertEqual(len(issue.discussion), 2)
        self.assertEqual(issue.discussion[0].content, issue_msg_content)
        self.assertEqual(issue.discussion[1].content, other_issue_msg_content)

        # The datasets are unchanged
        self.assertEqual(dataset.owner, user)

        # The reuses are unchanged
        self.assertEqual(reuse.owner, user)

        # The community resources are unchanged
        self.assertEqual(resource.owner, user)

        # The activities are unchanged
        self.assertEqual(activity.actor, user)
Пример #5
0
 def test_render_issues(self):
     '''It should render the organization issues page'''
     user = self.login()
     organization = OrganizationFactory(members=[Member(user=user, role='admin')])
     response = self.get(url_for('organizations.issues', org=organization))
     self.assert200(response)
Пример #6
0
 def test_render_edit_extras(self):
     '''It should render the organization extras edit form'''
     user = self.login()
     organization = OrganizationFactory(members=[Member(user=user, role='admin')])
     response = self.get(url_for('organizations.edit_extras', org=organization))
     self.assert200(response)