Ejemplo n.º 1
0
 def setUp(self):
     super(MasterAdminTestCase, self).setUp()
     self.master_admin = UserFactory(email='*****@*****.**',
                                     is_superuser=True,
                                     is_staff=True)
     self.master_admin.set_password('neptune123')
     self.master_admin.save()
Ejemplo n.º 2
0
    def setUp(self):
        self.user_1 = UserFactory(
            username="******",
            settings__first_name="Matti",
            settings__last_name="Meikäläinen",
            settings__municipality=MunicipalityFactory(name_fi="Helsinki"))
        self.user_2 = UserFactory(
            username="******",
            settings__first_name="Henri",
            settings__last_name="Kuisma",
            settings__municipality=MunicipalityFactory(name_fi="Vantaa"))
        self.user_3 = UserFactory(
            username="******",
            settings__first_name="Kalevi",
            settings__last_name="Kuusisto",
            settings__municipality=MunicipalityFactory(name_fi="Espoo"))
        organization_1 = Organization.objects.create(name="Helsingin koulu",
                                                     type=1)
        organization_2 = Organization.objects.create(name="Turun koulu",
                                                     type=1)
        self.user_1.organizations.add(organization_1)
        self.user_2.organizations.add(organization_1)
        self.user_2.organizations.add(organization_2)
        self.user_3.organizations.add(organization_2)

        group_admin = Group.objects.get(name=GROUP_NAME_ADMINS)
        self.user_1.groups.add(group_admin)
        self.client.login(username=self.user_1.username,
                          password=DEFAULT_PASSWORD)
Ejemplo n.º 3
0
class MasterAdminTestCase(FunctionalTestCase):
    def setUp(self):
        super(MasterAdminTestCase, self).setUp()
        self.master_admin = UserFactory(email='*****@*****.**',
                                        is_superuser=True,
                                        is_staff=True)
        self.master_admin.set_password('neptune123')
        self.master_admin.save()

    def log_in_master_admin(self):
        master_admin_session = SessionStore()
        master_admin_session[SESSION_KEY] = self.master_admin.pk
        master_admin_session[
            BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
        master_admin_session[
            HASH_SESSION_KEY] = self.master_admin.get_session_auth_hash()
        master_admin_session.save()

        self.visit('')
        self.browser.add_cookie({
            'name': settings.SESSION_COOKIE_NAME,
            'value': master_admin_session.session_key,
            'path': '/'
        })

    def wait_for_success_message(self, message):
        self.wait_for_element_contains_text('.messagelist .success', message)

    def wait_for_error_message(self, message=None):
        self.wait_for_element_contains_text(
            '.errornote', message or 'Please correct the errors below.')
Ejemplo n.º 4
0
 def setUp(self):
     self.group_admin = Group.objects.get(name=GROUP_NAME_ADMINS)
     self.group_moderator = Group.objects.get(name=GROUP_NAME_MODERATORS)
     self.user = UserFactory()
     self.user_admin = UserFactory()
     self.user_admin.groups.add(self.group_admin)
     self.user_moderator = UserFactory()
     self.user_moderator.groups.add(self.group_moderator)
     self.user_participant = UserFactory()
Ejemplo n.º 5
0
 def setUp(self):
     super(AccountsInlineAdminTestCase, self).setUp()
     self.log_in_master_admin()
     self.client = ClientFactory(name='NS Global')
     self.client2 = ClientFactory(name='NS Vietnam')
     self.role = RoleFactory(name='Physician')
     self.user1 = UserFactory(email='*****@*****.**')
     self.user2 = UserFactory(email='*****@*****.**')
     self.specialty_1, self.specialty_2 = SpecialtyFactory.create_batch(2)
Ejemplo n.º 6
0
 def setUp(self):
     super().setUp()
     self.client = ClientFactory(name='Central Dental Hospital')
     self.physician = AccountFactory(
         user=UserFactory(email='*****@*****.**'),
         client=self.client).user
     self.admin = AccountFactory(
         user=UserFactory(email='*****@*****.**'),
         client=self.client,
         role=RoleFactory(priority=RolePriority.ADMIN.value)).user
Ejemplo n.º 7
0
 def test_inactive_user(self):
     k1 = UserFactory(status=User.STATUS_AWAITING_ACTIVATION)
     k2 = UserFactory(status=User.STATUS_ARCHIVED)
     for user in (
             k1,
             k2,
     ):
         resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', {
             'username': user.username,
             'password': DEFAULT_PASSWORD
         },
                                 follow=True)
         self.assertContains(resp,
                             "Käyttäjätunnus ei ole aktiivinen.",
                             status_code=200)
