def setUpTestData(cls):
     cls.survey = SurveyFactory.create()
     cls.question = SurveyQuestionFactory.create(survey=cls.survey, level=1)
     cls.empty_survey = SurveyFactory.create()
     cls.grantee = UserFactory.create()
     cls.grantor = UserFactory.create()
     cls.other = UserFactory.create()
Exemplo n.º 2
0
 def setUp(self):
     candidate = CANDIDATE_CLINTON
     self.state_safe = StateFactory.create(
         safe_for=candidate,
         safe_rank=1
     )
     self.user = UserFactory.create(
         profile__state=self.state_safe.name,
         profile__preferred_candidate=candidate)
     self.state_swing = StateFactory.create(
         tipping_point_rank=1)
     self.friend = UserFactory.create(
         profile__state=self.state_swing.name,
         profile__preferred_candidate=CANDIDATE_STEIN)
     self.user.profile.friends.add(self.friend.profile)
     self.foaf = UserFactory.create(
         profile__state=self.state_swing.name,
         profile__preferred_candidate=CANDIDATE_JOHNSON)
     self.friend.profile.friends.add(self.foaf.profile)
     self.friend_proposal = PairProposal.objects.create(
         from_profile=self.user.profile,
         to_profile=self.friend.profile)
     self.foaf_proposal = PairProposal.objects.create(
         from_profile=self.foaf.profile,
         to_profile=self.user.profile)
Exemplo n.º 3
0
 def setUp(self):
     super(_TestSafeStateMatchBase, self).setUp()
     candidate = CANDIDATE_CLINTON
     self.state_safe = StateFactory.create(
         safe_for=candidate,
         safe_rank=1
     )
     self.user = UserFactory.create(
         profile__state=self.state_safe.name,
         profile__preferred_candidate=candidate)
     # Create friends in safe states
     for i in range(10):
         state = StateFactory.create(
             safe_for=self.user.profile.preferred_candidate,
             safe_rank=i+2)  # +2 because state_safe is rank 1
         friend = UserFactory.create(profile__state=state.name)
         self.user.profile.friends.add(friend.profile)
     # Create friends in swing states
     self.swing_state_1 = StateFactory.create(tipping_point_rank=1)
     swing_user_1 = UserFactory.create(
         profile__state=self.swing_state_1.name,
         profile__preferred_candidate=CANDIDATE_JOHNSON)
     self.user.profile.friends.add(swing_user_1.profile)
     self.swing_state_2 = StateFactory.create(tipping_point_rank=2)
     swing_user_2 = UserFactory.create(
         profile__state=self.swing_state_2.name,
         profile__preferred_candidate=CANDIDATE_STEIN)
     self.user.profile.friends.add(swing_user_2.profile)
     self.swing_state_3 = StateFactory.create(tipping_point_rank=3)
     swing_user_3 = UserFactory.create(
         profile__state=self.swing_state_3.name,
         profile__preferred_candidate=candidate)
     self.user.profile.friends.add(swing_user_3.profile)
     # The ordering of expected_matches matters, it's ordered by state rank
     self.expected_matches = [swing_user_1.profile, swing_user_2.profile]
Exemplo n.º 4
0
    def setUp(self):
        self.user1 = UserFactory.create(username='******')
        self.user2 = UserFactory.create(username='******')

        self.activity = ActivityFactory.create(max_speed=10,
                                               user=self.user1)
        ActivityFactory.create(max_speed=5, user=self.user1)
        ActivityFactory.create(max_speed=7, user=self.user2)
Exemplo n.º 5
0
    def test_it_works(self, settings):
        configure_airtable_settings(settings)

        UserFactory.create()
        io = StringIO()
        with patch('airtable.management.commands.syncairtable.Airtable') as m:
            m.return_value = FakeAirtable()
            call_command('syncairtable', stdout=io)
        assert io.getvalue().split('\n') == [
            'Retrieving current Airtable...',
            'boop does not exist in Airtable, adding them.',
            'Finished synchronizing with Airtable!',
            ''
        ]
Exemplo n.º 6
0
 def setUp(self):
     super(TestConfirmSwapView, self).setUp()
     self.request = RequestFactory()
     from_state = StateFactory.create(tipping_point_rank=1)
     self.from_profile = UserFactory.create(
         profile__state=from_state.name).profile
     to_state = StateFactory.create(safe_rank=1)
     self.to_profile = UserFactory.create(
         profile__state=to_state.name).profile
     self.other_profile = ProfileFactory.create()
     self.from_profile.friends.add(self.to_profile)
     self.from_profile.friends.add(self.other_profile)
     self.proposal = PairProposal.objects.create(
         from_profile=self.from_profile, to_profile=self.to_profile)
