def test_single_page(self): # The page length is 20, so we build just 5 StatusFactory.create_batch(5) resp = self.client.get(reverse('home-view')) assert resp.status_code == 200 # FIXME: Need a better assertion here. Should probably assert that 5 # statuses got rendered. self.assertNotContains(resp, 'No status updates available')
def test_single_page(self): # The page length is 20, so we build just 5 StatusFactory.create_batch(5) resp = self.client.get(reverse('status.index')) assert resp.status_code == 200 # FIXME: Need a better assertion here. Should probably assert that 5 # statuses got rendered. self.assertNotContains(resp, 'No status updates available')
def test_tags(): """Test that format update parses tags correctly""" # Test valid tags. for tag in ('#t', '#tag', '#TAG', '#tag123'): expected = '<p><span class="tag tag-%s">%s</span></p>' % (tag[1:].lower(), tag) assert StatusFactory(content=tag).htmlify() == expected # Test invalid tags. Not first b/c markdown. for tag in ('tag #1', 'tag #.abc', 'tag #?abc'): assert StatusFactory(content=tag).htmlify() == '<p>%s</p>' % tag
def test_tags(): """Test that format update parses tags correctly""" # Test valid tags. for tag in ('#t', '#tag', '#TAG', '#tag123'): expected = '%s <div class="tags">%s</div>' % ( tag, TAG_TMPL.format('', tag[1:].lower(), tag[1:])) assert StatusFactory(content=tag).htmlify() == expected # Test invalid tags. for tag in ('#1', '#.abc', '#?abc'): assert StatusFactory(content=tag).htmlify() == tag
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."}'
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."}'
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')
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."}'
def test_status_htmlify(): # plain olde markdown links should work original = '[The Dude](https://example.com/dude)' expected = '<p><a href="https://example.com/dude" rel="nofollow">The Dude</a></p>' assert StatusFactory(content=original).htmlify() == expected # bare urls should work as well, and be truncated original = 'My site is https://example.com/the-dude-abides-man' expected = '<p>My site is <a href="https://example.com/the-dude-abides-man" rel="nofollow">' \ 'https://example.com/the-dude-a...</a></p>' assert StatusFactory(content=original).htmlify() == expected # https://github.com/mozilla/standup/issues/321 original = '[#1234](https://example.com/dude)' expected = '<p><a href="https://example.com/dude" rel="nofollow">#1234</a></p>' assert StatusFactory(content=original).htmlify() == expected # bugzilla linking original = 'Bug 1234, bug #5678' expected = ( '<p>' '<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=1234" rel="nofollow">Bug 1234</a>, ' '<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=5678" rel="nofollow">bug #5678</a>' '</p>' ) assert StatusFactory(content=original).htmlify() == expected # github linking original = 'pr 1234, issue #5678' expected = '<p><a href="{0}pull/1234" rel="nofollow">pr 1234</a>, ' \ '<a href="{0}issues/5678" rel="nofollow">issue #5678</a></p>' status = StatusFactory(content=original) expected = expected.format(status.project.repo_url) assert status.htmlify() == expected # user linking StandupUserFactory(user__username='******') original = 'phone\'s ringing @dude' expected = '<p>phone\'s ringing <a href="/user/dude/" rel="nofollow">@dude</a></p>' assert StatusFactory(content=original).htmlify() == expected # not a user original = 'phone\'s ringing @bunny' expected = '<p>phone\'s ringing @bunny</p>' assert StatusFactory(content=original).htmlify() == expected
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."}'
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')
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."}'
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."}'
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
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
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
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
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)
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)