Ejemplo n.º 8
0
    def test_create_user(self):
        users_exists = User.objects.filter().exists()
        self.assertFalse(users_exists)

        UserFactory()
        users_exists = User.objects.filter().exists()
        self.assertTrue(users_exists)
Ejemplo n.º 9
0
 def test_kirjaudu_ulos(self):
     user = UserFactory()
     self.client.login(username=user.username, password=DEFAULT_PASSWORD)
     resp = self.client.get('/fi/kayttaja/kirjaudu-ulos/',
                            follow=True,
                            target_status_code=200)
     self.assertContains(resp, 'Sinut on kirjattu ulos palvelusta')
Ejemplo n.º 10
0
 def setUp(self):
     stage = CareerStageFactory()
     user = UserFactory()
     profile = user.profile
     profile.career_stage = stage
     profile.save()
     self.user = user
Ejemplo n.º 11
0
    def setUp(self):
        # HACK: setup Organization.unmoderated_objects manager
        from libs.moderation.helpers import auto_discover
        auto_discover()

        self.user = UserFactory()
        self.client.login(username=self.user.username,
                          password=DEFAULT_PASSWORD)
Ejemplo n.º 12
0
 def test_organization_detail_org_admin(self):
     user = UserFactory()
     org = OrganizationFactory(admins=[user, ])
     self.client.login(username=user.username, password=DEFAULT_PASSWORD)
     resp = self.client.get(org.get_absolute_url())
     self.assertTemplateUsed(resp, 'organization/organization_detail.html')
     self.assertTemplateUsed(resp, 'organization/organization_detail_description.html')
     self.assertContains(resp, 'fa-edit', count=4)
Ejemplo n.º 13
0
    def test_unauthorized_redirect(self):
        user = UserFactory()
        self.client.login(username=user.username, password=DEFAULT_PASSWORD)
        resp = self.client.get("/fi/hallinta/kayttajat/", follow=True)

        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, 'Toiminto vaatii moderaattorin oikeudet')
        self.assertContains(resp, 'Kirjaudu sisään')
Ejemplo n.º 14
0
 def test_email_already_in_use(self):
     UserFactory(settings__email='*****@*****.**')
     resp = self.client.post('/fi/kayttaja/rekisteroidy/',
                             {'usersettings-email': '*****@*****.**'})
     self.assertEqual(resp.status_code, 200)
     self.assertTemplateUsed(resp, 'account/signup.html')
     self.assertTemplateNotUsed(resp, 'account/signup_activation.html')
     self.assertContains(resp, 'Sähköpostiosoite on jo käytössä.')
Ejemplo n.º 15
0
 def test_open_as_normal_user(self):
     user = UserFactory()
     self.client.login(username=user.username, password=DEFAULT_PASSWORD)
     resp = self.client.get(changelist_url, follow=True)
     self.assertRedirects(
         resp, "{}?next={}".format(login_url, changelist_url),
         status_code=302, target_status_code=200
     )
Ejemplo n.º 16
0
 def setUp(self):
     self.client = ClientFactory(name='PETCARE')
     self.physician_role = RoleFactory(
         name='Physician', priority=RolePriority.PHYSICIAN.value)
     self.admin_role = RoleFactory(name='Hospital Admin',
                                   priority=RolePriority.ADMIN.value)
     self.user = UserFactory(email='*****@*****.**',
                             name='Old Benny Name')
