Ejemplo n.º 1
0
class UsernameUpdateFormTestCase(TestCase):
    """Tests for the ``UsernameUpdateForm`` form class."""
    longMessage = True

    def setUp(self):
        super(UsernameUpdateFormTestCase, self).setUp()
        self.data = {
            'username': '******',
        }
        self.profile = UserProfileFactory()

    def test_form(self):
        """Should save the username."""
        form = UsernameUpdateForm(instance=self.profile, data=self.data)
        self.assertTrue(form.is_valid(),
                        msg=('Errors: {0}'.format(form.errors.items())))
        instance = form.save()
        self.assertEqual(instance.username, 'foobar')

    def test_unique(self):
        """Checks if username exists before saving."""
        self.profile.username = '******'
        self.profile.save()
        form = UsernameUpdateForm(instance=self.profile, data=self.data)
        self.assertFalse(form.is_valid())
        self.assertTrue('username' in form.errors)
Ejemplo n.º 2
0
class UserProfileTestCase(TestCase):
    """Tests for the ``UserProfile`` model."""
    def setUp(self):
        self.profile = UserProfileFactory()

    def test_model(self):
        self.assertTrue(self.profile.pk)

    def test_get_absolute_url(self):
        self.profile.username = '******'
        self.profile.save()
        result = self.profile.get_absolute_url()
        self.assertEqual(result, '/profile/foobar/')
Ejemplo n.º 3
0
class UserProfileTestCase(TestCase):
    """Tests for the ``UserProfile`` model."""
    def setUp(self):
        self.profile = UserProfileFactory()

    def test_model(self):
        self.assertTrue(self.profile.pk)

    def test_get_absolute_url(self):
        self.profile.username = '******'
        self.profile.save()
        result = self.profile.get_absolute_url()
        self.assertEqual(result, '/profile/foobar/')
Ejemplo n.º 4
0
class PublicProfileViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``PublicProfileView`` view class."""
    longMessage = True

    def setUp(self):
        self.profile = UserProfileFactory()
        self.profile.username = '******'
        self.profile.save()

    def get_view_name(self):
        return 'user_profile_public_profile'

    def get_view_kwargs(self):
        return {'username': self.profile.username, }

    def test_callable(self):
        """Should be callable."""
        self.should_be_callable_when_anonymous()
Ejemplo n.º 5
0
class CustomCheckinCreateFormTestCase(TestCase):
    """Tests for the ``CustomCheckinCreateForm`` form class."""
    def setUp(self):
        super(CustomCheckinCreateFormTestCase, self).setUp()
        self.profile = UserProfileFactory()
        self.place = PlaceFactory()
        self.data = {
            'user_name': 'Foobar',
            'lat': '1.3568494',
            'lng': '103.9478796',
        }

    def test_adds_user_name_field(self):
        """Should add the user_name field if the user has no display name."""
        form = CustomCheckinCreateForm(user=self.profile.user,
                                       place=self.place,
                                       data={})
        self.assertTrue('user_name' in form.fields)

    def test_does_not_add_user_name_field(self):
        """Shouldn't add user_name field if the user has a display name."""
        self.profile.display_name = 'Foobar'
        self.profile.save()
        form = CustomCheckinCreateForm(user=self.profile.user,
                                       place=self.place,
                                       data={})
        self.assertFalse('user_name' in form.fields)

    def test_save(self):
        """
        Should set the user's display name when saved.

        That way the user only has to set it once on the first check-in.

        """
        self.assertEqual(self.profile.display_name, '')
        form = CustomCheckinCreateForm(user=self.profile.user,
                                       place=self.place,
                                       data=self.data)
        self.assertTrue(form.is_valid(),
                        msg=('Errors: {0}'.format(form.errors.items())))
        form.save()
        profile = UserProfile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.display_name, 'Foobar')
