示例#1
0
    def test_valid(self, superuser_client, tag_factory):
        tag = tag_factory.build()
        mutation = MutationGenerator.create_tag(name=tag.name)
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createTag']['tag']['name'] == tag.name
示例#2
0
    def test_unauthenticated(self, client, tag_factory):
        mutation = MutationGenerator.create_tag(name=tag_factory.build().name)
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['createTag']
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#3
0
    def test_update_tags(self, superuser_client, strand_factory, tag_factory):
        old_tag = tag_factory()
        strand = strand_factory()
        strand.tags.add(old_tag)  # Using post_generation decorator causes unnecessary saves
        new_tag = tag_factory.build()

        # Assert that old_tag exists
        query = QueryGenerator.get_tags()
        response = superuser_client.post('/graphql', {'query': query})

        assert response.status_code == 200, response.content
        assert len(response.json()['data']['tags']) == 1
        assert response.json()['data']['tags'][0]['name'] == old_tag.name

        mutation = MutationGenerator.update_strand(strand_id=strand.id,
                                                   tags=[new_tag.name])
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['updateStrand']['strand']['title'] == strand.title
        assert response.json()['data']['updateStrand']['strand']['body'] == strand.body
        assert response.json()['data']['updateStrand']['strand']['tags'][0]['name'] == new_tag.name

        # Assert that old_tag was orphaned and deleted
        query = QueryGenerator.get_tags()
        response = superuser_client.post('/graphql', {'query': query})

        assert response.status_code == 200, response.content
        assert len(response.json()['data']['tags']) == 1
        assert response.json()['data']['tags'][0]['name'] == new_tag.name
示例#4
0
    def test_invalid_name(self, superuser_client, tag_factory):
        mutation = MutationGenerator.create_tag(name=tag_factory().name)
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['createTag']
        assert response.json()['errors'][0]['message'] == str(
            {'name': ['tag with this name already exists.']})
示例#5
0
    def test_unauthenticated(self, client, team_factory):
        team = team_factory.build()

        mutation = MutationGenerator.create_team(team.name)
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createTeam'] is None
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#6
0
    def test_unauthenticated(self, client, user_factory):
        user = user_factory.build()

        mutation = MutationGenerator.create_user(email=user.email,
                                                 username=user.username)
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createUser'] is None
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#7
0
    def test_update_title(self, superuser_client, strand_factory):
        strand = strand_factory()
        new_title = strand_factory.build().title

        mutation = MutationGenerator.update_strand(strand_id=strand.id,
                                                   title=new_title)
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['updateStrand']['strand']['title'] == new_title
        assert response.json()['data']['updateStrand']['strand']['body'] == strand.body
示例#8
0
    def test_unauthenticated(self, client, user_factory):
        user = user_factory()

        mutation = MutationGenerator.change_password(user_id=user.id,
                                                     old_password='******',
                                                     new_password='******')
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['changePassword']
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#9
0
    def test_valid(self, superuser_client, user_factory):
        user = user_factory()

        mutation = MutationGenerator.change_password(user_id=user.id,
                                                     old_password='******',
                                                     new_password='******')
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json(
        )['data']['changePassword']['user']['email'] == user.email
示例#10
0
    def test_valid(self, superuser_client, team_factory, user_factory):
        team = team_factory(members=[user_factory()])
        jimmy = user_factory()

        mutation = MutationGenerator.add_members_to_team(id=team.id,
                                                         member_ids=[jimmy.id])
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['addMembersToTeam']['team']['members'][
            1]['email'] == jimmy.email
示例#11
0
    def test_unauthenticated(self, client, team_factory, user_factory):
        team = team_factory()
        jimmy = user_factory()

        mutation = MutationGenerator.add_members_to_team(id=team.id,
                                                         member_ids=[jimmy.id])
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['addMembersToTeam']
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#12
0
    def test_invalid_password(self, superuser_client, user_factory):
        user = user_factory()

        mutation = MutationGenerator.change_password(user_id=user.id,
                                                     old_password='******',
                                                     new_password='******')
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['changePassword']
        assert response.json()['errors'][0]['message'] == str(
            {'old_password': ['Wrong password.']})
示例#13
0
    def test_invalid_id(self, superuser_client, user_factory):
        user = user_factory()

        mutation = MutationGenerator.change_password(user_id=user.id + 1,
                                                     old_password='******',
                                                     new_password='******')
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['changePassword']
        assert response.json(
        )['errors'][0]['message'] == 'User matching query does not exist.'