Exemplo n.º 7
0
    def test_allow_random(self):
        user = UserFactory.create(profile=None)
        data = self._data(allow_random=1)
        form = LandingPageForm(data=data)
        self.assertTrue(form.is_valid())
        form.save(user)
        self.assertEqual(user.profile.allow_random, True)

        user = UserFactory.create(profile=None)
        data = self._data(allow_random=True)
        form = LandingPageForm(data=data)
        self.assertTrue(form.is_valid())
        form.save(user)
        self.assertEqual(user.profile.allow_random, True)
Exemplo n.º 8
0
 def setUp(self):
     super(_TestSafeStateFriendsOfFriendsMatchBase, self).setUp()
     candidate = CANDIDATE_CLINTON
     self.state_safe = StateFactory.create(
         safe_for=candidate,
         safe_rank=1
     )
     self.user = UserFactory.create(
         profile__state=self.state_safe.name,
         profile__preferred_candidate=candidate)
     tipping_point_rank = 1
     self.foaf_expected_matches = []
     # Create friends that haven't specified a vote choice just for links
     for i in range(2):
         friend_profile = ProfileFactory.create(state='')
         self.user.profile.friends.add(friend_profile)
         # And create friends of these friends in swing states
         for i in range(2):
             state = StateFactory.create(
                 tipping_point_rank=tipping_point_rank)
             foaf = UserFactory.create(
                 profile__state=state.name,
                 profile__preferred_candidate=CANDIDATE_STEIN)
             tipping_point_rank += 1
             friend_profile.friends.add(foaf.profile)
             self.foaf_expected_matches.append(foaf.profile)
     # And make another foaf that's friends with both of my friends
     state = StateFactory.create(
         tipping_point_rank=tipping_point_rank)
     self.foafoaf = UserFactory.create(
         profile__state=state.name,
         profile__preferred_candidate=CANDIDATE_JOHNSON)
     for friend in self.user.profile.friends.all():
         friend.friends.add(self.foafoaf.profile)
     self.foaf_expected_matches.append(self.foafoaf.profile)
     tipping_point_rank += 1
     self.direct_expected_matches = []
     # Create friends in swing states
     for i in range(2):
         state = StateFactory.create(
             tipping_point_rank=tipping_point_rank)
         friend = UserFactory.create(
             profile__state=state.name,
             profile__preferred_candidate=CANDIDATE_JOHNSON)
         tipping_point_rank += 1
         self.user.profile.friends.add(friend.profile)
         self.direct_expected_matches.append(friend.profile)
     # Direct friends are always preferred, so prepend them to expected
     self.expected_matches = (
         self.direct_expected_matches + self.foaf_expected_matches)
Exemplo n.º 9
0
 def test_dont_delete_profile(self):
     """From a bug where the user's profile was deleted after updating."""
     user = UserFactory.create(profile__fb_id=1, social_auth__uid=1)
     profile = user.profile
     # Add a friend
     friend = UserFactory.create(profile__fb_id=2, social_auth__uid=2)
     profile.friends.add(friend.profile)
     data = self._data()
     form = LandingPageForm(data=data)
     self.assertTrue(form.is_valid())
     form.save(user)
     user = get_user_model().objects.get(id=user.id)
     self.assertEqual(user.profile.id, profile.id)
     self.assertEqual(profile.friends.get(), friend.profile)
Exemplo n.º 10
0
 def setUp(self):
     super(TestAllowRandomSwingState, self).setUp()
     # Add some allow_random_users
     random_user_1 = UserFactory.create(
         profile__state=self.safe_states[0].name,
         profile__preferred_candidate=CANDIDATE_CLINTON,
         profile__allow_random=True)
     random_user_2 = UserFactory.create(
         profile__state=self.safe_states[1].name,
         profile__preferred_candidate=CANDIDATE_CLINTON,
         profile__allow_random=True)
     self.expected_no_random = self.expected_matches
     self.expected_with_random = self.expected_matches + [
         random_user_1.profile, random_user_2.profile]
