コード例 #1
0
    def test_invite_multiple_users_to_thread(self):
        # actor1 invites actor2
        thread_invitation_models = ThreadActions(
            actor=self.actor1).invite_users_to_thread(
                thread_id=self.thread_model.id,
                user_ids=[self.user_model2.id, self.user_model3.id])

        # Assert correct models have been returned
        self.assertEqual(len(thread_invitation_models), 2)
        for thread_invitation_model in thread_invitation_models:
            self.assertThreadInvitationModel(thread_invitation_model)
            self.assertIn(thread_invitation_model.user,
                          [self.user_model2.id, self.user_model3.id])
            self.assertEqual(thread_invitation_model.thread,
                             self.thread_model.id)
            self.assertEqual(thread_invitation_model.status, 1)
            self.assertEqual(thread_invitation_model.invited_by,
                             self.user_model1.id)
            self.assertEqual(thread_invitation_model.users_in_thread,
                             [self.user_model1.id])
        # Assert actor2 and actor3 got invited
        for actor in [self.actor2, self.actor3]:
            obtained_thread_invitation_model = ThreadActions(
                actor=actor).get_received_thread_invitations()[0]
            self.assertModelInListOfModels(obtained_thread_invitation_model,
                                           thread_invitation_models)
コード例 #2
0
    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, )
コード例 #3
0
 def test_invite_already_invited_user_to_thread(self):
     # actor1 invites actor2
     ThreadActions(actor=self.actor1).invite_users_to_thread(
         thread_id=self.thread_model.id, user_ids=[self.user_model2.id])
     # Assert unable to invite already invited user
     with self.assertRaises(http_exceptions.Conflict):
         ThreadActions(actor=self.actor1).invite_users_to_thread(
             thread_id=self.thread_model.id, user_ids=[self.user_model2.id])
コード例 #4
0
    def test_kick_single_user_from_thread_as_thread_owner(self):
        # actor1 kicks actor2 from thread
        thread_model = ThreadActions(actor=self.actor1).kick_users_from_thread(
            thread_id=self.thread_model.id, user_ids=[self.user_model2.id])

        # Assert user has been kicked
        self.assertNotIn(self.user_model2.id, thread_model.users)
        # Assert user has no access to thread
        with self.assertRaises(http_exceptions.Forbidden):
            ThreadActions(actor=self.actor2).send_message_in_thread(
                thread_id=self.thread_model.id)
コード例 #5
0
    def test_kick_multiple_users_from_thread_as_thread_owner(self):
        # actor1 kicks actor2 and actor3 from thread
        thread_model = ThreadActions(actor=self.actor1).kick_users_from_thread(
            thread_id=self.thread_model.id,
            user_ids=[self.user_model2.id, self.user_model3.id])

        # Assert users have been kicked
        self.assertNotIn(self.user_model2.id, thread_model.users)
        self.assertNotIn(self.user_model3.id, thread_model.users)
        # Assert users have no access to thread
        for actor in [self.actor2, self.actor3]:
            with self.assertRaises(http_exceptions.Forbidden):
                ThreadActions(actor=actor).send_message_in_thread(
                    thread_id=self.thread_model.id)
コード例 #6
0
    def test_apply_to_thread(self):
        # actor2 applies to thread
        thread_application_model = ThreadActions(actor=self.actor2).apply_to_thread(thread_id=self.thread_model.id)

        # Assert correct model has been returned
        self.assertThreadApplicationModel(thread_application_model)
        self.assertEqual(thread_application_model.user, self.user_model2.id)
        self.assertEqual(thread_application_model.thread, self.thread_model.id)
        self.assertEqual(thread_application_model.status, 1)
        # Assert thread owner can see the application
        thread_application_models = ThreadActions(actor=self.actor1).get_received_thread_applications(
            thread_id=self.thread_model.id
        )
        self.assertModelsAreEqual(thread_application_model, thread_application_models[0],
                                  ignore_attributes=["updated_at"])
コード例 #7
0
    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)
        ]
コード例 #8
0
    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)
コード例 #9
0
 def test_delete_thread_message_as_unauthorized_user(self):
     # Assert unable to delete thread message as unauthorized user
     with self.assertRaises(http_exceptions.Unauthorized):
         ThreadActions(actor=Actor()).remove_thread_message(
             thread_id=self.thread_model.id,
             message_id=self.thread_message_model.id
         )
コード例 #10
0
 def test_delete_non_existant_thread_message(self):
     # Assert unable to delete non existant thread message
     with self.assertRaises(http_exceptions.NotFound):
         ThreadActions(actor=self.actor1).remove_thread_message(
             thread_id=self.thread_model.id,
             message_id=generate_random_string(5, 10)
         )
コード例 #11
0
 def test_delete_thread_message_as_thread_member(self):
     # Assert unable to delete message even as thread member, but not message owner
     with self.assertRaises(http_exceptions.Forbidden):
         ThreadActions(actor=self.actor2).remove_thread_message(
             thread_id=self.thread_model.id,
             message_id=self.thread_message_model.id
         )
コード例 #12
0
 def test_reject_received_invitation_as_not_invitee(self):
     # Assert unable to reject received invitation as not invitee
     with self.assertRaises(http_exceptions.NotFound):
         ThreadActions(
             actor=self.actor1).accept_or_reject_thread_invitation(
                 invitation_id=self.thread_invitation_model.id,
                 accept=False)
