Exemplo n.º 1
0
 def test_will_error_if_not_user_requesting(self, _):
     user_profile = UserProfileFactory()
     user_profile_requesting = UserProfileFactory()
     self.client.authenticate(user_profile_requesting.user)
     result = self.compute_doppelganger({'userProfileId': user_profile.id})
     self.assertEqual([str(e) for e in result.errors],
                      [no_permission_error])
Exemplo n.º 2
0
    def setUp(self):
        user_profile1 = UserProfileFactory()
        user_profile2 = UserProfileFactory()

        # shared answer
        self.user1_answered_question1, _ = (shared_answered_questions_factory(
            user_profile1=user_profile1,
            user_profile2=user_profile2,
        ))

        # another shared answer
        self.user1_answered_question2, _ = (shared_answered_questions_factory(
            user_profile1=user_profile1,
            user_profile2=user_profile2,
        ))

        # a non-shared answer
        shared_answered_questions_factory(
            user_profile1=user_profile1,
            user_profile2=user_profile2,
            different_answers=True,
        )

        self.user1_answered_qs = user_profile1.answered_questions.all()
        self.user2_answered_qs = user_profile2.answered_questions.all()
Exemplo n.º 3
0
    def test_will_return_score_and_user_if_doppelganger_exists(self, _):
        user_profile = UserProfileFactory()
        doppelganger = UserProfileFactory()
        self.client.authenticate(user_profile.user)
        expected_result = {
            'userProfile': {
                'user': {
                    'username': doppelganger.user.username,
                },
            },
            'doppelgangerInfo': {
                'score': 1.0,
            },
        }

        with self.subTest('with explicit variables passed'):
            result = self.compute_doppelganger(
                {'userProfileId': user_profile.id})

            self.assertIsNone(result.errors)
            self.assertEqual(result.data[self.op_name], expected_result)

        with self.subTest('with implicit user through authentication'):
            result = self.compute_doppelganger()

            self.assertIsNone(result.errors)
            self.assertEqual(result.data[self.op_name], expected_result)
Exemplo n.º 4
0
    def test_comparison_returns_answered_questions_for_users_with_shared_qs(
            self):
        user_profile1 = UserProfileFactory()
        user_profile2 = UserProfileFactory()
        user1_answered_question1, user2_answered_question1 = (
            shared_answered_questions_factory(
                user_profile1=user_profile1,
                user_profile2=user_profile2,
            ))
        user1_answered_question2, user2_answered_question2 = (
            shared_answered_questions_factory(
                user_profile1=user_profile1,
                user_profile2=user_profile2,
            ))
        shared_answered_questions_factory(
            user_profile1=user_profile1,
            user_profile2=user_profile2,
            different_answers=True,
        )

        comparison = UserComparison(
            source_user_profile=user_profile1,
            target_user_profile=user_profile2,
        )
        self.assertEqual(list(comparison.sources_shared_answered_questions()),
                         [user1_answered_question1, user1_answered_question2])
        self.assertEqual(list(comparison.targets_shared_answered_questions()),
                         [user2_answered_question1, user2_answered_question2])
Exemplo n.º 5
0
 def test_comparison_returns_answered_questions_for_users_with_no_questions(
         self):
     user_profile1 = UserProfileFactory()
     user_profile2 = UserProfileFactory()
     comparison = UserComparison(
         source_user_profile=user_profile1,
         target_user_profile=user_profile2,
     )
     self.assertEqual(list(comparison.sources_shared_answered_questions()),
                      [])
     self.assertEqual(list(comparison.targets_shared_answered_questions()),
                      [])
Exemplo n.º 6
0
    def test_handler(self):
        user = UserFactory()
        profile = UserProfileFactory(user=user)

        #empty response
        facebook_extra_values(self, user, {}, {})

        # This is how the response from facebook looks like. It contains many
        # more values but we only use these few.
        response = {
            'birthday': '09/08/1982',
            'gender': 'male',
            'username': '******',
            'first_name': 'Foo',
            'last_name': 'Bar',
            'location': {
                'id': '101883206519751',
                'name': 'Singapore, Singapore',
            },
        }
        facebook_extra_values(self, user, response, {})

        profile = UserProfile.objects.get(pk=profile.pk)
        self.assertEqual(profile.birthday,
                         timezone.datetime(1982, 9, 8).date(),
                         msg=('Should set the birthday correctly'))
        self.assertEqual(profile.gender,
                         'male',
                         msg=('Should set the gender correctly'))
        self.assertEqual(profile.location,
                         'Singapore, Singapore',
                         msg=('Should set the location correctly'))