Exemplo n.º 11
0
 def setUp(self):
     super(TestEmailBase, self).setUp()
     self.from_state = StateFactory.create(tipping_point_rank=1)
     self.from_user = UserFactory.create(
         profile__state=self.from_state.name,
         profile__preferred_candidate=CANDIDATE_JOHNSON)
     self.to_state = StateFactory.create(safe_rank=1)
     self.to_user = UserFactory.create(
         profile__state=self.to_state.name,
         profile__preferred_candidate=CANDIDATE_CLINTON)
     self.proposal = PairProposal.objects.create(
         from_profile=self.from_user.profile,
         to_profile=self.to_user.profile,
         date_rejected=timezone.now())
Exemplo n.º 12
0
    def test_it_works(self, settings):
        configure_airtable_settings(settings)

        UserFactory.create()
        io = StringIO()
        with patch("airtable.management.commands.syncairtable.Airtable") as m:
            m.return_value = FakeAirtable()
            call_command("syncairtable", stdout=io)
        assert io.getvalue().split("\n") == [
            "Retrieving current Airtable...",
            "Synchronizing users...",
            "boop does not exist in Airtable, adding them.",
            "Finished synchronizing with Airtable!",
            "",
        ]
Exemplo n.º 13
0
    def test_books_list_logged(self):
        user1 = UserFactory.create()
        user2 = UserFactory.create()

        book1 = BookFactory.create(owner=user1)
        book2 = BookFactory.create(owner=user1)
        book3 = BookFactory.create(owner=user2)

        with self.login(user1):
            response = self.client.get('/books/my/')

            self.assertEqual(response.status_code, 200)
            self.assertContains(response, book1.title)
            self.assertContains(response, book2.title)
            self.assertNotContains(response, book3.title)
Exemplo n.º 14
0
 def setUp(self):
     super(_TestSwingStateMatchBase, self).setUp()
     candidate = CANDIDATE_JOHNSON
     self.state_safe = StateFactory.create(
         tipping_point_rank=1,
     )
     self.user = UserFactory.create(
         profile__state=self.state_safe.name,
         profile__preferred_candidate=candidate,
     )
     # Make two friends for each candidate in a safe state for each
     # The ordering of expected matches is by state safe_rank
     self.expected_matches = []
     safe_rank = 1
     self.safe_states = []
     for (preferred_candidate, safe_for) in [
             (CANDIDATE_CLINTON, CANDIDATE_CLINTON),
             (CANDIDATE_TRUMP, CANDIDATE_CLINTON),
             (CANDIDATE_CLINTON, CANDIDATE_TRUMP),
             (CANDIDATE_TRUMP, CANDIDATE_TRUMP)]:
         for i in range(2):
             state = StateFactory.create(
                 safe_for=safe_for,
                 safe_rank=safe_rank)
             self.safe_states.append(state)
             friend = UserFactory.create(
                 profile__state=state.name,
                 profile__preferred_candidate=preferred_candidate)
             self.user.profile.friends.add(friend.profile)
             if preferred_candidate == CANDIDATE_CLINTON:
                 self.expected_matches.append(friend.profile)
             safe_rank += 1
     # Create friends in swing states
     swing_state_1 = StateFactory.create(tipping_point_rank=2)
     swing_user_1 = UserFactory.create(
         profile__state=swing_state_1.name,
         profile__preferred_candidate=CANDIDATE_JOHNSON)
     self.user.profile.friends.add(swing_user_1.profile)
     swing_state_2 = StateFactory.create(tipping_point_rank=3)
     swing_user_2 = UserFactory.create(
         profile__state=swing_state_2.name,
         profile__preferred_candidate=CANDIDATE_STEIN)
     self.user.profile.friends.add(swing_user_2.profile)
     swing_state_3 = StateFactory.create(tipping_point_rank=4)
     swing_user_3 = UserFactory.create(
         profile__state=swing_state_3.name,
         profile__preferred_candidate=candidate)
     self.user.profile.friends.add(swing_user_3.profile)
Exemplo n.º 15
0
 def test_it_errors_if_hpaction_is_disabled(self, graphql_client):
     user = UserFactory.create()
     graphql_client.request.user = user
     result = execute_genpdf_mutation(graphql_client)
     assert result["errors"] == []
     assert get_upload_status_for_user(user,
                                       NORMAL) == HPUploadStatus.ERRORED
Exemplo n.º 16
0
 def _test_valid(self, candidate):
     user = UserFactory.create(profile=None)
     data = self._data(preferred_candidate=candidate)
     form = LandingPageForm(data=data)
     self.assertTrue(form.is_valid())
     form.save(user)
     self.assertEqual(user.profile.preferred_candidate, candidate)
