Пример #1
0
    def test_create_source_with_false_feature(self, api):
        '''It should handled negative values'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'features': {
                    'test': False,
                    'toggled': False,
                }
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert201(response)

        source = response.json
        assert source['config'] == {
            'features': {
                'test': False,
                'toggled': False,
            }
        }
Пример #2
0
 def test_create(self, api):
     data = self.factory.as_dict()
     response = api.post(url_for('api.reuse_badges', reuse=self.reuse),
                         data)
     assert201(response)
     self.reuse.reload()
     assert len(self.reuse.badges) == 1
 def test_create(self, api):
     data = self.factory.as_dict()
     url = url_for('api.organization_badges', org=self.organization)
     with assert_emit(on_badge_added):
         response = api.post(url, data)
         assert201(response)
     self.organization.reload()
     assert len(self.organization.badges) is 1
Пример #4
0
    def test_reuse_api_create(self, api):
        '''It should create a reuse from the API'''
        data = ReuseFactory.as_dict()
        user = api.login()
        response = api.post(url_for('api.reuses'), data)
        assert201(response)
        assert Reuse.objects.count() == 1

        reuse = Reuse.objects.first()
        assert reuse.owner == user
        assert reuse.organization is None
    def test_organization_api_create(self, api):
        '''It should create an organization from the API'''
        data = OrganizationFactory.as_dict()
        user = api.login()
        response = api.post(url_for('api.organizations'), data)
        assert201(response)
        assert Organization.objects.count() is 1

        org = Organization.objects.first()
        member = org.member(user)
        assert member is not None, 'Current user should be a member'
        assert member.role == 'admin', 'Current user should be an administrator'
 def test_create_2nd(self, api):
     # Explicitely setting the kind to avoid collisions given the
     # small number of choices for kinds.
     kinds_keys = Organization.__badges__.keys()
     self.organization.add_badge(kinds_keys[0])
     data = self.factory.as_dict()
     data['kind'] = kinds_keys[1]
     url = url_for('api.organization_badges', org=self.organization)
     response = api.post(url, data)
     assert201(response)
     self.organization.reload()
     assert len(self.organization.badges) is 2
Пример #7
0
    def test_create_source_with_config(self, api):
        '''It should create a new source with configuration'''
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'filters': [
                    {
                        'key': 'test',
                        'value': 1
                    },
                    {
                        'key': 'test',
                        'value': 42
                    },
                    {
                        'key': 'tag',
                        'value': 'my-tag'
                    },
                ],
                'features': {
                    'test': True,
                    'toggled': True,
                }
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert201(response)

        source = response.json
        assert source['config'] == {
            'filters': [
                {
                    'key': 'test',
                    'value': 1
                },
                {
                    'key': 'test',
                    'value': 42
                },
                {
                    'key': 'tag',
                    'value': 'my-tag'
                },
            ],
            'features': {
                'test': True,
                'toggled': True,
            }
        }
Пример #8
0
 def test_create_2nd(self, api):
     # Explicitely setting the kind to avoid collisions given the
     # small number of choices for kinds.
     kinds_keys = list(Reuse.__badges__)
     self.reuse.add_badge(kinds_keys[0])
     data = self.factory.as_dict()
     data['kind'] = kinds_keys[1]
     response = api.post(url_for('api.reuse_badges', reuse=self.reuse),
                         data)
     assert201(response)
     self.reuse.reload()
     assert len(self.reuse.badges) == 2
Пример #9
0
    def test_create_source_with_owner(self, api):
        '''It should create and attach a new source to an owner'''
        user = api.login()
        data = {'name': faker.word(), 'url': faker.url(), 'backend': 'factory'}
        response = api.post(url_for('api.harvest_sources'), data)

        assert201(response)

        source = response.json
        assert source['validation']['state'] == VALIDATION_PENDING
        assert source['owner']['id'] == str(user.id)
        assert source['organization'] is None
Пример #10
0
 def test_post_api_create(self, api):
     '''It should create a post from the API'''
     data = PostFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     api.login(AdminFactory())
     response = api.post(url_for('api.posts'), data)
     assert201(response)
     assert Post.objects.count() == 1
     post = Post.objects.first()
     for dataset, expected in zip(post.datasets, data['datasets']):
         assert str(dataset.id) == expected
     for reuse, expected in zip(post.reuses, data['reuses']):
         assert str(reuse.id) == expected
Пример #11
0
    def test_reuse_api_create_as_org(self, api):
        '''It should create a reuse as organization from the API'''
        user = api.login()
        data = ReuseFactory.as_dict()
        member = Member(user=user, role='editor')
        org = OrganizationFactory(members=[member])
        data['organization'] = str(org.id)
        response = api.post(url_for('api.reuses'), data)
        assert201(response)
        assert Reuse.objects.count() == 1

        reuse = Reuse.objects.first()
        assert reuse.owner is None
        assert reuse.organization == org
Пример #12
0
 def test_post_api_create(self, api):
     '''It should create a post from the API'''
     data = PostFactory.as_dict()
     data['datasets'] = [str(d.id) for d in data['datasets']]
     data['reuses'] = [str(r.id) for r in data['reuses']]
     api.login(AdminFactory())
     response = api.post(url_for('api.posts'), data)
     assert201(response)
     assert Post.objects.count() == 1
     post = Post.objects.first()
     for dataset, expected in zip(post.datasets, data['datasets']):
         assert str(dataset.id) == expected
     for reuse, expected in zip(post.reuses, data['reuses']):
         assert str(reuse.id) == expected
Пример #13
0
    def test_follow_reuse(self, api):
        '''It should follow a reuse on POST'''
        user = api.login()
        to_follow = ReuseFactory()

        response = api.post(url_for('api.reuse_followers', id=to_follow.id))
        assert201(response)

        assert Follow.objects.following(to_follow).count() == 0
        assert Follow.objects.followers(to_follow).count() == 1
        follow = Follow.objects.followers(to_follow).first()
        assert isinstance(follow.following, Reuse)
        assert Follow.objects.following(user).count() == 1
        assert Follow.objects.followers(user).count() == 0
    def test_follow_org(self, api):
        '''It should follow an organization on POST'''
        user = api.login()
        to_follow = OrganizationFactory()

        url = url_for('api.organization_followers', id=to_follow.id)
        response = api.post(url)
        assert201(response)

        assert Follow.objects.following(to_follow).count() is 0
        assert Follow.objects.followers(to_follow).count() is 1
        follow = Follow.objects.followers(to_follow).first()
        assert isinstance(follow.following, Organization)
        assert Follow.objects.following(user).count() is 1
        assert Follow.objects.followers(user).count() is 0
Пример #15
0
    def test_create_source_with_config_with_custom_key(self, api):
        api.login()
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'config': {
                'custom': 'value'
            }
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert201(response)

        source = response.json
        assert source['config'] == {'custom': 'value'}
    def test_create_member(self, api):
        user = api.login()
        added_user = UserFactory()
        organization = OrganizationFactory(members=[
            Member(user=user, role='admin'),
        ])

        api_url = url_for('api.member', org=organization, user=added_user)
        response = api.post(api_url, {'role': 'admin'})

        assert201(response)

        assert response.json['role'] == 'admin'

        organization.reload()
        assert organization.is_member(added_user)
        assert organization.is_admin(added_user)
Пример #17
0
    def test_create_source_with_org(self, api):
        '''It should create and attach a new source to an organization'''
        user = api.login()
        member = Member(user=user, role='admin')
        org = OrganizationFactory(members=[member])
        data = {
            'name': faker.word(),
            'url': faker.url(),
            'backend': 'factory',
            'organization': str(org.id)
        }
        response = api.post(url_for('api.harvest_sources'), data)

        assert201(response)

        source = response.json
        assert source['validation']['state'] == VALIDATION_PENDING
        assert source['owner'] is None
        assert source['organization']['id'] == str(org.id)
Пример #18
0
    def test_reuse_api_add_dataset(self, api):
        '''It should add a dataset to a reuse from the API'''
        user = api.login()
        reuse = ReuseFactory(owner=user)

        dataset = DatasetFactory()
        data = {'id': dataset.id, 'class': 'Dataset'}
        url = url_for('api.reuse_add_dataset', reuse=reuse)
        response = api.post(url, data)
        assert201(response)
        reuse.reload()
        assert len(reuse.datasets) == 1
        assert reuse.datasets[-1] == dataset

        dataset = DatasetFactory()
        data = {'id': dataset.id, 'class': 'Dataset'}
        url = url_for('api.reuse_add_dataset', reuse=reuse)
        response = api.post(url, data)
        assert201(response)
        reuse.reload()
        assert len(reuse.datasets) == 2
        assert reuse.datasets[-1] == dataset
    def test_request_membership(self, api):
        organization = OrganizationFactory()
        user = api.login()
        data = {'comment': 'a comment'}

        api_url = url_for('api.request_membership', org=organization)
        response = api.post(api_url, data)
        assert201(response)

        organization.reload()
        assert len(organization.requests) is 1
        assert len(organization.pending_requests) is 1
        assert len(organization.refused_requests) is 0
        assert len(organization.accepted_requests) is 0

        request = organization.requests[0]
        assert request.user == user
        assert request.status == 'pending'
        assert request.comment == 'a comment'
        assert request.handled_on is None
        assert request.handled_by is None
        assert request.refusal_comment is None