Exemplo n.º 7
0
    def test_will_return_none_if_no_doppelganger_exists(self, _):
        user_profile = UserProfileFactory(user__username='******')
        self.client.authenticate(user_profile.user)

        result = self.compute_doppelganger({'userProfileId': user_profile.id})

        self.assertIsNone(result.errors)
        self.assertEqual(result.data[self.op_name], None)
Exemplo n.º 8
0
 def setUp(self):
     super(CustomCheckinCreateFormTestCase, self).setUp()
     self.profile = UserProfileFactory()
     self.place = PlaceFactory()
     self.data = {
         'user_name': 'Foobar',
         'lat': '1.3568494',
         'lng': '103.9478796',
     }
Exemplo n.º 9
0
 def test_will_not_error_if_superuser_requesting(self, _):
     superuser = get_user_model().objects.create_superuser(
         username='******',
         email='*****@*****.**',
         password='******')
     user_profile = UserProfileFactory()
     self.client.authenticate(superuser)
     result = self.compute_doppelganger({'userProfileId': user_profile.id})
     self.assertIsNone(result.errors)
Exemplo n.º 10
0
 def test_will_error_if_not_user_requesting(self):
     user_profile_requesting = UserProfileFactory()
     self.client.authenticate(user_profile_requesting.user)
     result = self.user_comparison({
         'sourceUserProfileId':
         self.user_profile.id,
         'targetUserProfileId':
         self.target_user_profile.id,
     })
     self.assertEqual([str(e) for e in result.errors],
                      [no_permission_error])
Exemplo n.º 11
0
    def test_finds_doppelganger_with_most_similar_answers(self):
        question = QuestionFactory(with_answers=True)
        non_shared_answer = question.answers.first()
        shared_answer = question.answers.last()

        user_profile, doppelganger = [
            AnsweredQuestionFactory(question=question,
                                    answer=shared_answer).user_profile
            for _ in range(2)
        ]

        # Create an answered ques. with a profile that won't be a doppelganger
        AnsweredQuestionFactory(
            question=question,
            answer=non_shared_answer,
        )

        # Create a profile with no answered questions that won't be a
        # doppelganger
        UserProfileFactory()

        self.assertEqual(get_doppelganger_and_score(user_profile),
                         (doppelganger, 1))
Exemplo n.º 12
0
 def setUp(self):
     super(UserProfileUpdateFormTestCase, self).setUp()
     self.data = {
         'timezone': 'Asia/Singapore',
     }
     self.profile = UserProfileFactory()
Exemplo n.º 13
0
 def setUp(self):
     super(UsernameUpdateFormTestCase, self).setUp()
     self.data = {
         'username': '******',
     }
     self.profile = UserProfileFactory()
Exemplo n.º 14
0
 def setUp(self):
     super(PlaceCreateFormTestCase, self).setUp()
     self.type = PlaceTypeFactory(name='Basketball')
     self.profile = UserProfileFactory()
Exemplo n.º 15
0
 def test_will_error_if_not_logged_in(self, _):
     user_profile = UserProfileFactory()
     result = self.compute_doppelganger({'userProfileId': user_profile.id})
     self.assertEqual([str(e) for e in result.errors],
                      [no_permission_error])
Exemplo n.º 16
0
 def setUp(self):
     self.profile = UserProfileFactory()
Exemplo n.º 17
0
 def test_if_no_good_candidates_doppelganger_is_none(self):
     user_profile = UserProfileFactory()
     UserProfileFactory()
     self.assertIsNone(get_doppelganger_and_score(user_profile))
Exemplo n.º 18
0
 def test_view(self):
     UserProfileFactory()
     UserProfileFactory()
     resp = self.client.get(self.get_url())
     self.assertEqual(resp.content, '"2"')
Exemplo n.º 19
0
 def setUp(self):
     super(UsernameUpdateViewTestCase, self).setUp()
     self.profile = UserProfileFactory()
