Example #1
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."}'
Example #2
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."}'
Example #3
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."}'
Example #4
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."}'
Example #5
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')
Example #6
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."}'
Example #7
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."}'
Example #8
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')
Example #9
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.irc_nick,
                                         '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
Example #10
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.irc_nick,
                '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
Example #11
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
Example #12
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
Example #13
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)
Example #14
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)