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])
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()
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)
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])
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()), [])
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'))
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)
def setUp(self): super(CustomCheckinCreateFormTestCase, self).setUp() self.profile = UserProfileFactory() self.place = PlaceFactory() self.data = { 'user_name': 'Foobar', 'lat': '1.3568494', 'lng': '103.9478796', }
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)
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])
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))
def setUp(self): super(UserProfileUpdateFormTestCase, self).setUp() self.data = { 'timezone': 'Asia/Singapore', } self.profile = UserProfileFactory()
def setUp(self): super(UsernameUpdateFormTestCase, self).setUp() self.data = { 'username': '******', } self.profile = UserProfileFactory()
def setUp(self): super(PlaceCreateFormTestCase, self).setUp() self.type = PlaceTypeFactory(name='Basketball') self.profile = UserProfileFactory()
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])
def setUp(self): self.profile = UserProfileFactory()
def test_if_no_good_candidates_doppelganger_is_none(self): user_profile = UserProfileFactory() UserProfileFactory() self.assertIsNone(get_doppelganger_and_score(user_profile))
def test_view(self): UserProfileFactory() UserProfileFactory() resp = self.client.get(self.get_url()) self.assertEqual(resp.content, '"2"')
def setUp(self): super(UsernameUpdateViewTestCase, self).setUp() self.profile = UserProfileFactory()
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 }, ], } }])
def setUp(self): self.profile = UserProfileFactory() self.user = self.profile.user self.answer = AnswerFactory() self.question = self.answer.question
def setUp(self): self.profile = UserProfileFactory() self.profile.username = '******' self.profile.save()
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='******', )
def setUp(self): self.user_profile = UserProfileFactory() self.target_user_profile = UserProfileFactory()