Ejemplo n.º 17
0
    def setUp(self):
        self.users = []
        for i in range(0, 55):
            self.users.append(UserFactory())

        group_admin = Group.objects.get(name=GROUP_NAME_ADMINS)
        self.users[0].groups.add(group_admin)
        self.client.login(username=self.users[0].username,
                          password=DEFAULT_PASSWORD)
Ejemplo n.º 18
0
 def setUp(self):
     self.user1 = UserSettingsFactory().user
     contact_user = UserSettingsFactory().user
     self.organization = OrganizationFactory(admins=[
         contact_user,
     ])
     self.contact_user = User.objects.get(pk=contact_user.pk)
     self.admin = UserFactory(
         groups=[Group.objects.get(name=GROUP_NAME_ADMINS)])
Ejemplo n.º 19
0
 def test_welcome_messages(self):
     user = UserFactory()
     resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', {
         'username': user.username,
         'password': DEFAULT_PASSWORD
     }, follow=True)
     self.assertRedirects(resp, '/fi/kayttaja/{}/'.format(user.pk),
                          target_status_code=200)
     self.assertNotContains(resp, 'Käytit palvelua viimeksi')
     self.assertContains(resp, 'Tervetuloa Nuortenideat.fi palveluun!')
     user.joined -= timedelta(seconds=5)
     user.save()
     resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', {
         'username': user.username,
         'password': DEFAULT_PASSWORD
     }, follow=True)
     self.assertContains(resp, 'Käytit palvelua viimeksi')
     self.assertNotContains(resp, 'Tervetuloa Nuortenideat.fi palveluun!')
Ejemplo n.º 20
0
    def admins(self, create, extracted, **kwargs):
        if not create:
            # Simple build, do nothing.
            return

        if extracted:
            for admin in extracted:
                self.admins.add(admin)
        else:
            self.admins.add(UserFactory())
Ejemplo n.º 21
0
 def setUp(self):
     self.user1 = UserSettingsFactory().user
     self.user2 = UserSettingsFactory().user
     self.admin = UserFactory(
         groups=[Group.objects.get(name=GROUP_NAME_ADMINS)])
     self.moderator = UserFactory(
         groups=[Group.objects.get(name=GROUP_NAME_MODERATORS)])
     self.idea1 = IdeaFactory(owners=[self.user1],
                              title="Public Initiative",
                              visibility=Idea.VISIBILITY_PUBLIC)
     IdeaFactory(owners=[self.user1, self.user2],
                 title="Shared Initiative",
                 visibility=Idea.VISIBILITY_DRAFT)
     IdeaFactory(owners=[self.user1],
                 title="Draft Initiative",
                 visibility=Idea.VISIBILITY_DRAFT)
     IdeaFactory(owners=[self.user2],
                 title="Non-Owned Initiative",
                 visibility=Idea.VISIBILITY_DRAFT)
Ejemplo n.º 22
0
 def test_active_user_login(self):
     user = UserFactory(username='******')
     resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', {
         'username': user.username,
         'password': DEFAULT_PASSWORD
     },
                             follow=True)
     self.assertRedirects(resp, '/fi/kayttaja/{}/'.format(user.pk))
     self.assertContains(resp, 'Tepotin')
     self.assertNotContains(resp, "Ei käyttöoikeutta")
Ejemplo n.º 23
0
 def test_broken_activation_link(self):
     user = UserFactory(is_active=False,
                        status=User.STATUS_AWAITING_ACTIVATION)
     token = EmailConfirmationForm.create_token(user)
     resp = self.client.get('/fi/kayttaja/vahvista-sahkoposti/%s/' %
                            token[1:])
     self.assertEqual(resp.status_code, 200)
     self.assertTemplateUsed(resp, 'account/email_confirmation_failed.html')
     self.assertContains(
         resp, 'Vahvistuslinkki on virheellinen tai vanhentunut.')
