Ejemplo n.º 1
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.user = User.objects.create(username="******")
     self.client.force_login(self.user)
     self.rushee1 = Rushee.objects.create(name="first_rushee")
     self.rushee2 = Rushee.objects.create(name="second_rushee", cut=True)
     self.rushee3 = Rushee.objects.create(name="third_rushee")
Ejemplo n.º 2
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     u = User.objects.create(username="******",
                             is_staff=True,
                             is_superuser=True)
     self.client.force_login(u)
     a = Announcement.objects.create(user=u)
Ejemplo n.º 3
0
 def setUp(self):
     """TenantTestCase generates a tenant for tests.
     Each tenant should have a single SiteConfig object 
     that is created upon first access via the get() method.
     """
     self.config = SiteConfig.get()
     self.client = TenantClient(self.tenant)
Ejemplo n.º 4
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.admin = User.objects.create(username="******",
                                      is_superuser=True,
                                      is_staff=True)
     self.client.force_login(self.admin)
     self.roster = Roster.objects.create(title="test_roster")
    def test_bulk_delete_participation(self) -> None:
        self.set_tenant(0)

        user = self.users[0]
        first_contact = Contact.objects.create(email='*****@*****.**', first_name='First', last_name='Smith')
        second_contact = Contact.objects.create(email='*****@*****.**', first_name='Second', last_name='Smith')

        campaign = Campaign.objects.create(name='cool campaign', owner=user)

        Participation.objects.bulk_create([
            Participation(campaign=campaign, contact=first_contact),
            Participation(campaign=campaign, contact=second_contact),
        ])

        t_client = TenantClient(self.get_current_tenant())
        t_client.handler = ForceAuthClientHandler(enforce_csrf_checks=False)
        t_client.handler._force_user = user
        self.assertTrue(t_client.login(username=user.username, password='******'), 'Test user was not logged in')

        url = reverse.reverse('api:campaigns-contacts-list', args=[campaign.pk, ])
        with modify_settings(ALLOWED_HOSTS={'append': self.get_current_tenant().domain_url}):
            response = t_client.delete(urljoin(url, '?contact__in=%s' % str(first_contact.id)),
                                       content_type='application/json',
                                       )

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, str(response.content))
        participation = Participation.objects.get(campaign=campaign)
        self.assertEqual(second_contact, participation.contact)
    def test_email_stage_template_validation(self) -> None:
        self.set_tenant(0)

        user = self.users[0]

        campaign = Campaign.objects.create(name='some campaign', owner=user)
        step = Step.objects.create(campaign=campaign, start=datetime.time(9, 45), end=datetime.time(18, 30))

        t_client = TenantClient(self.get_current_tenant())
        t_client.handler = ForceAuthClientHandler(enforce_csrf_checks=False)
        t_client.handler._force_user = user
        self.assertTrue(t_client.login(username=user.username, password='******'), 'Test user was not logged in')

        url = reverse.reverse('api:campaigns-steps-email-list', args=[campaign.pk, step.pk, ])
        with modify_settings(ALLOWED_HOSTS={'append': self.get_current_tenant().domain_url}):
            response = t_client.post(url,
                                     json.dumps(dict(
                                         subject='Hello good fellow',
                                         html_content='Some invalid email template to {{First name}}!',
                                     )),
                                     content_type='application/json',
                                     )

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, str(response.content))
        error_data = response.data
        self.assertTrue("Could not parse" in error_data['html_content'][0])
