def setUp(self): # Create actor1, actor2 and actor3 self.actor1, self.actor2, self.actor3 = Actor(), Actor(), Actor() # actors sign up self.user_model1, self.user_model2, self.user_model3 = (UserActions( actor=self.actor1).signup(), UserActions( actor=self.actor2).signup(), UserActions( actor=self.actor3).signup()) # actor1 creates thread self.thread_model = ThreadActions(actor=self.actor1).create_thread() # actor1 invites actor2 and actor3 to thread ThreadActions(actor=self.actor1).invite_users_to_thread( thread_id=self.thread_model.id, user_ids=[self.user_model2.id, self.user_model3.id]) # actor2 and actor3 accept thread invitations actor2_invitation_model = ThreadActions( actor=self.actor2).get_received_thread_invitations()[0] actor3_invitation_model = ThreadActions( actor=self.actor3).get_received_thread_invitations()[0] ThreadActions(actor=self.actor2).accept_or_reject_thread_invitation( invitation_id=actor2_invitation_model.id, accept=True) ThreadActions(self.actor3).accept_or_reject_thread_invitation( invitation_id=actor3_invitation_model.id, accept=True)
def setUp(self): # Create actor1, actor2 self.actor1, self.actor2 = Actor(), Actor() # actors sign up self.user_model1, self.user_model2 = ( UserActions(actor=self.actor1).signup(), UserActions(actor=self.actor2).signup() ) # actor1 creates threads self.thread_model1, self.thread_model2, self.thread_model3 = ( ThreadActions(actor=self.actor1).create_thread(), ThreadActions(actor=self.actor1).create_thread(), ThreadActions(actor=self.actor1).create_thread() ) # actor1 invites actor2 to threads self.thread_invitation_models1 = ThreadActions(actor=self.actor1).invite_users_to_thread( thread_id=self.thread_model1.id, user_ids=[self.user_model2.id] ) self.thread_invitation_models2 = ThreadActions(actor=self.actor1).invite_users_to_thread( thread_id=self.thread_model2.id, user_ids=[self.user_model2.id] ) self.thread_invitation_models3 = ThreadActions(actor=self.actor1).invite_users_to_thread( thread_id=self.thread_model3.id, user_ids=[self.user_model2.id] )
def setUp(self): # Create actor1, actor2 self.actor1, self.actor2 = Actor(), Actor() # actors sign up self.user_model1, self.user_model2 = (UserActions( actor=self.actor1).signup(), UserActions( actor=self.actor2).signup()) # actor1 creates thread self.thread_model = ThreadActions(actor=self.actor1).create_thread() # actor2 applies to thread thread_application_model = ThreadActions( actor=self.actor2).apply_to_thread(thread_id=self.thread_model.id) # actor1 accepts thread application ThreadActions(actor=self.actor1).accept_or_reject_thread_application( thread_id=self.thread_model.id, application_id=thread_application_model.id, accept=True) # actor1 sends message in thread self.thread_message_model = ThreadActions( actor=self.actor1).send_message_in_thread( thread_id=self.thread_model.id, )
def test_signup_as_already_existing_user(self): # Create actor2 actor2 = Actor() # Signup UserActions(actor=self.actor).signup() # Assert unable to signup with already taken username with self.assertRaises(http_exceptions.Conflict): UserActions(actor=actor2).signup(username=self.actor.username)
def setUp(self): # Create actor1, actor2 and actor3 self.actor1, self.actor2, self.actor3 = Actor(), Actor(), Actor() # actors sign up self.user_model1, self.user_model2, self.user_model3 = (UserActions( actor=self.actor1).signup(), UserActions( actor=self.actor2).signup(), UserActions( actor=self.actor3).signup()) # actor1 creates thread self.thread_model = ThreadActions(actor=self.actor1).create_thread()
def test_get_user(self): # Signup signup_user_model = UserActions(actor=self.actor).signup() # Get user details user_model = UserActions(actor=self.actor).get_user() # Assert correct UserModel has been returned self.assertUserModel(user_model) self.assertEqual(user_model.username, signup_user_model.username) self.assertEqual(user_model.lastname, signup_user_model.lastname) self.assertEqual(user_model.username, signup_user_model.username)
def test_get_user_by_username(self): # Create actor2 actor2 = Actor() # actor2 signs up UserActions(actor=actor2).signup() # actor2 gets actor1 details by username user_model = UserActions(actor=actor2).get_user_by_username(username=self.signup_user_model.username) # Assert correct model has been returned self.assertUserModel(user_model) self.assertModelsAreEqual(model1=self.signup_user_model, model2=user_model, ignore_attributes=["updated_at"])
def setUp(self): # Create actor1, actor2 self.actor1, self.actor2 = Actor(), Actor() # actors sign up self.user_model1, self.user_model2 = (UserActions( actor=self.actor1).signup(), UserActions( actor=self.actor2).signup()) # actor1 creates thread self.thread_model = ThreadActions(actor=self.actor1).create_thread() # actor2 applies to thread self.thread_application_model = ThreadActions( actor=self.actor2).apply_to_thread(thread_id=self.thread_model.id)
def setUp(self): # Create actors self.actors = [Actor() for _ in range(10)] # Actors sign up self.user_models = [ UserActions(actor=actor).signup() for actor in self.actors ]
def test_delete_thread_as_not_owner(self): # Create another actor and signup actor2 = Actor() UserActions(actor=actor2).signup() # Assert unable to delete thread as not owner with self.assertRaises(http_exceptions.Forbidden): ThreadActions(actor=actor2).delete_thread(thread_id=self.thread_model.id)
def test_get_thread_messages_as_not_member_of_thread(self): # Create another actor and signup actor5 = Actor() UserActions(actor=actor5).signup() # Assert unable to get thread messages as not member of thread with self.assertRaises(http_exceptions.Forbidden): ThreadActions(actor=actor5).get_thread_messages( thread_id=self.thread_model.id)
def test_signup(self): # Signup user_model = UserActions(actor=self.actor).signup() # Assert correct UserModel has been returned self.assertUserModel(user_model) self.assertEqual(user_model.username, self.actor.username) self.assertEqual(user_model.lastname, self.actor.lastname) self.assertEqual(user_model.username, self.actor.username)
def test_get_users(self): # Get users user_models = UserActions(actor=self.actors[0]).get_users() # Assert all signed up actors are present and are correct models for user_model in user_models: self.assertUserModel(user_model) self.assertModelsInListOfModels(container=user_models, models=self.user_models)
def test_send_message_in_thread_as_not_thread_member(self): # Create actor3 and sign up actor3 = Actor() UserActions(actor=actor3).signup() # Assert unable to send message in thread while not being a member of the thread with self.assertRaises(http_exceptions.Forbidden): ThreadActions(actor=actor3).send_message_in_thread( thread_id=self.thread_model.id)
def setUp(self): # Create actor self.actor = Actor() # actor signs up self.user_model = UserActions(actor=self.actor).signup() # actor creates thread self.thread_model = ThreadActions(actor=self.actor).create_thread()
def setUp(self): # Create actor1, actor2, actor3 and actor4 self.actor1, self.actor2, self.actor3, self.actor4 = [ Actor() for _ in xrange(4) ] # actors sign up self.user_model1, self.user_model2, self.user_model3, self.user_model4 = ( UserActions(actor=self.actor1).signup(), UserActions(actor=self.actor2).signup(), UserActions(actor=self.actor3).signup(), UserActions(actor=self.actor4).signup()) # actor1 creates thread self.thread_model = ThreadActions(actor=self.actor1).create_thread() # actor2, actor3 and actor4 apply to thread to thread thread_application_models = [ ThreadActions(actor=actor).apply_to_thread( thread_id=self.thread_model.id) for actor in [self.actor2, self.actor3, self.actor4] ] # actor1 accepts thread applications for thread_application_model in thread_application_models: ThreadActions( actor=self.actor1).accept_or_reject_thread_application( thread_id=self.thread_model.id, application_id=thread_application_model.id, accept=True) # actors send messages in thread self.thread_message_model1 = ThreadActions( actor=self.actor1).send_message_in_thread( thread_id=self.thread_model.id) self.thread_message_model2 = ThreadActions( actor=self.actor2).send_message_in_thread( thread_id=self.thread_model.id) self.thread_message_model3 = ThreadActions( actor=self.actor3).send_message_in_thread( thread_id=self.thread_model.id) self.thread_message_model4 = ThreadActions( actor=self.actor4).send_message_in_thread( thread_id=self.thread_model.id)
def test_get_thread_message_as_not_thread_member(self): # Create additional actor and sign up actor3 = Actor() UserActions(actor=actor3).signup() # Assert unable to get thread message as not thread member with self.assertRaises(http_exceptions.Forbidden): ThreadActions(actor=actor3).get_thread_message( thread_id=self.thread_model.id, message_id=self.thread_message_model.id)
def setUp(self): # Create actor self.actor = Actor() # actor signs up self.user_model = UserActions(actor=self.actor).signup() # actor creates threads self.thread_models = [ ThreadActions(actor=self.actor).create_thread() for _ in xrange(10) ] self.private_thread_models = [ ThreadActions(actor=self.actor).create_thread(private=True) for _ in xrange(3) ]
def test_get_threads(self): # Create actor2 and signup actor2 = Actor() UserActions(actor=actor2).signup() # actor2 gets threads thread_models = ThreadActions(actor=actor2).get_threads() # Assert threads have the correct model and all created threads are present for thread_model in thread_models: self.assertThreadModel(thread_model) self.assertModelsInListOfModels(container=thread_models, models=self.thread_models) self.assertModelsNotInListOfModels(container=thread_models, models=self.private_thread_models)
def setUp(self): # Create actor self.actor = Actor() # actor signs up self.user_model = UserActions(actor=self.actor).signup()
def test_signup_username_below_min_length(self): # Assert unable to signup with username below minimum length with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup( username=generate_random_string(1, 1))
def test_signup_username_as_digits(self): # Assert unable to signup with username as digits with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup(username="******")
def test_get_user_by_username_as_unauthorized_user(self): # Assert unable to get user by username as unauthorized user with self.assertRaises(http_exceptions.Unauthorized): UserActions(actor=Actor()).get_user_by_username(username=self.signup_user_model.username)
def test_signup_empty_username(self): # Assert unable to signup with empty username with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup(username="")
def test_signup_lastname_over_max_length(self): # Assert unable to signup with lastname over maximum length with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup( lastname=generate_random_string(51, 51))
def test_get_user_as_unauthorized_user(self): # Assert unable to get user details as unauthorized user with self.assertRaises(http_exceptions.Unauthorized): UserActions(actor=self.actor).get_user()
def test_signup_password_below_min_length(self): # Assert unable to signup with password below minimum length with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup( password=generate_random_string(3, 3))
def test_signup_empty_password(self): # Assert unable to signup with empty password with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup(password="")
def test_validate_username(self): username_validation_model = UserActions( actor=self.actor).validate_username() self.assertUsernameValidationModel(username_validation_model)
def test_signup_password_over_max_length(self): # Assert unable to signup with password over maximum length with self.assertRaises(http_exceptions.UnprocessableEntity): UserActions(actor=self.actor).signup( password=generate_random_string(21, 21))