Ejemplo n.º 1
0
 def from_native(self, data):
     if self.parent.object:
         email = EMails(address=data, content_object=self.parent.object)
     else:
         email = EMails(address=data)
     result = [email]
     return result
Ejemplo n.º 2
0
    def test_change_email(self):
        email = EMails(address="*****@*****.**", content_object=self.user)
        email.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).get_email().address, "*****@*****.**")

        email.address = ""
        email.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).get_email().address, "")

        email.address = "*****@*****.**"
        email.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).get_email().address, "*****@*****.**")
Ejemplo n.º 3
0
    def test_suspend_user(self):
        du1, u1 = self.create_user('amsuspended')
        dtnow = now().replace(hour=0, minute=0, microsecond=0, second=00)
        u1.shadow_last_change = (
            (dtnow - datetime.timedelta(days=5)) - EPOCH).days - u1.shadow_max
        u1.suspended_date = (dtnow - datetime.timedelta(days=5))
        u1.save()
        u1.email.add(EMails(address='*****@*****.**', content_object=u1))

        with self.settings(
                EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
        ):
            c = SuspendAccountCommand()
            c.handle('suspendaccounts', dry=True, force=True)

        u1a = Users.objects.get(username=u1.username)
        self.assertEqual(u1a.google_status, u1a.ACTIVEPERSON)

        with self.settings(
                EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
        ):
            c = SuspendAccountCommand()
            c.handle('suspendaccounts', dry=False, force=True)

        self.assertTrue(u1 in c.suspended)
        u1a = Users.objects.get(username=u1.username)
        self.assertTrue(u1a.shadow_last_change != u1.shadow_last_change)
        g, _ = Groups.objects.get_or_create(name="Disabled")
        self.assertTrue(u1a.in_group(g))
Ejemplo n.º 4
0
    def test_remind_password(self):
        du1, u1 = self.create_user('amok')
        du2, u2 = self.create_user('amexpired')
        dtnow = now().replace(hour=0, minute=0, microsecond=0, second=00)
        u2.shadow_last_change = (
            (dtnow - datetime.timedelta(days=5)) - EPOCH).days - u1.shadow_max
        u2.save()
        u1.shadow_last_change = (
            (dtnow - datetime.timedelta(days=5)) - EPOCH).days - u1.shadow_max
        u1.save()
        u1.email.add(EMails(address='*****@*****.**', content_object=u1))
        self.assertTrue((dtnow - u1.password_expires_date).days, 5 - 1)

        with self.settings(
                EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
        ):
            with patch('fum.management.commands.remind.send_mail') as o:
                c = RemindCommand()
                c.handle('password', dry=True, force=True)
                self.assertFalse(o.called)

        with self.settings(
                EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'
        ):
            with patch('fum.management.commands.remind.send_mail') as o:
                c = RemindCommand()
                c.handle('password', dry=False, force=True)
                self.assertTrue(o.called)

        self.assertTrue(u1 in [k[0] for k in c.emailed])
        self.assertFalse(u2 in [k[0] for k in c.emailed])
Ejemplo n.º 5
0
    def test_user_editing(self):
        self.user.phone1 = "+358 1234 3456"
        self.user.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).phone1, "+35812343456")

        self.user.active_in_planmill = True
        self.user.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).active_in_planmill, True)

        self.user.first_name=u'Täämu'
        self.user.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).first_name, u'Täämu')

        email = EMails(address="*****@*****.**", content_object=self.user)
        email.save()
        self.assertEqual(Users.objects.get(username=self.USERNAME).get_email().address, "*****@*****.**")
Ejemplo n.º 6
0
    def test_change_email(self):
        email = EMails(address="*****@*****.**",
                       content_object=self.user)
        email.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).get_email().address,
            "*****@*****.**")

        email.address = ""
        email.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).get_email().address, "")

        email.address = "*****@*****.**"
        email.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).get_email().address,
            "*****@*****.**")
Ejemplo n.º 7
0
    def test_email_valid_via_user(self):
        email = EMails.objects.create(
            address="*****@*****.**",
            content_type=ContentType.objects.get_for_model(self.user),
            object_id=self.user.pk)

        try:
            mail = "notvalid@futurice"
            self.user.email.add(EMails(address=mail, content_object=self.user))
        except Exception, e:
            print e
            pass
Ejemplo n.º 8
0
    def test_user_editing(self):
        self.user.phone1 = "+358 1234 3456"
        self.user.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).phone1, "+35812343456")

        self.user.active_in_planmill = True
        self.user.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).active_in_planmill, True)

        self.user.first_name = u'Täämu'
        self.user.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).first_name, u'Täämu')

        email = EMails(address="*****@*****.**",
                       content_object=self.user)
        email.save()
        self.assertEqual(
            Users.objects.get(username=self.USERNAME).get_email().address,
            "*****@*****.**")
Ejemplo n.º 9
0
    def test_user_email(self):
        self.assertEqual(self.user.email.all().count(), 0)
        self.user.email.add(
            EMails(address='*****@*****.**', content_object=self.user))
        self.assertEqual(self.user.email.all().count(), 1)
        self.assertEqual(self.ldap_val('mail', self.user),
                         ['*****@*****.**'])
        self.user.title = 'something else'
        self.user.save()
        self.assertEqual(self.user.email.all().count(), 1)
        self.assertEqual(self.ldap_val('mail', self.user),
                         ['*****@*****.**'])

        self.user.email.add(
            EMails(address='*****@*****.**', content_object=self.user))
        self.assertEqual(self.user.email.all().count(), 1)
        self.assertEqual(self.user.email.all()[0].address,
                         '*****@*****.**')
        self.assertEqual(self.ldap_val('mail', self.user),
                         ['*****@*****.**'])
        self.user.email = [
        ]  # unsetting email in API might be problematic :knock wood-not so
        self.assertEqual(self.user.email.all().count(), 0)
Ejemplo n.º 10
0
            object_id=self.user.pk)

        try:
            mail = "notvalid@futurice"
            self.user.email.add(EMails(address=mail, content_object=self.user))
        except Exception, e:
            print e
            pass

        self.assertEqual(
            Users.objects.get(username=self.USERNAME).get_email().address,
            "*****@*****.**")

        try:
            mail = "not valid mail"
            self.user.email.add(EMails(address=mail, content_object=self.user))
        except Exception, e:
            print e
            pass

        self.assertEqual(
            Users.objects.get(username=self.USERNAME).get_email().address,
            "*****@*****.**")

        try:
            mail = "*****@*****.**"
            self.user.email.add(EMails(address=mail, content_object=self.user))
        except Exception, e:
            print e
            pass