Ejemplo n.º 7
0
class SiteConfigModelTest(ViewTestUtilsMixin, TenantTestCase):
    """Tests for the SiteConfig model
    """
    def setUp(self):
        """TenantTestCase generates a tenant for tests.
        Each tenant should have a single SiteConfig object 
        that is created upon first access via the get() method.
        """
        self.config = SiteConfig.get()
        self.client = TenantClient(self.tenant)

    def test_SiteConfigUpdateOwn(self):
        """ SiteConfigUpdateOwn is an update view that sets the object to 
        this tenants SiteConfig singleton
        """

        # requires staff member
        self.assertRedirectsAdmin('config:site_config_update_own')

        self.client.force_login(
            User.objects.create_user(username='******', is_staff=True))
        self.assert200('config:site_config_update_own')

    def test_SiteConfigUpdate(self):
        # requires staff member
        self.assertRedirectsAdmin('config:site_config_update',
                                  args=[self.config.get().id])

        self.client.force_login(
            User.objects.create_user(username='******', is_staff=True))
        self.assert200('config:site_config_update',
                       args=[self.config.get().id])
    def test_bulk_post_participation(self) -> None:
        self.set_tenant(0)

        user = self.users[0]
        first_contact = Contact.objects.create(email='*****@*****.**', first_name='First', last_name='Smith')
        second_contact = Contact.objects.create(email='*****@*****.**', first_name='Second', last_name='Smith')

        campaign = Campaign.objects.create(name='cool campaign', owner=user)

        t_client = TenantClient(self.get_current_tenant())
        t_client.handler = ForceAuthClientHandler(enforce_csrf_checks=False)
        t_client.handler._force_user = user
        self.assertTrue(t_client.login(username=user.username, password='******'), 'Test user was not logged in')

        url = reverse.reverse('api:campaigns-contacts-list', args=[campaign.pk, ])
        with modify_settings(ALLOWED_HOSTS={'append': self.get_current_tenant().domain_url}):
            response = t_client.post(url,
                                     json.dumps([
                                         dict(contact=first_contact.id),
                                         dict(contact=second_contact.id),
                                     ]),
                                     content_type='application/json',
                                     )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED, str(response.content))
        self.assertEqual(2, Participation.objects.filter(
            campaign=campaign,
            contact_id__in=(first_contact.id, second_contact.id,),
        ).count())
        contacts = campaign.contacts.all()
        self.assertListEqual([first_contact, second_contact, ], list(contacts))
Ejemplo n.º 9
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.admin = User.objects.create(username="******",
                                      is_staff=True,
                                      is_superuser=True)
     self.client.force_login(self.admin)
     self.event = SocialEvent.objects.create()
Ejemplo n.º 10
0
class QuestionDetailViewTests(TenantTestCase):
    def setUp(self):
        self.client = TenantClient(self.tenant)

    def test_future_question(self):
        """
        The detail view of a question with a pub_date in the future
        returns a 404 not found.
        """
        future_question = create_question(question_text='Future question.',
                                          days=5)
        url = reverse('detail', args=(future_question.id, ))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)

    def test_past_question(self):
        """
        The detail view of a question with a pub_date in the past
        displays the question's text.
        """
        past_question = create_question(question_text='Past Question.',
                                        days=-5)
        url = reverse('detail', args=(past_question.id, ))
        print(url)
        response = self.client.get(url)
        self.assertContains(response, past_question.question_text)
Ejemplo n.º 11
0
class IndexTestCase(TenantTestCase):
    """ tests the index page of the recruitment tab """
    def setUp(self):
        self.client = TenantClient(self.tenant)
        self.u = User.objects.create(username="******")
        self.client.force_login(self.u)
        self.event1 = RushEvent.objects.create(name='test_event1',
                                               date='2001-01-01',
                                               time='00:00:00',
                                               round=1,
                                               new_rushees_allowed=True)
        self.event2 = RushEvent.objects.create(name='test_event2',
                                               date='2001-01-01',
                                               time='00:00:00',
                                               round=3,
                                               new_rushees_allowed=True)

    def test_index_health(self):
        path = reverse('rush:index')
        response = self.client.get(path)
        self.assertEqual(response.status_code, 200)

    def test_index_round_groups(self):
        path = reverse('rush:index')
        response = self.client.get(path)
        self.assertContains(response, "<h4>Round 1</h4>")
        self.assertContains(response, "<h4>Round 3</h4>")
Ejemplo n.º 12
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     User = get_user_model()
     self.semester = baker.make(Semester)
     self.teacher = Recipe(User, is_staff=True).make(
     )  # need a teacher or student creation will fail.
     self.student = baker.make(User)
     self.submission = baker.make(QuestSubmission, quest__name="Test")
Ejemplo n.º 13
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.rushee = Rushee.objects.create(name="test_rushee",
                                         voting_open=True)
     self.user = User.objects.create(username="******",
                                     is_staff=True,
                                     is_superuser=True)
     self.client.force_login(self.user)