Exemplo n.º 17
0
    def test_subscriber_sms_is_older(self):
        subscriber = SubscriberSMSFactory.create(phone='123123123',
                                                 gdpr_consent=True)
        user = UserFactory.create(phone=subscriber.phone)

        call_command('update_gdpr_consent')
        assert User.objects.get(pk=user.pk).gdpr_consent is False
Exemplo n.º 18
0
    def test_subscriber_is_newest(self):
        user = UserFactory.create()
        SubscriberFactory.create(email=user.email, gdpr_consent=True)

        call_command('update_gdpr_consent')

        assert User.objects.get(pk=user.pk).gdpr_consent is True
Exemplo n.º 19
0
    def test_it_works(self):
        self.graphql_client.request.user = UserFactory.create()

        result = self.execute({
            'area':
            'HOME',
            'issues': ['HOME__RATS'],
            'customIssues': [{
                'description': 'boop',
                'DELETE': False,
            }],
        })
        assert result['errors'] == []
        assert result['session']['issues'] == ['HOME__RATS']
        ci = result['session']['customIssuesV2']
        ci_id = ci[0].pop('id')
        assert ci == [{'area': 'HOME', 'description': 'boop'}]

        result = self.execute({
            'area':
            'HOME',
            'issues': [],
            'customIssues': [{
                'description': 'boop',
                'DELETE': True,
                'id': ci_id,
            }]
        })
        assert result['errors'] == []
        assert result['session']['issues'] == []
        assert result['session']['customIssuesV2'] == []
Exemplo n.º 20
0
 def setUp(self):
     super().setUp()
     self.organisation = OrganisationFactory.create()
     self.user = UserFactory.create(organisation=self.organisation)
     self.order = OrderFactory.create(organisation=self.organisation,
                                      status=Order.STATUS_APPROVED)
     assign_role(self.user, 'admin')
Exemplo n.º 21
0
    def test_it_works(self):
        self.graphql_client.request.user = UserFactory.create()

        result = self.execute({
            "area":
            "HOME",
            "issues": ["HOME__RATS"],
            "customIssues": [{
                "description": "boop",
                "DELETE": False,
            }],
        })
        assert result["errors"] == []
        assert result["session"]["issues"] == ["HOME__RATS"]
        ci = result["session"]["customIssuesV2"]
        ci_id = ci[0].pop("id")
        assert ci == [{"area": "HOME", "description": "boop"}]

        result = self.execute({
            "area":
            "HOME",
            "issues": [],
            "customIssues": [{
                "description": "boop",
                "DELETE": True,
                "id": ci_id,
            }],
        })
        assert result["errors"] == []
        assert result["session"]["issues"] == []
        assert result["session"]["customIssuesV2"] == []
 def test_get_admin(self):
     view = self.view.as_view()
     user = UserFactory.create()
     assign_role(user, 'admin')
     request = self.create_request(user=user)
     response = view(request)
     self.assertEqual(response.status_code, 200)
    def setUp(self):
        self.user = UserFactory.create(password=self.password)
        assign_role(self.user, 'admin')

        self.survey = SurveyFactory.create()

        self.section1_1 = SurveySectionFactory.create(number=1, )
        self.section1_2 = SurveySectionFactory.create(number=2, )
        self.section1_3 = SurveySectionFactory.create(number=3, )

        self.q1 = SurveyQuestionFactory.create(survey=self.survey,
                                               level=1,
                                               section=self.section1_1)
        self.q2 = SurveyQuestionFactory.create(survey=self.survey,
                                               level=2,
                                               section=self.section1_1)
        self.q3 = SurveyQuestionFactory.create(survey=self.survey,
                                               level=2,
                                               section=self.section1_1)

        self.q4 = SurveyQuestionFactory.create(survey=self.survey,
                                               level=3,
                                               section=self.section1_2)
        self.q5 = SurveyQuestionFactory.create(survey=self.survey,
                                               level=4,
                                               section=self.section1_3)

        package_invitation_allowed = 10
        self.package = AssessmentPackageFactory.create(
            name="10 invitations Package",
            number_included=package_invitation_allowed,
            price=900.00)

        self.login(self.user.email, self.password)
        self.assertIn(self.title, self.browser.title)