コード例 #13
0
 def test_edit_non_existant_thread_message(self):
     # Assert unable to edit non existant thread message
     with self.assertRaises(http_exceptions.NotFound):
         ThreadActions(actor=self.actor1).edit_thread_message(
             thread_id=self.thread_model.id,
             message_id=generate_random_string(5, 10),
             message=generate_random_words(5, 15))
コード例 #14
0
    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()

        # actor1 invites actor2 to thread
        self.thread_invitation_models = ThreadActions(
            actor=self.actor1).invite_users_to_thread(
                thread_id=self.thread_model.id, user_ids=[self.user_model2.id])
コード例 #15
0
 def test_reject_received_thread_application_as_unauthorized_user(self):
     # Assert unable to reject received thread application as unauthorized user
     with self.assertRaises(http_exceptions.Unauthorized):
         ThreadActions(actor=Actor()).accept_or_reject_thread_application(
             thread_id=self.thread_model.id,
             application_id=self.thread_application_model.id,
             accept=False)
コード例 #16
0
 def test_get_sent_invitation_as_unauthorized_user(self):
     # Assert unable to get sent invitation as unauthorized user
     with self.assertRaises(http_exceptions.Unauthorized):
         ThreadActions(actor=Actor()).get_sent_thread_invitation(
             thread_id=self.thread_model.id,
             invitation_id=self.thread_invitation_models[0].id
         )
コード例 #17
0
 def test_edit_thread_message_as_unauthorized_user(self):
     # Assert unable to edit thread message as unauthorized user
     with self.assertRaises(http_exceptions.Unauthorized):
         ThreadActions(actor=Actor()).edit_thread_message(
             thread_id=self.thread_model.id,
             message_id=self.thread_message_model.id,
             message=generate_random_string(5, 15))
コード例 #18
0
 def test_edit_thread_message_as_thread_member(self):
     # Assert unable to edit message even as thread member, but not message owner
     with self.assertRaises(http_exceptions.Forbidden):
         ThreadActions(actor=self.actor2).edit_thread_message(
             thread_id=self.thread_model.id,
             message_id=self.thread_message_model.id,
             message=generate_random_words(5, 15))
コード例 #19
0
 def test_get_sent_invitation_as_not_invitation_owner(self):
     # Assert unable to get sent invitation as not invitation owner
     with self.assertRaises(http_exceptions.Forbidden):
         ThreadActions(actor=self.actor2).get_sent_thread_invitation(
             thread_id=self.thread_model.id,
             invitation_id=self.thread_invitation_models[0].id
         )
コード例 #20
0
    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)
コード例 #21
0
 def test_reject_received_thread_application_as_not_thread_owner(self):
     # Assert unable to reject received thread application as not thread owner
     with self.assertRaises(http_exceptions.Forbidden):
         ThreadActions(
             actor=self.actor2).accept_or_reject_thread_application(
                 thread_id=self.thread_model.id,
                 application_id=self.thread_application_model.id,
                 accept=False)
コード例 #22
0
    def test_delete_thread_as_owner(self):
        # actor deletes thread
        thread_model = ThreadActions(actor=self.actor).delete_thread(thread_id=self.thread_model.id)

        # Assert thread has been marked as deleted
        self.assertThreadModel(thread_model)
        self.assertModelsAreEqual(self.thread_model, thread_model, ignore_attributes=["deleted", "updated_at"])
        self.assertTrue(thread_model.deleted)
コード例 #23
0
    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()
コード例 #24
0
    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)
コード例 #25
0
    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)
コード例 #26
0
    def test_get_sent_application_as_application_owner(self):
        # actor2 gets application
        thread_application_model = ThreadActions(
            actor=self.actor2).get_sent_thread_application(
                application_id=self.thread_application_model.id)

        # Assert correct model has been returned
        self.assertThreadApplicationModel(thread_application_model)
        self.assertModelsAreEqual(thread_application_model,
                                  self.thread_application_model)
コード例 #27
0
    def test_get_received_invitation_as_invitee(self):
        # actor2 gets received invitation
        thread_invitation_model = ThreadActions(
            actor=self.actor2).get_received_thread_invitation(
                invitation_id=self.thread_invitation_model.id)

        # Assert correct model has been returned
        self.assertThreadInvitationModel(thread_invitation_model)
        self.assertModelsAreEqual(thread_invitation_model,
                                  self.thread_invitation_model)
コード例 #28
0
    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)
コード例 #29
0
    def test_get_sent_invitation_as_invitation_owner(self):
        # actor1 gets sent invitation
        thread_invitation_model = ThreadActions(actor=self.actor1).get_sent_thread_invitation(
            thread_id=self.thread_model.id,
            invitation_id=self.thread_invitation_models[0].id
        )

        # Assert proper model has been returned
        self.assertThreadInvitationModel(thread_invitation_model)
        self.assertModelsAreEqual(thread_invitation_model, self.thread_invitation_models[0],
                                  ignore_attributes=["updated_at"])
コード例 #30
0
    def test_get_received_invitations(self):
        # actor2 gets received invitations
        thread_invitation_models = ThreadActions(actor=self.actor2).get_received_thread_invitations()

        # Assert correct models have been returned
        for thread_invitation_model in thread_invitation_models:
            self.assertThreadInvitationModel(thread_invitation_model)
        self.assertModelsInListOfModels(
            container=thread_invitation_models,
            models=self.thread_invitation_models1 + self.thread_invitation_models2 + self.thread_invitation_models3
        )