Ejemplo n.º 24
0
    def test_unauthorized_redirect(self):
        user_logged = UserFactory()
        self.client.login(username=user_logged.username,
                          password=DEFAULT_PASSWORD)
        resp = self.client.get("/fi/hallinta/kayttajat/%d/muokkaa/" %
                               self.target_user.pk,
                               follow=True)

        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, 'Ei käyttöoikeutta.')
        self.assertContains(resp, 'Kirjaudu sisään')
Ejemplo n.º 25
0
    def test_vahvista_sahkoposti(self):
        user = UserFactory(status=User.STATUS_AWAITING_ACTIVATION)
        self.assertEqual(len(mail.outbox), 0)
        self.assertFalse(user.is_active)
        token = EmailConfirmationForm.create_token(user)

        resp = self.client.get('/fi/kayttaja/vahvista-sahkoposti/%s/' % token)
        self.assertEqual(resp.status_code, 200)
        self.assertTemplateUsed(resp, 'account/email_confirmed.html')
        self.assertContains(resp, 'Sähköposti vahvistettu')
        self.assertEqual(len(mail.outbox), 0)
Ejemplo n.º 26
0
    def test_generate_username(self):
        """
        Tests that: * u"Valérian", "Saliou" == "valerian.saliou"
                    * "John", "Doe" == "john.doe"
                    * "Jane", "Moffit!?" == "jane.moffit"
                    * u"Καλημέρα", "Joe" == "kalhmera.joe"
        """

        from account.factories import UserFactory

        self.assertEqual(
            UserFactory.generate_username(
                first_name=u'Valérian',
                last_name='Saliou'
            ),
            'valerian.saliou'
        )

        self.assertEqual(
            UserFactory.generate_username(
                first_name='John',
                last_name='Doe'
            ),
            'john.doe'
        )

        self.assertEqual(
            UserFactory.generate_username(
                first_name='Jane',
                last_name='Moffit!?'
            ),
            'jane.moffit'
        )

        self.assertEqual(
            UserFactory.generate_username(
                first_name=u'Καλημέρα',
                last_name='Joe'
            ),
            'kalhmera.joe'
        )
Ejemplo n.º 27
0
 def test_welcome_messages(self):
     user = UserFactory()
     resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', {
         'username': user.username,
         'password': DEFAULT_PASSWORD
     },
                             follow=True)
     self.assertRedirects(resp,
                          '/fi/kayttaja/{}/'.format(user.pk),
                          target_status_code=200)
     self.assertNotContains(resp, 'Käytit palvelua viimeksi')
     self.assertContains(resp, 'Tervetuloa Nuortenideat.fi palveluun!')
     user.joined -= timedelta(seconds=5)
     user.save()
     resp = self.client.post('/fi/kayttaja/kirjaudu-sisaan/', {
         'username': user.username,
         'password': DEFAULT_PASSWORD
     },
                             follow=True)
     self.assertContains(resp, 'Käytit palvelua viimeksi')
     self.assertNotContains(resp, 'Tervetuloa Nuortenideat.fi palveluun!')
    def setUp(self):
        super().setUp()
        self.log_in_master_admin()
        self.visit_reverse('admin:tracker_repcase_add')
        self.wait_for_element_contains_text('#content h1', 'Add rep case')
        physician = RoleFactory(name='Physician',
                                priority=RolePriority.PHYSICIAN.value)
        admin = RoleFactory(name='Admin', priority=RolePriority.ADMIN.value)
        client = ClientFactory(name='NSINC')
        AccountFactory(user=UserFactory(email='*****@*****.**'),
                       role=physician,
                       client=client)
        AccountFactory(user=UserFactory(email='*****@*****.**'),
                       role=admin,
                       client=client)

        client = ClientFactory(name='EA')
        AccountFactory(user=UserFactory(email='*****@*****.**'),
                       role=admin,
                       client=client)

        ClientFactory(name='UVMC')
