Exemplo n.º 1
0
    def test_teams(self, db, django_user_model):
        """Verify teams get carried over"""
        team1 = TeamFactory.create()
        team2 = TeamFactory.create()
        team3 = TeamFactory.create()

        user_keep = UserFactory.create(username='******',
                                       email='*****@*****.**')
        standupuser_keep = StandupUserFactory.create(user=user_keep)
        team1.users.add(standupuser_keep)
        team1.save()
        team3.users.add(standupuser_keep)
        team3.save()

        user_delete = UserFactory.create(username='******',
                                         email='*****@*****.**')
        standupuser_delete = StandupUserFactory.create(user=user_delete)
        team1.users.add(standupuser_delete)
        team1.save()
        team2.users.add(standupuser_delete)
        team2.save()

        stdout = StringIO()
        call_command('mergeuser',
                     keep=user_keep.id,
                     delete=user_delete.id,
                     assume_yes=True,
                     stdout=stdout)
        output = stdout.getvalue()
        print(output)

        user_keep = django_user_model.objects.get(id=user_keep.id)
        teams = [team.name for team in user_keep.profile.teams.all()]
        assert sorted(teams) == sorted([team1.name, team2.name, team3.name])
Exemplo n.º 2
0
    def test_teams(self, db, django_user_model):
        """Verify teams get carried over"""
        team1 = TeamFactory.create()
        team2 = TeamFactory.create()
        team3 = TeamFactory.create()

        user_keep = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_keep = StandupUserFactory.create(user=user_keep)
        team1.users.add(standupuser_keep)
        team1.save()
        team3.users.add(standupuser_keep)
        team3.save()

        user_delete = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_delete = StandupUserFactory.create(user=user_delete)
        team1.users.add(standupuser_delete)
        team1.save()
        team2.users.add(standupuser_delete)
        team2.save()

        stdout = StringIO()
        call_command('mergeuser', keep=user_keep.id, delete=user_delete.id, assume_yes=True, stdout=stdout)
        output = stdout.getvalue()
        print(output)

        user_keep = django_user_model.objects.get(id=user_keep.id)
        teams = [team.name for team in user_keep.profile.teams.all()]
        assert sorted(teams) == sorted([team1.name, team2.name, team3.name])
Exemplo n.º 3
0
    def test_keep_and_delete_have_standupser(self, db, django_user_model):
        """Test when keep and delete both have standup users"""
        user_keep = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_keep = StandupUserFactory.create(user=user_keep)
        StatusFactory.create(user=standupuser_keep, content='1'),
        StatusFactory.create(user=standupuser_keep, content='2'),
        StatusFactory.create(user=standupuser_keep, content='3'),

        user_delete = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_delete = StandupUserFactory.create(user=user_delete)
        StatusFactory.create(user=standupuser_delete, content='4'),
        StatusFactory.create(user=standupuser_delete, content='5'),
        StatusFactory.create(user=standupuser_delete, content='6'),

        stdout = StringIO()
        call_command('mergeuser', keep=user_keep.id, delete=user_delete.id, assume_yes=True, stdout=stdout)
        output = stdout.getvalue()
        print(output)

        # Verify all statuses were transfered from delete to keep
        user_keep = django_user_model.objects.get(id=user_keep.id)
        statuses = [status.content for status in user_keep.profile.statuses.all()]
        assert sorted(statuses) == ['1', '2', '3', '4', '5', '6']

        # Verify email address was transferred from delete -> keep
        assert user_keep.email == '*****@*****.**'

        # Verify delete no longer exists
        with pytest.raises(django_user_model.DoesNotExist):
            django_user_model.objects.get(id=user_delete.id)
Exemplo n.º 4
0
def test_find_user(db):
    user = UserFactory.create(username='******', email='*****@*****.**')
    StandupUserFactory.create(user=user, irc_nick='jimbobbaz')

    stdout = StringIO()
    call_command('finduser', 'willkg', stdout=stdout)
    output = stdout.getvalue().splitlines()
    assert len(output) == 4
    for i, starter in enumerate([
            'Searching for: willkg',
            '-----',
            'user_id',
            '-----'
    ]):
        assert output[i].startswith(starter)

    stdout = StringIO()
    call_command('finduser', 'jimbob', stdout=stdout)
    output = stdout.getvalue().splitlines()
    assert len(output) == 5
    for i, starter in enumerate([
            'Searching for: jimbob',
            '-----',
            'user_id  username',
            '%-5d    jimbob' % user.id,
    ]):
        print((i, output[i], starter))
        assert output[i].startswith(starter)
