Beispiel #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])
Beispiel #2
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)
Beispiel #3
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)
Beispiel #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)
Beispiel #5
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])
Beispiel #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)
Beispiel #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)
Beispiel #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."}'
Beispiel #9
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'
Beispiel #10
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."}'
Beispiel #11
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."}'
Beispiel #12
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 == '*****@*****.**'
Beispiel #13
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')
Beispiel #14
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."}'
Beispiel #15
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'
Beispiel #16
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'
Beispiel #17
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."}'
Beispiel #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')
Beispiel #19
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."}'
Beispiel #20
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 == '*****@*****.**'
Beispiel #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
Beispiel #22
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."}'
Beispiel #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."}'
Beispiel #24
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
Beispiel #25
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."}'
Beispiel #26
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
Beispiel #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)
Beispiel #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
Beispiel #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
Beispiel #30
0
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
Beispiel #31
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."}'
Beispiel #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
Beispiel #33
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
Beispiel #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
Beispiel #35
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