Exemplo n.º 24
0
 def setUp(self):
     user = UserFactory.create(username="******")
     a = ActivityFactory(user=user)
     t = ActivityTrackFactory.create(activity=a)
     ActivityTrackpointFactory.create(track=t)
     t.reset_trim()
     self.client.login(username='******', password='******')
Exemplo n.º 25
0
    def test_no_allow_random(self):
        user = UserFactory.create(profile=None)
        data = self._data(allow_random=0)
        form = LandingPageForm(data=data)
        self.assertTrue(form.is_valid())
        form.save(user)
        self.assertEqual(user.profile.allow_random, False)

        user = UserFactory.create(profile=None)
        data = self._data()
        if 'allow_random' in data:
            del data['allow_random']
        form = LandingPageForm(data=data)
        self.assertTrue(form.is_valid())
        form.save(user)
        self.assertEqual(user.profile.allow_random, False)
Exemplo n.º 26
0
def test_set_for_user_works():
    user = UserFactory.create()
    AccessDate.objects.set_for_user(user, [date(2010, 1, 1)])
    assert AccessDate.objects.get_for_user(user) == [date(2010, 1, 1)]

    AccessDate.objects.set_for_user(user, [date(2011, 2, 2)])
    assert AccessDate.objects.get_for_user(user) == [date(2011, 2, 2)]
    def test_invite_registered_grantee_from_assessments_shared_tier_gold(self):
        self.grantee = UserFactory.create(password=self.password)
        self.click_and_wait_for_page_load(
            self.browser.find_element_by_link_text("Assessments"), )
        self.click_and_wait_for_page_load(
            self.browser.find_element_by_link_text("Invite grantee"), )

        self.select_drop_down_for_invitation("grantee")

        # select survey
        self.select_drop_down_for_invitation("survey")

        # select tier
        # 0-Bronze,1-Silver,2-Gold,3-Platinum
        tiers = self.browser.find_elements_by_css_selector(
            "label[class='ui-check w-sm']")
        tiers[2].click()

        self.set_survey_due_date("id_due_date")

        submit = self.browser.find_element_by_css_selector(
            "button[type='submit']")
        self.click_and_wait_for_page_load(submit)
        alert_elem = self.browser.find_element_by_id("alert")
        success_msg = "Invitation sent successfully"
        self.assertIn(
            alert_elem.find_element_by_class_name("px-2").text, success_msg)
Exemplo n.º 28
0
 def test_emoji_reason(self):
     poo = u"💩"
     user = UserFactory.create(profile=None)
     data = self._data(reason=poo)
     form = LandingPageForm(data=data)
     self.assertTrue(form.is_valid())
     form.save(user)
     self.assertEqual(user.profile.reason_decoded, poo)
Exemplo n.º 29
0
 def test_save_update_name_user_only(self):
     user = UserFactory.create(profile=None)
     data = self._data()
     form = LandingPageForm(data=data)
     self.assertTrue(form.is_valid())
     form.save(user)
     user = get_user_model().objects.get(id=user.id)
     self.assertEqual(user.get_full_name(), user.profile.fb_name)
Exemplo n.º 30
0
def create_profiles(num_profiles):
    # This seed does nothing because I'm using fake-factory instead of
    # factory.fuzzy. TODO fix it
    fuzzy.reseed_random(RANDOM_SEED)
    return [
        user.profile
        for user in (UserFactory.create() for x in range(num_profiles))
    ]
Exemplo n.º 31
0
 def test_it_works(self, graphql_client, fake_soap_call,
                   django_file_storage):
     user = UserFactory.create()
     graphql_client.request.user = user
     fake_soap_call.simulate_success(user)
     result = execute_genpdf_mutation(graphql_client)
     assert result['errors'] == []
     assert get_upload_status_for_user(user) == HPUploadStatus.SUCCEEDED
Exemplo n.º 32
0
 def setUp(self):
     self.client = Client()
     self.book = BookFactory.create()
     self.user = UserFactory.create()
Exemplo n.º 33
0
 def test_requests(self):
     user = UserFactory.create()
     book = BookFactory.create()
     request = BookRequest(book=book, requester=user)
     request.save()
     self.assertEqual(list(book.requests()), [request])
Exemplo n.º 34
0
 def setUp(self):
     self.client = APIClient(enforce_csrf_checks=True)
     self.user = UserFactory.create()  # suppress @UndefinedVariable
     self.auth = 'JWT {}'.format(self.create_token(self.user))