Exemplo n.º 5
0
def test_find_user(db):
    user = UserFactory.create(username='******', email='*****@*****.**')
    StandupUserFactory.create(user=user, irc_nick='jimbobbaz')

    stdout = StringIO()
    call_command('finduser', 'willkg', stdout=stdout)
    output = stdout.getvalue().splitlines()
    assert len(output) == 4
    for i, starter in enumerate([
            'Searching for: willkg',
            '-----',
            'user_id',
            '-----'
    ]):
        assert output[i].startswith(starter)

    stdout = StringIO()
    call_command('finduser', 'jimbob', stdout=stdout)
    output = stdout.getvalue().splitlines()
    assert len(output) == 5
    for i, starter in enumerate([
            'Searching for: jimbob',
            '-----',
            'user_id  username',
            '1        jimbob',
    ]):
        print((i, output[i], starter))
        assert output[i].startswith(starter)
Exemplo n.º 6
0
    def test_keep_and_delete_have_standupser(self, db, django_user_model):
        """Test when keep and delete both have standup users"""
        user_keep = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_keep = StandupUserFactory.create(user=user_keep)
        StatusFactory.create(user=standupuser_keep, content='1'),
        StatusFactory.create(user=standupuser_keep, content='2'),
        StatusFactory.create(user=standupuser_keep, content='3'),

        user_delete = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_delete = StandupUserFactory.create(user=user_delete)
        StatusFactory.create(user=standupuser_delete, content='4'),
        StatusFactory.create(user=standupuser_delete, content='5'),
        StatusFactory.create(user=standupuser_delete, content='6'),

        stdout = StringIO()
        call_command('mergeuser', keep=user_keep.id, delete=user_delete.id, assume_yes=True, stdout=stdout)
        output = stdout.getvalue()
        print(output)

        # Verify all statuses were transfered from delete to keep
        user_keep = django_user_model.objects.get(id=user_keep.id)
        statuses = [status.content for status in user_keep.profile.statuses.all()]
        assert sorted(statuses) == ['1', '2', '3', '4', '5', '6']

        # Verify email address was transferred from delete -> keep
        assert user_keep.email == '*****@*****.**'

        # Verify delete no longer exists
        with pytest.raises(django_user_model.DoesNotExist):
            django_user_model.objects.get(id=user_delete.id)
Exemplo n.º 7
0
    def test_keep_no_standupuser_but_delete_has_standupuser(
            self, db, django_user_model):
        """Test when keep has no standup user, but delete does"""
        user_keep = UserFactory.create(username='******',
                                       email='*****@*****.**')
        user_delete = UserFactory.create(username='******',
                                         email='*****@*****.**')
        standupuser_delete = StandupUserFactory.create(user=user_delete)

        stdout = StringIO()
        call_command('mergeuser',
                     keep=user_keep.id,
                     delete=user_delete.id,
                     assume_yes=True,
                     stdout=stdout)
        output = stdout.getvalue()
        print(output)

        # Verify profile was transfered from delete to keep
        user_keep = django_user_model.objects.get(id=user_keep.id)
        assert user_keep.profile.id == standupuser_delete.id

        # Verify delete no longer exists
        with pytest.raises(django_user_model.DoesNotExist):
            django_user_model.objects.get(id=user_delete.id)