Exemplo n.º 20
0
    def test_omits_answered_questions_when_arg_passed(self):
        # Non answered question
        question = QuestionFactory()
        answer1 = AnswerFactory(question=question)
        answer2 = AnswerFactory(question=question)

        # answered question
        question2 = QuestionFactory()
        answer3 = AnswerFactory(question=question2)
        AnswerFactory(question=question2)

        # authenticate user with answered question
        user_profile = UserProfileFactory()
        AnsweredQuestionFactory(
            user_profile=user_profile,
            question=question2,
            answer=answer3,
        )
        user = user_profile.user
        self.client.authenticate(user)

        result = self.client.execute(
            '''
            query {
                questions(omitAnsweredQuestions: true) {
                    edges {
                        node {
                            id
                            pk
                            text
                            answers {
                                pk
                                text
                            }
                        }
                    }
                }
            }
            ''', )

        self.assertIsNone(result.errors)
        self.assertEqual(result.data[self.op_name]['edges'], [{
            'node': {
                'id':
                to_global_id(QuestionType._meta.name, question.id),
                'pk':
                question.id,
                'text':
                question.text,
                'answers': [
                    {
                        'pk': answer2.id,
                        'text': answer2.text
                    },
                    {
                        'pk': answer1.id,
                        'text': answer1.text
                    },
                ],
            }
        }])
Exemplo n.º 21
0
 def setUp(self):
     self.profile = UserProfileFactory()
     self.user = self.profile.user
     self.answer = AnswerFactory()
     self.question = self.answer.question
Exemplo n.º 22
0
 def setUp(self):
     self.profile = UserProfileFactory()
     self.profile.username = '******'
     self.profile.save()
Exemplo n.º 23
0
    def handle(self, *args, **options):
        # question
        create_questions_and_answers(question_answers)

        # user
        user = get_user_model().objects.create_superuser(
            username='******',
            email='*****@*****.**',
            password='******')
        UserProfileFactory(user=user)

        profile_with_doppelganger = UserProfileFactory(
            user__email='*****@*****.**',
            user__password='******',
        )
        AnsweredQuestionFactory(
            user_profile=profile_with_doppelganger,
            question=Question.objects.get(text=BEST_VILLAIN),
            answer=Answer.objects.get(text='Darth Vader'),
        )
        AnsweredQuestionFactory(
            user_profile=profile_with_doppelganger,
            question=Question.objects.get(text=BEST_DJ),
            answer=Answer.objects.get(text='A-Trak'),
        )
        AnsweredQuestionFactory(
            user_profile=profile_with_doppelganger,
            question=Question.objects.get(text=BEST_SEINFELD_CHARACTER),
            answer=Answer.objects.get(text='Jerry'),
        )

        doppelganger_profile = UserProfileFactory(
            user__email='*****@*****.**',
            user__password='******',
        )
        AnsweredQuestionFactory(
            user_profile=doppelganger_profile,
            question=Question.objects.get(text=BEST_VILLAIN),
            answer=Answer.objects.get(text='Darth Vader'),
        )
        AnsweredQuestionFactory(
            user_profile=doppelganger_profile,
            question=Question.objects.get(text=BEST_DJ),
            answer=Answer.objects.get(text='Diplo'),
        )
        AnsweredQuestionFactory(
            user_profile=doppelganger_profile,
            question=Question.objects.get(text=BEST_SEINFELD_CHARACTER),
            answer=Answer.objects.get(text='Jerry'),
        )

        not_doppelganger_profile = UserProfileFactory(
            user__email='*****@*****.**',
            user__password='******',
        )
        AnsweredQuestionFactory(
            user_profile=not_doppelganger_profile,
            question=Question.objects.get(text=BEST_VILLAIN),
            answer=Answer.objects.get(text='Darth Maul'),
        )
        AnsweredQuestionFactory(
            user_profile=not_doppelganger_profile,
            question=Question.objects.get(text=BEST_DJ),
            answer=Answer.objects.get(text='Diplo'),
        )
        AnsweredQuestionFactory(
            user_profile=not_doppelganger_profile,
            question=Question.objects.get(text=BEST_SEINFELD_CHARACTER),
            answer=Answer.objects.get(text='George'),
        )

        UserProfileFactory(
            user__email='*****@*****.**',
            user__password='******',
        )
Exemplo n.º 24
0
 def setUp(self):
     self.user_profile = UserProfileFactory()
     self.target_user_profile = UserProfileFactory()