示例#14
0
    def test_unauthenticated(self, client, strand_factory, tag_factory):
        strand = strand_factory()
        new_title = strand_factory.build().title
        new_tag = tag_factory()

        mutation = MutationGenerator.update_strand(strand_id=strand.id,
                                                   title=new_title,
                                                   tags=[new_tag.name])
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['updateStrand']
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#15
0
    def test_valid(self, superuser_client, user_factory):
        assert not mail.outbox
        user = user_factory.build()

        mutation = MutationGenerator.create_user(email=user.email)
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createUser']['user']['id']
        assert mail.outbox[0].subject == 'Welcome to Strand'
        assert mail.outbox[0].to == [user.email]
        assert mail.outbox[0].body
        assert mail.outbox[0].template_id == settings.NEW_ACCOUNT_TEMPLATE_ID
示例#16
0
    def test_valid_no_title(self, superuser_client, user_factory, team_factory,
                            strand_factory):
        jimmy = user_factory()
        owner = team_factory(members=[jimmy])
        strand = strand_factory.build()

        mutation = MutationGenerator.create_strand(title=None,
                                                   body=strand.body,
                                                   timestamp=strand.timestamp,
                                                   saver_id=jimmy.id,
                                                   owner_id=owner.id)
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createStrand']['strand']['body']
示例#17
0
    def test_invalid_user(self, superuser_client, team_factory, user_factory):
        team = team_factory()
        jimmy = user_factory()

        mutation = MutationGenerator.add_members_to_team(
            id=team.id, member_ids=[jimmy.id + 1])
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['addMembersToTeam']
        assert response.json()['errors'][0]['message'] == str({
            'member_ids':
            [f'Invalid pk "{jimmy.id + 1}" '
             f'- object does not exist.']
        })
示例#18
0
    def test_unauthenticated(self, client, strand_factory, user_factory,
                             team_factory):
        saver = user_factory()
        owner = team_factory()
        strand = strand_factory.build()

        mutation = MutationGenerator.create_strand(title=strand.title,
                                                   body=strand.body,
                                                   timestamp=strand.timestamp,
                                                   saver_id=saver.id,
                                                   owner_id=owner.id)
        response = client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['createStrand']
        assert response.json()['errors'][0]['message'] == 'Unauthorized'
示例#19
0
    def test_valid(self, superuser_client, user_factory, team_factory):
        assert not mail.outbox
        team = team_factory()
        user = user_factory.build()

        mutation = MutationGenerator.create_user_with_teams(
            email=user.email, username=user.username, team_ids=[team.id])
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createUserWithTeams']['user']['email']
        assert response.json()['data']['createUserWithTeams']['user']['teams'][
            0]['name'] == team.name
        assert mail.outbox[0].subject == 'Welcome to Strand'
        assert mail.outbox[0].to == [user.email]
        assert mail.outbox[0].body
示例#20
0
    def test_invalid_team(self, superuser_client, user_factory, team_factory):
        assert not mail.outbox
        team = team_factory()
        user = user_factory.build()

        mutation = MutationGenerator.create_user_with_teams(
            email=user.email, username=user.username, team_ids=[team.id + 1])
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['createUserWithTeams']
        assert response.json()['errors'][0]['message'] == str({
            'team_ids':
            [f'Invalid pk "{team.id + 1}" '
             f'- object does not exist.']
        })
        assert not mail.outbox
示例#21
0
    def test_valid_add_existing_tags(self, superuser_client, user_factory,
                                     team_factory, strand_factory,
                                     tag_factory):
        jimmy = user_factory()
        owner = team_factory(members=[jimmy])
        strand = strand_factory.build()

        mutation = MutationGenerator.create_strand(
            title=strand.title,
            body=strand.body,
            timestamp=strand.timestamp,
            saver_id=jimmy.id,
            owner_id=owner.id,
            tags=[tag_factory().name, tag_factory().name])
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert response.json()['data']['createStrand']['strand']['title']
        assert len(
            response.json()['data']['createStrand']['strand']['tags']) == 2
示例#22
0
    def test_invalid_owner(self, superuser_client, user_factory, team_factory,
                           strand_factory):
        jimmy = user_factory()
        owner = team_factory(members=[jimmy])
        strand = strand_factory.build()

        mutation = MutationGenerator.create_strand(title=strand.title,
                                                   body=strand.body,
                                                   timestamp=strand.timestamp,
                                                   saver_id=jimmy.id,
                                                   owner_id=owner.id + 1)
        response = superuser_client.post('/graphql', {'query': mutation})

        assert response.status_code == 200, response.content
        assert not response.json()['data']['createStrand']
        assert response.json()['errors'][0]['message'] == str({
            'owner_id':
            [f'Invalid pk "{owner.id + 1}" '
             f'- object does not exist.']
        })