Ejemplo n.º 29
0
    def setUp(self):
        user = UserFactory(is_superuser=True, is_staff=True)
        self.client.login(username=user.username, password=DEFAULT_PASSWORD)
        self.test_files = {
            "large": os.path.join(
                os.path.dirname(os.path.dirname(__file__)),
                'nkpicturecarousel', 'testdata', "large.jpg"
            ),
            "medium": os.path.join(
                os.path.dirname(os.path.dirname(__file__)),
                'nkpicturecarousel', 'testdata', "medium.jpg"
            ),
            "small": os.path.join(
                os.path.dirname(os.path.dirname(__file__)),
                'nkpicturecarousel', 'testdata', "small.jpg"
            ),
            "large_less_height": os.path.join(
                os.path.dirname(os.path.dirname(__file__)),
                'nkpicturecarousel', 'testdata', "large_less_height.jpg"
            ),
            "large_less_width": os.path.join(
                os.path.dirname(os.path.dirname(__file__)),
                'nkpicturecarousel', 'testdata', "large_less_width.jpg"
            ),
        }
        self.data = {
            "name": "Carousel Pictures",
            "is_active": "on",

            "images-0-id": "",
            "images-0-carousel_set": None,
            "images-0-language": "fi",
            "images-0-image_large": open(self.test_files["large"], "rb"),
            "images-0-image_medium": open(self.test_files["medium"], "rb"),
            "images-0-image_small": open(self.test_files["small"], "rb"),
            "images-0-alt_text": "First picture alt",

            "images-1-id": "",
            "images-1-carousel_set": None,
            "images-1-language": "sv",
            "images-1-image_large": open(self.test_files["large"], "rb"),
            "images-1-image_medium": open(self.test_files["medium"], "rb"),
            "images-1-image_small": open(self.test_files["small"], "rb"),
            "images-1-alt_text": "Second picture alt",

            # Form metadata.
            "images-TOTAL_FORMS": 2,
            "images-INITIAL_FORMS": 0,
            "images-MIN_NUM_FORMS": 1,
            "images-MAX_NUM_FORMS": 2,
        }
Ejemplo n.º 30
0
    def test_logged_in(self):
        # Log in.
        user = UserFactory()
        self.client.login(username=user.username, password=DEFAULT_PASSWORD)

        # Check no votes are present and add a vote.
        self.assertEqual(self.idea.votes.count(), 0)
        resp = self.client.post("/fi/ideat/{0}/kannata/".format(self.idea.id),
                                follow=True,
                                **HEADERS)
        self.assertEqual(resp.status_code, 200)

        # Assert that one vote is present.
        self.assertEqual(self.idea.votes.count(), 1)
Ejemplo n.º 31
0
    def test_show_draft_as_admin(self):
        self.setUp_gallup()
        self.assertTrue(self.gallup.is_draft())

        admin = UserFactory(groups=[Group.objects.get(name=GROUP_NAME_ADMINS)])
        self.client.login(username=admin.username, password=DEFAULT_PASSWORD)
        resp = self.client.get("/fi/ideat/{}/".format(self.idea.pk))
        self.assertContains(resp, "Gallup on luonnos.")
        self.assertContains(resp, "Question #1")
        self.assertContains(resp, "Question #2")
        self.assertContains(resp, "Option #1")
        self.assertContains(resp, "Option #2")
        self.assertContains(resp, "Option #3")
        self.assertContains(resp, "Option #4")
Ejemplo n.º 32
0
    def test_show_draft_as_non_owner(self):
        self.setUp_gallup()
        self.assertTrue(self.gallup.is_draft())

        user = UserFactory()
        self.client.login(username=user.username, password=DEFAULT_PASSWORD)
        resp = self.client.get("/fi/ideat/{}/".format(self.idea.pk))
        self.assertNotContains(resp, "Gallup on luonnos.")
        self.assertNotContains(resp, "Question #1")
        self.assertNotContains(resp, "Question #2")
        self.assertNotContains(resp, "Option #1")
        self.assertNotContains(resp, "Option #2")
        self.assertNotContains(resp, "Option #3")
        self.assertNotContains(resp, "Option #4")