Ejemplo n.º 6
0
class PublicProfileViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``PublicProfileView`` view class."""
    longMessage = True

    def setUp(self):
        self.profile = UserProfileFactory()
        self.profile.username = '******'
        self.profile.save()

    def get_view_name(self):
        return 'user_profile_public_profile'

    def get_view_kwargs(self):
        return {
            'username': self.profile.username,
        }

    def test_callable(self):
        """Should be callable."""
        self.should_be_callable_when_anonymous()
Ejemplo n.º 7
0
class CustomCheckinCreateFormTestCase(TestCase):
    """Tests for the ``CustomCheckinCreateForm`` form class."""
    def setUp(self):
        super(CustomCheckinCreateFormTestCase, self).setUp()
        self.profile = UserProfileFactory()
        self.place = PlaceFactory()
        self.data = {
            'user_name': 'Foobar',
            'lat': '1.3568494',
            'lng': '103.9478796',
        }

    def test_adds_user_name_field(self):
        """Should add the user_name field if the user has no display name."""
        form = CustomCheckinCreateForm(
            user=self.profile.user, place=self.place, data={})
        self.assertTrue('user_name' in form.fields)

    def test_does_not_add_user_name_field(self):
        """Shouldn't add user_name field if the user has a display name."""
        self.profile.display_name = 'Foobar'
        self.profile.save()
        form = CustomCheckinCreateForm(
            user=self.profile.user, place=self.place, data={})
        self.assertFalse('user_name' in form.fields)

    def test_save(self):
        """
        Should set the user's display name when saved.

        That way the user only has to set it once on the first check-in.

        """
        self.assertEqual(self.profile.display_name, '')
        form = CustomCheckinCreateForm(
            user=self.profile.user, place=self.place, data=self.data)
        self.assertTrue(form.is_valid(), msg=(
            'Errors: {0}'.format(form.errors.items())))
        form.save()
        profile = UserProfile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.display_name, 'Foobar')
Ejemplo n.º 8
0
class UsernameUpdateViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``UniqueNameUpdateView`` view class."""
    longMessage = True

    def setUp(self):
        super(UsernameUpdateViewTestCase, self).setUp()
        self.profile = UserProfileFactory()

    def get_view_name(self):
        return 'user_profile_username_update'

    def test_login_required(self):
        """Should redirect to login if anonymous."""
        self.should_redirect_to_login_when_anonymous()

    def test_callable(self):
        """Should be callable if user is authenticated."""
        self.should_be_callable_when_authenticated(self.profile.user)

    def test_not_callable(self):
        """
        Should redirect to profile if user has already taken his username.

        """
        self.profile.username = '******'
        self.profile.save()
        self.login(self.profile.user)
        resp = self.client.get(self.get_url())
        self.assertRedirects(resp, reverse('user_profile_update'))

    def test_save(self):
        """Should save the username on a POST request."""
        self.login(self.profile.user)
        self.client.post(self.get_url(), data={'username': '******'})
        profile = UserProfile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.username, 'foobar')
Ejemplo n.º 9
0
class UsernameUpdateViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``UniqueNameUpdateView`` view class."""
    longMessage = True

    def setUp(self):
        super(UsernameUpdateViewTestCase, self).setUp()
        self.profile = UserProfileFactory()

    def get_view_name(self):
        return 'user_profile_username_update'

    def test_login_required(self):
        """Should redirect to login if anonymous."""
        self.should_redirect_to_login_when_anonymous()

    def test_callable(self):
        """Should be callable if user is authenticated."""
        self.should_be_callable_when_authenticated(self.profile.user)

    def test_not_callable(self):
        """
        Should redirect to profile if user has already taken his username.

        """
        self.profile.username = '******'
        self.profile.save()
        self.login(self.profile.user)
        resp = self.client.get(self.get_url())
        self.assertRedirects(resp, reverse('user_profile_update'))

    def test_save(self):
        """Should save the username on a POST request."""
        self.login(self.profile.user)
        self.client.post(self.get_url(), data={'username': '******'})
        profile = UserProfile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.username, 'foobar')
Ejemplo n.º 10
0
class UsernameUpdateFormTestCase(TestCase):
    """Tests for the ``UsernameUpdateForm`` form class."""
    longMessage = True

    def setUp(self):
        super(UsernameUpdateFormTestCase, self).setUp()
        self.data = {'username': '******', }
        self.profile = UserProfileFactory()

    def test_form(self):
        """Should save the username."""
        form = UsernameUpdateForm(instance=self.profile, data=self.data)
        self.assertTrue(form.is_valid(), msg=(
            'Errors: {0}'.format(form.errors.items())))
        instance = form.save()
        self.assertEqual(instance.username, 'foobar')

    def test_unique(self):
        """Checks if username exists before saving."""
        self.profile.username = '******'
        self.profile.save()
        form = UsernameUpdateForm(instance=self.profile, data=self.data)
        self.assertFalse(form.is_valid())
        self.assertTrue('username' in form.errors)