def setup_user(self): self.test_user = User.objects.create(username="******", email="*****@*****.**") self.test_user.set_password("test_pass") self.test_user.is_active = True self.test_user.save() self.test_profile = Profile.brand_new(user=self.test_user)
def test_brand_new(self): new_user = User.objects.create(username="******", password="******", email="*****@*****.**") new_prof = Profile.brand_new(user=new_user) self.assertEquals(new_prof.user, new_user) self.assertEquals(new_prof.risk, 0)
def setup_user(self): self.test_user = User.objects.create(username="******", email="*****@*****.**") self.test_user.set_password("test_pass") self.test_user.is_active = True self.test_user.save() self.test_profile = Profile.brand_new(user=self.test_user) self.token = Token.objects.get(user=self.test_user) self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
def setup_interaction_test(self): self.test_user2 = User.objects.create(username="******", password="******", email="*****@*****.**") self.test_user2.is_active = True self.test_user2.save() self.test_profile2 = Profile.brand_new(user=self.test_user2) self.test_profile2.save() self.token = Token.objects.get(user=self.test_user2) interaction = UserInteraction.start(creator=self.test_profile2) interaction.add_participants([self.test_profile]) interaction.save() return interaction
def post(self, request): serializer = UserSignupSerializer(data=request.data) if serializer.is_valid(): data = serializer.data user = self.signup(data['email'], data['username'], data['password']) if user is not None: profile = Profile.brand_new(user) profile.send_verification_email() return Response({ 'detail': 'Please check your email for a verification link' }) return Response( {'detail': 'A user with those credentials already exists'}, status=403)
def test_end_interaction_is_not_creator(self): new_user = User.objects.create(username="******", password="******", email="*****@*****.**") prof = Profile.brand_new(user=new_user) interaction = UserInteraction.start(creator=prof) interaction.add_participants([self.test_profile]) self.assertFalse(interaction.has_ended) # Tests response that it ended the interaction url = reverse('end_interaction', kwargs={'code': interaction.unique_id}) response = self.client.get(url) parsed = json.loads(response.content) self.assertEquals(response.status_code, 403) # Tests that the interaction was not ended interaction = UserInteraction.objects.get(creator=prof) self.assertFalse(interaction.has_ended)
def test_join_interaction_has_others(self): new_user = User.objects.create(username="******", password="******", email="*****@*****.**") prof = Profile.brand_new(user=new_user) # Asserts that the user is already in an interaction for the remainder of the test interaction = UserInteraction.start(creator=prof) interaction.add_participants([self.test_profile]) self.assertTrue(self.test_profile.has_running_interactions) # Tests response that the was not allowed to join the interaction url = reverse('join_interaction', kwargs={'code': interaction.unique_id}) response = self.client.get(url) parsed = json.loads(response.content) self.assertEquals(response.status_code, 403) self.assertEquals( parsed['detail'], 'You are only able to have one interaction running at a time')
def test_join_interaction_no_others(self): # Sets up user with interaction new_user = User.objects.create(username="******", password="******", email="*****@*****.**") prof = Profile.brand_new(user=new_user) self.assertFalse(self.test_profile.has_running_interactions) interaction = UserInteraction.start(creator=prof) # Tests response that the user joined the interaction url = reverse('join_interaction', kwargs={'code': interaction.unique_id}) response = self.client.get(url) parsed = json.loads(response.content) self.assertEquals(parsed['interaction_code'], str(interaction.unique_id)) self.assertEquals(response.status_code, 200) # Tests user is added to interaction self.assertTrue(self.test_profile.has_running_interactions)