class UserProfileTest(TestCase):
    def setUp(self):
        self.user = SuperUserFactory(password="******")
        success = self.client.login(username=self.user.username,
                                    password="******")
        self.assertTrue(success)

    def test_profile(self):
        self.assertTrue(isinstance(self.user.profile, UserProfile))

        self.assertEqual(self.user.profile.structure.name,
                         settings.DEFAULT_STRUCTURE_NAME)
        self.assertEqual(self.user.profile.language, settings.LANGUAGE_CODE)

    def test_language(self):
        response = self.client.get(reverse('core:path_list'))
        self.assertEqual(200, response.status_code)
        self.assertContains(response, "Logout")

        # Change user lang
        self.assertNotEqual(settings.LANGUAGE_CODE, "fr")
        userprofile = UserProfile.objects.get(user=self.user)
        userprofile.language = "fr"
        userprofile.save()
        self.assertEqual(self.user.profile.language, "fr")
        # No effect if no logout
        response = self.client.get(reverse('core:path_list'))
        self.assertContains(response, "Logout")

        self.client.logout()

        self.client.login(username=self.user.username, password="******")
        response = self.client.get(reverse('core:path_list'))
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], "fr")
        self.assertContains(response, "Déconnexion")

    def test_link_to_adminsite_visible_to_staff(self):
        self.assertTrue(self.user.is_staff)
        response = self.client.get(reverse('core:path_list'))
        self.assertContains(response, '<a href="/admin/">Admin</a>')

    def test_link_to_adminsite_not_visible_to_others(self):
        self.user.is_staff = False
        self.user.save()
        self.client.login(username=self.user.username, password="******")
        response = self.client.get(reverse('core:path_list'))
        self.assertNotContains(response, '<a href="/admin/">Admin</a>')
示例#2
0
class UserProfileTest(TestCase):
    def setUp(self):
        self.user = SuperUserFactory(password=u"Bar")
        success = self.client.login(username=self.user.username, password=u"Bar")
        self.assertTrue(success)

    def test_profile(self):
        self.assertTrue(isinstance(self.user.profile, UserProfile))
        self.assertEqual(self.user.profile, self.user.get_profile())

        self.assertEqual(self.user.profile.structure.name, settings.DEFAULT_STRUCTURE_NAME)
        self.assertEqual(self.user.profile.language, settings.LANGUAGE_CODE)

    def test_language(self):
        response = self.client.get(reverse('core:path_list'))
        self.assertEqual(200, response.status_code)
        self.assertContains(response, "Logout")

        # Change user lang
        self.assertNotEqual(settings.LANGUAGE_CODE, u"fr")
        userprofile = UserProfile.objects.get(user=self.user)
        userprofile.language = u"fr"
        userprofile.save()
        self.assertEqual(self.user.profile.language, u"fr")
        # No effect if no logout
        response = self.client.get(reverse('core:path_list'))
        self.assertContains(response, "Logout")

        self.client.logout()

        self.client.login(username=self.user.username, password=u"Bar")
        response = self.client.get(reverse('core:path_list'))
        self.assertEqual(self.client.session['django_language'], u"fr")
        self.assertContains(response, u"Déconnexion")

    def test_link_to_adminsite_visible_to_staff(self):
        self.assertTrue(self.user.is_staff)
        response = self.client.get(reverse('core:path_list'))
        self.assertContains(response, '<a href="/admin/">Admin</a>')

    def test_link_to_adminsite_not_visible_to_others(self):
        self.user.is_staff = False
        self.user.save()
        self.client.login(username=self.user.username, password=u"Bar")
        response = self.client.get(reverse('core:path_list'))
        self.assertNotContains(response, '<a href="/admin/">Admin</a>')
示例#3
0
class UserProfileTest(TestCase):
    def setUp(self):
        self.user = SuperUserFactory(password="******")
        success = self.client.login(username=self.user.username,
                                    password="******")
        self.assertTrue(success)

    def test_link_to_adminsite_visible_to_staff(self):
        self.assertTrue(self.user.is_staff)
        response = self.client.get(reverse('core:path_list'))
        self.assertContains(response, '<a href="/admin/">Admin</a>')

    def test_link_to_adminsite_not_visible_to_others(self):
        self.user.is_staff = False
        self.user.save()
        self.client.login(username=self.user.username, password="******")
        response = self.client.get(reverse('core:path_list'))
        self.assertNotContains(response, '<a href="/admin/">Admin</a>')