Exemplo n.º 8
0
    def test_status_does_not_exist(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        resp = self.client.delete_json(reverse('api.status-delete',
                                               kwargs={'pk': str(1000)}),
                                       payload={
                                           'api_key': token.token,
                                           'user': standupuser.irc_nick,
                                       })
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Status does not exist."}'
Exemplo n.º 9
0
    def test_delete(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create(user=standupuser)

        resp = self.client.delete_json(reverse('api.status-delete',
                                               kwargs={'pk': str(status.id)}),
                                       payload={
                                           'api_key': token.token,
                                           'user': standupuser.irc_nick,
                                       })
        assert resp.status_code == 200
        assert resp.content == ('{"id": %s}' % (status.id, )).encode('utf-8')
Exemplo n.º 10
0
    def test_invalid_username(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create(user=standupuser)

        resp = self.client.delete_json(reverse('api.status-delete',
                                               kwargs={'pk': str(status.id)}),
                                       payload={
                                           'api_key': token.token,
                                           'user': ''
                                       })
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Missing required fields."}'
Exemplo n.º 11
0
    def test_update_github_handle(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(github_handle='data')

        resp = self.client.post_json(reverse(
            'api.user-update', kwargs={'username': standupuser.username}),
                                     payload={
                                         'api_key': token.token,
                                         'github_handle': 'lor',
                                     })
        assert resp.status_code == 200
        standupuser = StandupUser.objects.get(pk=standupuser.id)
        assert standupuser.github_handle == 'lor'
Exemplo n.º 12
0
    def test_wrong_user(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(user__username='******')
        status = StatusFactory.create(user=standupuser)

        resp = self.client.delete_json(reverse('api.status-delete',
                                               kwargs={'pk': str(status.id)}),
                                       payload={
                                           'api_key': token.token,
                                           'user': '******',
                                       })
        assert resp.status_code == 403
        assert resp.content == b'{"error": "You cannot delete this status."}'
Exemplo n.º 13
0
    def test_update_name(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(name='Data')

        resp = self.client.post_json(reverse(
            'api.user-update', kwargs={'username': standupuser.irc_nick}),
                                     payload={
                                         'api_key': token.token,
                                         'name': 'Lor',
                                     })
        assert resp.status_code == 200
        standupuser = StandupUser.objects.get(pk=standupuser.id)
        assert standupuser.name == 'Lor'
Exemplo n.º 14
0
    def test_update_email(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(email='*****@*****.**')

        resp = self.client.post_json(reverse(
            'api.user-update', kwargs={'username': standupuser.irc_nick}),
                                     payload={
                                         'api_key': token.token,
                                         'email': '*****@*****.**',
                                     })
        assert resp.status_code == 200
        standupuser = StandupUser.objects.get(pk=standupuser.id)
        assert standupuser.email == '*****@*****.**'
Exemplo n.º 15
0
    def test_status_does_not_exist(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        resp = self.client.delete_json(
            reverse('api.status-delete', kwargs={'pk': str(1000)}),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
            }
        )
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Status does not exist."}'
Exemplo n.º 16
0
    def test_update_email(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(email='*****@*****.**')

        resp = self.client.post_json(
            reverse('api.user-update', kwargs={'username': standupuser.irc_nick}),
            payload={
                'api_key': token.token,
                'email': '*****@*****.**',
            }
        )
        assert resp.status_code == 200
        standupuser = StandupUser.objects.get(pk=standupuser.id)
        assert standupuser.email == '*****@*****.**'
Exemplo n.º 17
0
    def test_update_name(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(name='Data')

        resp = self.client.post_json(
            reverse('api.user-update', kwargs={'username': standupuser.irc_nick}),
            payload={
                'api_key': token.token,
                'name': 'Lor',
            }
        )
        assert resp.status_code == 200
        standupuser = StandupUser.objects.get(pk=standupuser.id)
        assert standupuser.name == 'Lor'
Exemplo n.º 18
0
    def test_delete(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create(user=standupuser)

        resp = self.client.delete_json(
            reverse('api.status-delete', kwargs={'pk': str(status.id)}),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
            }
        )
        assert resp.status_code == 200
        assert resp.content == ('{"id": %s}' % (status.id,)).encode('utf-8')
Exemplo n.º 19
0
    def test_wrong_user(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create(user__username='******')
        status = StatusFactory.create(user=standupuser)

        resp = self.client.delete_json(
            reverse('api.status-delete', kwargs={'pk': str(status.id)}),
            payload={
                'api_key': token.token,
                'user': '******',
            }
        )
        assert resp.status_code == 403
        assert resp.content == b'{"error": "You cannot delete this status."}'
Exemplo n.º 20
0
    def test_invalid_username(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create(user=standupuser)

        resp = self.client.delete_json(
            reverse('api.status-delete', kwargs={'pk': str(status.id)}),
            payload={
                'api_key': token.token,
                'user': ''
            }
        )
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Missing required fields."}'
Exemplo n.º 21
0
    def test_reply_to_status_doesnt_exist(self):
        """Verify replying to a status that doesn't exist fails"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.irc_nick,
                                         'reply_to': 1000,
                                         'content': content
                                     })
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Status does not exist."}'
Exemplo n.º 22
0
    def test_post(self):
        """Test minimal post"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.irc_nick,
                                         'content': content
                                     })
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
Exemplo n.º 23
0
    def test_reply_to_status_doesnt_exist(self):
        """Verify replying to a status that doesn't exist fails"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(
            reverse('api.status-create'),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
                'reply_to': 1000,
                'content': content
            }
        )
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Status does not exist."}'
Exemplo n.º 24
0
    def test_post(self):
        """Test minimal post"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(
            reverse('api.status-create'),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
                'content': content
            }
        )
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
Exemplo n.º 25
0
    def test_reply_to(self):
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.user.username,
                                         'reply_to': status.id,
                                         'content': content
                                     })
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        assert post.reply_to.id == status.id
Exemplo n.º 26
0
    def test_reply_to_reply(self):
        """Verify you can't reply to a reply-to"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create()
        reply = StatusFactory.create(reply_to=status)

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.irc_nick,
                                         'reply_to': reply.id,
                                         'content': content
                                     })
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Cannot reply to a reply."}'
Exemplo n.º 27
0
    def test_keep_no_standupuser_but_delete_has_standupuser(self, db, django_user_model):
        """Test when keep has no standup user, but delete does"""
        user_keep = UserFactory.create(username='******', email='*****@*****.**')
        user_delete = UserFactory.create(username='******', email='*****@*****.**')
        standupuser_delete = StandupUserFactory.create(user=user_delete)

        stdout = StringIO()
        call_command('mergeuser', keep=user_keep.id, delete=user_delete.id, assume_yes=True, stdout=stdout)
        output = stdout.getvalue()
        print(output)

        # Verify profile was transfered from delete to keep
        user_keep = django_user_model.objects.get(id=user_keep.id)
        assert user_keep.profile.id == standupuser_delete.id

        # Verify delete no longer exists
        with pytest.raises(django_user_model.DoesNotExist):
            django_user_model.objects.get(id=user_delete.id)
Exemplo n.º 28
0
    def test_post_with_new_project(self):
        """Test post with an new project"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.irc_nick,
                                         'project': 'jcoulton',
                                         'content': content
                                     })
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        project = Project.objects.filter(slug='jcoulton').first()
        assert post.project.id == project.id
Exemplo n.º 29
0
    def test_post_with_existing_project(self):
        """Test post with an existing project"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        project = ProjectFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.irc_nick,
                                         'project': project.slug,
                                         'content': content
                                     })
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        assert post.project.id == project.id
Exemplo n.º 30
0
    def test_reply_to_reply(self):
        """Verify you can't reply to a reply-to"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create()
        reply = StatusFactory.create(reply_to=status)

        content = next(content_generator)
        resp = self.client.post_json(
            reverse('api.status-create'),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
                'reply_to': reply.id,
                'content': content
            }
        )
        assert resp.status_code == 400
        assert resp.content == b'{"error": "Cannot reply to a reply."}'
Exemplo n.º 31
0
    def test_post_with_existing_project(self):
        """Test post with an existing project"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        project = ProjectFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(
            reverse('api.status-create'),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
                'project': project.slug,
                'content': content
            }
        )
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        assert post.project.id == project.id
Exemplo n.º 32
0
    def test_post_with_new_project(self):
        """Test post with an new project"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(
            reverse('api.status-create'),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
                'project': 'jcoulton',
                'content': content
            }
        )
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        project = Project.objects.filter(slug='jcoulton').first()
        assert post.project.id == project.id
Exemplo n.º 33
0
    def test_reply_to_with_project(self):
        """Verify posting a reply-to ignores the project"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create()
        project = ProjectFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(reverse('api.status-create'),
                                     payload={
                                         'api_key': token.token,
                                         'user': standupuser.irc_nick,
                                         'reply_to': status.id,
                                         'project': project.id,
                                         'content': content
                                     })
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        assert post.reply_to.id == status.id
        assert post.project is None
Exemplo n.º 34
0
    def test_reply_to_with_project(self):
        """Verify posting a reply-to ignores the project"""
        token = SystemTokenFactory.create()
        standupuser = StandupUserFactory.create()
        status = StatusFactory.create()
        project = ProjectFactory.create()

        content = next(content_generator)
        resp = self.client.post_json(
            reverse('api.status-create'),
            payload={
                'api_key': token.token,
                'user': standupuser.irc_nick,
                'reply_to': status.id,
                'project': project.id,
                'content': content
            }
        )
        assert resp.status_code == 200
        post = Status.objects.get(content=content)
        assert post.user.id == standupuser.id
        assert post.reply_to.id == status.id
        assert post.project is None