Example #1
0
    def test_user_does_not_exist(self):
        token = SystemTokenFactory.create()

        resp = self.client.post_json(reverse('api.user-update',
                                             kwargs={'username': '******'}),
                                     payload={
                                         'api_key': token.token,
                                         'name': 'lor',
                                     })
        assert resp.status_code == 400
        assert resp.content == b'{"error": "User does not exist."}'
Example #2
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."}'
Example #3
0
    def test_user_does_not_exist(self):
        token = SystemTokenFactory.create()

        resp = self.client.post_json(
            reverse('api.user-update', kwargs={'username': '******'}),
            payload={
                'api_key': token.token,
                'name': 'lor',
            }
        )
        assert resp.status_code == 400
        assert resp.content == b'{"error": "User does not exist."}'
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_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."}'
Example #7
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 == '*****@*****.**'
Example #8
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'
Example #9
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 #10
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'
Example #11
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 #12
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'
Example #13
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 == '*****@*****.**'
Example #14
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 #15
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 #16
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
Example #17
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."}'
Example #18
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
Example #19
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 #20
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."}'
Example #21
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
Example #22
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
Example #23
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
Example #24
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 #25
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
Example #26
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
Example #27
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 #28
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