Ejemplo n.º 14
0
class CurrentRusheesTestCase(TenantTestCase):
    """ tests for the current rushees page """
    def setUp(self):
        self.client = TenantClient(self.tenant)
        self.user = User.objects.create(username="******")
        self.client.force_login(self.user)
        self.rushee1 = Rushee.objects.create(name="first_rushee")
        self.rushee2 = Rushee.objects.create(name="second_rushee", cut=True)
        self.rushee3 = Rushee.objects.create(name="third_rushee")

    def test_current_rushees_template(self):
        """ tests that current rushees page displays with all rushees """
        path = reverse('rush:current_rushees')
        response = self.client.post(path)
        self.assertContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee1.pk))
        self.assertNotContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee2.pk))
        self.assertContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee3.pk))

    def test_current_rushees_with_filter(self):
        """ tests current rushees page with filter set """
        session = self.client.session
        session['rushee_filter'] = dict(name='first')
        session.save()
        path = reverse('rush:current_rushees')
        response = self.client.post(path)
        self.assertContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee1.pk))
        self.assertNotContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee2.pk))
        self.assertNotContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee3.pk))

    def test_current_rushees_with_cut(self):
        """ tests current rushees with cut filter set """
        session = self.client.session
        session['rushee_filter'] = dict(cut=True)
        session.save()
        path = reverse('rush:current_rushees')
        response = self.client.post(path)
        self.assertContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee1.pk))
        self.assertContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee2.pk))
        self.assertContains(
            response,
            "<tr onclick=\"window.location='rushee" + str(self.rushee3.pk))
Ejemplo n.º 15
0
    def setUp(self):
        self.client = TenantClient(self.tenant)

        # need a teacher and a student with known password so tests can log in as each, or could use force_login()?
        self.test_password = "******"

        # need a teacher before students can be created or the profile creation will fail when trying to notify
        self.test_teacher = User.objects.create_user('test_teacher', password=self.test_password, is_staff=True)
        self.test_student1 = User.objects.create_user('test_student', password=self.test_password)
        self.test_student2 = baker.make(User)
Ejemplo n.º 16
0
    def setUp(self):
        self.client = TenantClient(self.tenant)

        self.user = mommy.make('auth.User', email='*****@*****.**')
        self.user.set_password('123456')
        self.user.save()

        self.client.post(reverse_lazy('tenant:login'), {'email': self.user.email, 'password': '******'})

        mommy.make('provarme_dashboard.Setup', tx_shopify=1, tx_gateway=1, tx_antecipation=1, tx_tax=1, tx_iof=1,
                   tx_cashback=1,)
Ejemplo n.º 17
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.form_data = {
         'username': '******',
         'email': '*****@*****.**',
         'first_name': 'Test_first',
         'last_name': 'Test_last',
         'verification_key': '9999',
         'password1': 'c0mpl#x_p@$$w0rd',
         'password2': 'c0mpl#x_p@$$w0rd'
     }
