Exemple #1
0
    def test_send_activation_email(self):
        user_admin = UserAdmin(get_user_model(), AdminSite())

        qs = get_user_model().objects.all()
        user_admin.send_activation_email(self.request, qs)
        # we created 1 inactive user, so there should be one email in outbox
        self.assertEqual(len(mail.outbox), 1)
Exemple #2
0
    def test_send_activation_email(self):
        user_admin = UserAdmin(get_user_model(), AdminSite())

        qs = get_user_model().objects.all()
        user_admin.send_activation_email(self.request, qs)
        # we created 1 inactive user, so there should be one email in outbox
        self.assertEqual(len(mail.outbox), 1)
Exemple #3
0
    def test_activate_users(self):
        user_admin = UserAdmin(get_user_model(), AdminSite())

        qs = get_user_model().objects.all()
        user_admin.activate_users(self.request, qs)
        # both users should be active
        self.assertEqual(get_user_model().objects.filter(is_active=True).count(), 2)
        # superuser is automatically activated. so we test the attribute for [email protected]
        user = get_user_model().objects.get(email='*****@*****.**')
        self.assertTrue(user.is_active)
Exemple #4
0
    def test_activate_users(self):
        user_admin = UserAdmin(get_user_model(), AdminSite())

        qs = get_user_model().objects.all()
        user_admin.activate_users(self.request, qs)
        # both users should be active
        self.assertEqual(
            get_user_model().objects.filter(is_active=True).count(), 2)
        # superuser is automatically activated. so we test the attribute for [email protected]
        user = get_user_model().objects.get(email='*****@*****.**')
        self.assertTrue(user.is_active)
Exemple #5
0
class TestUserAdmin(UsersTestBase):
    def setup_method(self):
        super().setup_method()
        self.site = AdminSite()
        self.admin = UserAdmin(admin_site=self.site, model=User)

    def test_email(self):
        email_link = self.admin._email(self.user)
        assert email_link.startswith(f'<a href="mailto:{self.user.email}')

    def test_email_empty(self):
        email_link = self.admin._email(User.objects.get(pk=2))
        assert email_link == ''

    def test_full_name(self):
        assert self.admin.full_name(self.user) == 'evangelos ch'

    def test_has_add_permission(self):
        request = HttpRequest()
        assert not self.admin.has_add_permission(request)
Exemple #6
0
 def test_get_queryset(self):
     user_admin = UserAdmin(get_user_model(), AdminSite())
     self.assertQuerysetEqual(
         user_admin.get_queryset(self.request),
         ['<User: [email protected]>', '<User: [email protected]>'],
         ordered=False)
Exemple #7
0
 def test_get_queryset(self):
     user_admin = UserAdmin(get_user_model(), AdminSite())
     self.assertQuerysetEqual(
         user_admin.get_queryset(self.request),
         ['<User: [email protected]>', '<User: [email protected]>'], ordered=False)
Exemple #8
0
 def setup_method(self):
     super().setup_method()
     self.site = AdminSite()
     self.admin = UserAdmin(admin_site=self.site, model=User)