示例#1
0
    def test_purge_reuses(self):
        reuse = ReuseFactory(title='test-reuse')

        # Upload reuse's image
        file = create_test_image()
        user = AdminFactory()
        self.login(user)
        response = self.post(url_for('api.reuse_image', reuse=reuse),
                             {'file': (file, 'test.png')},
                             json=False)
        self.assert200(response)

        # Delete reuse
        response = self.delete(url_for('api.reuse', reuse=reuse))
        self.assert204(response)

        user = UserFactory()
        transfer = Transfer.objects.create(
            owner=user,
            recipient=user,
            subject=reuse,
            comment='comment',
        )

        tasks.purge_reuses()

        assert Transfer.objects.filter(id=transfer.id).count() == 0

        # Check reuse's image is deleted
        self.assertEqual(list(storages.images.list_files()), [])

        deleted_reuse = Reuse.objects(title='test-reuse').first()
        self.assertIsNone(deleted_reuse)
示例#2
0
    def test_purge_organizations(self):
        with self.autoindex():
            org = Organization.objects.create(name='delete me',
                                              description='XXX')
            resources = [ResourceFactory() for _ in range(2)]
            dataset = DatasetFactory(resources=resources, organization=org)

        # Upload organization's logo
        file = create_test_image()
        user = AdminFactory()
        self.login(user)
        response = self.post(url_for('api.organization_logo', org=org),
                             {'file': (file, 'test.png')},
                             json=False)
        self.assert200(response)

        # Delete organization
        response = self.delete(url_for('api.organization', org=org))
        self.assert204(response)

        tasks.purge_organizations()

        # Check organization's logo is deleted
        self.assertEqual(list(storages.avatars.list_files()), [])

        dataset = Dataset.objects(id=dataset.id).first()
        self.assertIsNone(dataset.organization)

        organization = Organization.objects(name='delete me').first()
        self.assertIsNone(organization)

        indexed_dataset = DatasetSearch.get(id=dataset.id,
                                            using=es.client,
                                            index=es.index_name)
        self.assertIsNone(indexed_dataset.organization)
示例#3
0
    def test_purge_organizations(self):
        org = Organization.objects.create(name='delete me', description='XXX')
        resources = [ResourceFactory() for _ in range(2)]
        dataset = DatasetFactory(resources=resources, organization=org)

        # Upload organization's logo
        file = create_test_image()
        user = AdminFactory()
        self.login(user)
        response = self.post(
            url_for('api.organization_logo', org=org),
            {'file': (file, 'test.png')},
            json=False)
        self.assert200(response)

        transfer_to_org = Transfer.objects.create(
            owner=user,
            recipient=org,
            subject=dataset,
            comment='comment',
        )
        transfer_from_org = Transfer.objects.create(
            owner=org,
            recipient=user,
            subject=dataset,
            comment='comment',
        )

        oauth_client = OAuth2Client.objects.create(
            name='test-client',
            owner=user,
            organization=org,
            redirect_uris=['https://test.org/callback'],
        )

        # Delete organization
        response = self.delete(url_for('api.organization', org=org))
        self.assert204(response)

        tasks.purge_organizations()

        oauth_client.reload()
        assert oauth_client.organization is None

        assert Transfer.objects.filter(id=transfer_from_org.id).count() == 0
        assert Transfer.objects.filter(id=transfer_to_org.id).count() == 0

        # Check organization's logo is deleted
        self.assertEqual(list(storages.avatars.list_files()), [])

        dataset = Dataset.objects(id=dataset.id).first()
        self.assertIsNone(dataset.organization)

        organization = Organization.objects(name='delete me').first()
        self.assertIsNone(organization)
示例#4
0
    def test_delete_user(self):
        user = AdminFactory()
        self.login(user)
        other_user = UserFactory()
        file = create_test_image()

        response = self.post(url_for('api.user_avatar', user=other_user),
                             {'file': (file, 'test.png')},
                             json=False)

        response = self.delete(url_for('api.user', user=other_user))
        self.assertEqual(list(storages.avatars.list_files()), [])
        self.assert204(response)
        other_user.reload()
        response = self.delete(url_for('api.user', user=other_user))
        self.assert410(response)
        response = self.delete(url_for('api.user', user=user))
        self.assert403(response)
示例#5
0
    def test_purge_reuses(self):
        reuse = ReuseFactory(title='test-reuse')

        # Upload reuse's image
        file = create_test_image()
        user = AdminFactory()
        self.login(user)
        response = self.post(url_for('api.reuse_image', reuse=reuse),
                             {'file': (file, 'test.png')},
                             json=False)
        self.assert200(response)

        # Delete reuse
        response = self.delete(url_for('api.reuse', reuse=reuse))
        self.assert204(response)

        tasks.purge_reuses()

        # Check reuse's image is deleted
        self.assertEqual(list(storages.images.list_files()), [])

        organization = Reuse.objects(title='test-reuse').first()
        self.assertIsNone(organization)