Ejemplo n.º 18
0
class QuestionIndexViewTests(TenantTestCase):
    def setUp(self):
        self.client = TenantClient(self.tenant)

    def test_no_questions(self):
        """
        If no questions exist, an appropriate message is displayed.
        """
        response = self.client.get(reverse('index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No polls are available.")
        self.assertQuerysetEqual(response.context['latest_question_list'], [])

    def test_past_question(self):
        """
        Questions with a pub_date in the past are displayed on the
        index page.
        """
        create_question(question_text="Past question.", days=-30)
        response = self.client.get(reverse('index'))
        self.assertQuerysetEqual(response.context['latest_question_list'],
                                 ['<Question: Past question.>'])

    def test_future_question(self):
        """
        Questions with a pub_date in the future aren't displayed on
        the index page.
        """
        create_question(question_text="Future question.", days=30)
        response = self.client.get(reverse('index'))
        self.assertContains(response, "No polls are available.")
        self.assertQuerysetEqual(response.context['latest_question_list'], [])

    def test_future_question_and_past_question(self):
        """
        Even if both past and future questions exist, only past questions
        are displayed.
        """
        create_question(question_text="Past question.", days=-30)
        create_question(question_text="Future question.", days=30)
        response = self.client.get(reverse('index'))
        self.assertQuerysetEqual(response.context['latest_question_list'],
                                 ['<Question: Past question.>'])

    def test_two_past_questions(self):
        """
        The questions index page may display multiple questions.
        """
        create_question(question_text="Past question 1.", days=-30)
        create_question(question_text="Past question 2.", days=-5)
        response = self.client.get(reverse('index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question 2.>', '<Question: Past question 1.>'])
Ejemplo n.º 19
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.admin = User.objects.create(username="******",
                                      is_staff=True,
                                      is_superuser=True)
     self.client.force_login(self.admin)
     self.event = SocialEvent.objects.create()
     self.attendees = []
     for i in range(1, 4):
         a = Attendee.objects.create(name="attendee" + str(i),
                                     user=self.admin,
                                     event=self.event)
         self.attendees.append(a)
     self.event.save()
Ejemplo n.º 20
0
class AuthenticationTestCase(TenantTestCase):
    def setUp(self):
        self.client = TenantClient(self.tenant)
        self.u = User.objects.create(username="******", is_superuser=True)
        self.client.force_login(self.u)

    # tests that logged in user can logout
    def test_logout_redirects_to_login(self):
        path = reverse('logout')
        response = self.client.post(path, follow=True)
        self.assertContains(response, 'Login')

    # gets template with signup form
    def test_signup_get_template(self):
        path = reverse('signup')
        response = self.client.get(path)
        self.assertContains(response, "Register")

    # tests that inactive users can activate with activate view
    def test_activate_view(self):
        user = User.objects.create(username="******", is_active="False")
        token = account_activation_token.make_token(user)
        path = reverse('activate', kwargs=dict(user_id=user.pk, token=token))
        response = self.client.post(path)
        self.assertContains(response, "Your account has been verified!")

    # tests user that does not exist
    def test_activate_user_does_not_exist(self):
        user = User.objects.create(username="******", is_active="False")
        token = account_activation_token.make_token(user)
        path = reverse('activate', kwargs=dict(user_id=user.pk, token=token))
        user.delete()
        response = self.client.post(path)
        self.assertContains(response, "Activation link is invalid")

    # tests invalid activation token
    def test_activate_user_invalid_token(self):
        user = User.objects.create(username="******", is_active="False")
        token = "999-99999999999999999999"
        path = reverse('activate', kwargs=dict(user_id=user.pk, token=token))
        response = self.client.post(path)
        self.assertContains(response, "Activation link is invalid")

    # tests logout
    def test_logout(self):
        user = User.objects.create(username="******")
        self.client.force_login(user)
        path = reverse('logout')
        response = self.client.post(path, follow=True)
        self.assertContains(response, "Login")
Ejemplo n.º 21
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.u = User.objects.create(username="******")
     self.client.force_login(self.u)
     self.event1 = RushEvent.objects.create(name='test_event1',
                                            date='2001-01-01',
                                            time='00:00:00',
                                            round=1,
                                            new_rushees_allowed=True)
     self.event2 = RushEvent.objects.create(name='test_event2',
                                            date='2001-01-01',
                                            time='00:00:00',
                                            round=3,
                                            new_rushees_allowed=True)
Ejemplo n.º 22
0
    def setUp(self):
        self.client = TenantClient(self.tenant)
        self.sem = SiteConfig.get().active_semester

        self.teacher = Recipe(User, is_staff=True).make(
        )  # need a teacher or student creation will fail.
        self.student = baker.make(User)
        self.assertion = baker.make(BadgeAssertion, semester=self.sem)
        self.badge = Recipe(Badge, xp=20).make()

        self.badge_assertion_recipe = Recipe(BadgeAssertion,
                                             user=self.student,
                                             badge=self.badge,
                                             semester=self.sem)
Ejemplo n.º 23
0
    def setUp(self):
        self.client = TenantClient(self.tenant)
        User = get_user_model()
        self.sem = SiteConfig.get().active_semester

        # need a teacher and a student with known password so tests can log in as each, or could use force_login()?
        self.test_password = "******"

        # need a teacher before students can be created or the profile creation will fail when trying to notify
        self.test_teacher = User.objects.create_user('test_teacher', password=self.test_password, is_staff=True)
        self.test_student1 = User.objects.create_user('test_student', password=self.test_password)
        self.test_student2 = mommy.make(User)

        self.quest1 = mommy.make(Quest)
        self.quest2 = mommy.make(Quest)
Ejemplo n.º 24
0
    def setUp(self):
        self.client = TenantClient(self.tenant)
        self.sem = SiteConfig.get().active_semester

        self.teacher = Recipe(User, is_staff=True).make(
        )  # need a teacher or student creation will fail.
        self.student = baker.make(User)
Ejemplo n.º 25
0
    def setUp(self):
        self.client = TenantClient(self.tenant)
        User = get_user_model()

        # need a teacher and a student with known password so tests can log in as each, or could use force_login()?
        self.test_password = "******"

        # need a teacher before students can be created or the profile creation will fail when trying to notify
        self.test_teacher = User.objects.create_user(
            'test_teacher', password=self.test_password, is_staff=True)
        self.test_student1 = User.objects.create_user(
            'test_student', password=self.test_password)
        self.test_student2 = baker.make(User)

        # create semester with pk of default semester
        # this seems backward, but no semesters should exist yet in the test, so their shouldn't be any conflicts.
        self.active_sem = SiteConfig.get().active_semester
class TestMultiTenantSocialAuth(TenantTestCase):

    @classmethod
    def setUpClass(cls):
        settings.AUTHENTICATION_BACKENDS = ('social_core.backends.twitter.TwitterOAuth',
                                            'django.contrib.auth.backends.ModelBackend',)
        cls.sync_shared()
        tenant_domain = 'tenant.test.com'
        invalid_tenant_domain = 'invalid_tenant.test.com'

        cls.social_auth_settings = {
            'twitter': {
                'SOCIAL_AUTH_TWITTER_KEY': 'TtfLziJDLaNc0bRwCCYCxpMIc',
                'SOCIAL_AUTH_TWITTER_SECRET': 'AXgPEFhJNHtbhBycoKn9KfMtsINOAOHsQ4o2wSJmzG0XCMeVbr'
            }
        }
        cls.tenant = get_tenant_model()(domain_url=tenant_domain,
                                        schema_name='test', social_auth_settings=cls.social_auth_settings)

        cls.tenant.save(verbosity=0)

        cls.invalid_tenant = get_tenant_model()(domain_url=invalid_tenant_domain,
                                                schema_name='invalid_test', social_auth_settings={})
        cls.invalid_tenant.save(verbosity=0)

        connection.set_tenant(cls.tenant)

    def setUp(self):
        self.c = TenantClient(self.tenant)
        self.invalid_c = TenantClient(self.invalid_tenant)

    def test_tenant_social_auth_settings(self):
        self.assertEqual(self.tenant.social_auth_settings,
                         self.social_auth_settings)

    def test_user_login(self):
        response = self.c.get(
            reverse('social:begin', args=['twitter']))
        self.assertIn('auth_token=', response['Location'])

    def test_invalid_user_login(self):
        connection.set_tenant(self.invalid_tenant)
        response = self.invalid_c.get(
            reverse('social:begin', args=['twitter']))

        self.assertEqual(400, response.status_code)
Ejemplo n.º 27
0
    def test_initial_map_generated_on_first_view(self):
        # shouldn't be any maps from the start
        self.assertFalse(CytoScape.objects.exists())

        # log in anoyone
        self.client = TenantClient(self.tenant)
        anyone = User.objects.create_user('anyone', password="******")
        success = self.client.login(username=anyone.username,
                                    password="******")
        self.assertTrue(success)

        # Access the primary map view
        self.assert200('djcytoscape:primary')

        # Should have generated the "Main" map
        self.assertEqual(CytoScape.objects.count(), 1)
        self.assertTrue(CytoScape.objects.filter(name="Main").exists())
Ejemplo n.º 28
0
class TestLocationAutocompleteView(BaseTenantTestCase):
    def setUp(self):
        super(TestLocationAutocompleteView, self).setUp()
        self.unicef_staff = UserFactory(is_staff=True)
        self.client = TenantClient(self.tenant)

    def test_non_auth(self):
        LocationFactory()
        response = self.client.get(reverse("locations-autocomplete-light"))
        self.assertEqual(response.status_code, status.HTTP_302_FOUND)

    def test_get(self):
        LocationFactory()
        self.client.force_login(self.unicef_staff)
        response = self.client.get(reverse("locations-autocomplete-light"))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        data = response.json()
        self.assertEqual(len(data["results"]), 1)

    def test_get_filter(self):
        LocationFactory(name="Test")
        LocationFactory(name="Other")
        self.client.force_login(self.unicef_staff)
        response = self.client.get("{}?q=te".format(
            reverse("locations-autocomplete-light")))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        data = response.json()
        self.assertEqual(len(data["results"]), 1)
Ejemplo n.º 29
0
 def test_sign_up_via_post(self):
     self.client = TenantClient(self.tenant)
     form_data = {
         'username': "******",
         'first_name': "firsttest",
         'last_name': "Lasttest",
         'access_code': "314159",
         'password1': "password",
         'password2': "password"
     }
     response = self.client.post(
         reverse('account_signup'),
         form_data,
         follow=True,
     )
     self.assertRedirects(response, reverse('quests:quests'))
     user = User.objects.get(username="******")
     self.assertEqual(user.first_name, "firsttest")
Ejemplo n.º 30
0
 def setUp(self):
     self.client = TenantClient(self.tenant)
     self.admin = User.objects.create(username="******",
                                      is_staff=True,
                                      is_superuser=True)
     self.client.force_login(self.admin)
     file = SimpleUploadedFile("file.txt",
                               b"file_content",
                               content_type="text/plain")
     for i in range(0, 10):
         SocialEvent.objects.create(name="test_event_" + str(i))
         ResourceLink.objects.create(name="test_link_" + str(i),
                                     description="test",
                                     url="https://www.google.com")
         Announcement.objects.create(title="announcement_" + str(i))
         ResourceFile.objects.create(name="test_file_" + str(i),
                                     file=file,
                                     description="test")