Beispiel #1
0
    def test_10_create_message_by_kicked_user(self):
        account_data = SignupMethods().create_test_account(generate_fields=True)
        account_id = account_data[1]['response']['id']
        data_to_encode = account_data[0]['username'] + ':' + account_data[0]['password']
        encoded_credentials = self.encoder.encode_data(data_to_encode)
        thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
        logging.info('Inviting user to thread %s' % self.thread_id)
        result = ThreadsMethods().invite_user_to_thread(authorization=self.thread_auth_headers,
                                                        thread_id=self.thread_id,
                                                        user_id=account_id)
        logging.info('Server returned %s' % result)
        invitation_id = result['response'][0]['id']

        logging.info('Accepting invitation to a thread %s' % self.thread_id)
        result = ThreadsMethods().accept_invitation_to_thread(authorization=thread_auth_headers,
                                                              invitation_id=invitation_id, accept=True)
        logging.info('Server returned %s' % result)
        logging.info('Kicking user from a thread %s' % self.thread_id)
        result = ThreadsMethods().kick_user_from_thread(authorization=self.thread_auth_headers,
                                                        thread_id=self.thread_id, user_id=account_id)
        logging.info('Server returned %s' % result)
        message = self.rand.generate_random_string(50)
        logging.info('Creating sample message as kicked user in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=thread_auth_headers,
                                                                       message=message)
        logging.info('Server returned %s' % result)
        result['code'] | should.be.equal.to(403)
        result['response']['message'].lower() | should.contain('is not a member of the thread')
 def test_04_view_messages_as_invited_user(self):
     account_data = SignupMethods().create_test_account(
         generate_fields=True)
     account_id = account_data[1]['response']['id']
     data_to_encode = account_data[0]['username'] + ':' + account_data[0][
         'password']
     encoded_credentials = self.encoder.encode_data(data_to_encode)
     thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
     logging.info('Inviting user to thread %s' % self.thread_id)
     result = ThreadsMethods().invite_user_to_thread(
         authorization=self.thread_auth_headers,
         thread_id=self.thread_id,
         user_id=account_id)
     logging.info('Server returned %s' % result)
     invitation_id = result['response'][0]['id']
     logging.info('Getting messages list from thread %s' % self.thread_id)
     result = MessageMethods(
         self.thread_id).view_messages(authorization=thread_auth_headers)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(403)
     result['response']['message'].lower() | should.contain(
         'is not a member of the thread')
     logging.info('Accepting invitation to a thread %s' % self.thread_id)
     result = ThreadsMethods().accept_invitation_to_thread(
         authorization=thread_auth_headers,
         invitation_id=invitation_id,
         accept=True)
     logging.info('Server returned %s' % result)
     logging.info('Getting messages list from thread %s' % self.thread_id)
     result = MessageMethods(
         self.thread_id).view_messages(authorization=thread_auth_headers)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(200)
Beispiel #3
0
 def test_02_get_last_100_threads(self):
     logging.info('Generating 100 threads')
     for i in range(0, 102):
         sample_thread = self.rand.generate_random_string(10)
         ThreadsMethods().create_sample_thread(
             authorization=self.thread_auth_headers,
             thread_name=sample_thread,
             private=False)
     logging.info('Trying to get last 100 threads')
     result = ThreadsMethods().get_threads(
         authorization=self.thread_auth_headers)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(200)
     len(result['response']['items']) | should.be.equal.to(100)
Beispiel #4
0
 def test_07_create_thread_no_name(self):
     logging.info('Trying to create thread with no name')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers, private=False)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(409)
     result['response']['message'].lower() | should.contain(
         'thread name required')
Beispiel #5
0
 def test_08_create_thread_no_private(self):
     sample_thread = self.rand.get_date(
     ) + self.rand.generate_random_string(10)
     logging.info('Trying to create thread with no private setting')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers, thread_name=sample_thread)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(409)
     result['response']['message'].lower() | should.contain(
         'private required')
Beispiel #6
0
 def test_05_create_thread_name_number(self):
     sample_thread = self.rand.get_date()
     logging.info('Trying to create sample thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] = 422
     result['response']['message'].lower() | should.contain(
         'thread name must not be a number')
Beispiel #7
0
 def test_03_create_thread_name_too_short(self):
     sample_thread = 'a'
     logging.info('Trying to create sample thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] = 422
     result['response']['message'].lower() | should.contain(
         'thread name length must be between 2 and 50 characters')
Beispiel #8
0
 def test_06_create_second_thread_with_same_name(self):
     sample_thread = self.rand.get_date(
     ) + self.rand.generate_random_string(10)
     logging.info('Trying to create sample thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(200)
     self.thread_id = result['response']['id']
     logging.info('Trying to create thread with the same name')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] = 409
     result['response']['message'].lower() | should.contain(
         'thread name already taken')
Beispiel #9
0
 def test_01_create_public_thread(self):
     sample_thread = self.rand.generate_random_string(
         34) + self.rand.get_date()
     logging.info('Trying to create new public thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(200)
     result['response']['createdAt'] | should.be.a(int)
     result['response']['updatedAt'] | should.be.a(int)
     result['response']['id'] | should.be.a(str)
     result['response']['id'] | should.not_be.none
     result['response']['modelType'] | should.be.equal.to('ThreadModel')
     result['response']['name'] | should.be.a(str)
     result['response']['owner'] | should.be.a(str)
     result['response']['users'] | should.be.a(list)
     result['response']['private'] | should.be.a(bool)
     result['response']['private'] | should.be.false
     result['response']['deleted'] | should.be.a(bool)
     self.thread_id = result['response']['id']
     logging.info('Trying to get created thread')
     result = ThreadsMethods().get_thread(authorization=self.thread_headers,
                                          thread_id=self.thread_id)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(200)
     result['response']['createdAt'] | should.be.a(int)
     result['response']['updatedAt'] | should.be.a(int)
     result['response']['id'] | should.be.a(str)
     result['response']['id'] | should.not_be.none
     result['response']['modelType'] | should.be.equal.to('ThreadModel')
     result['response']['name'] | should.be.a(str)
     result['response']['owner'] | should.be.a(str)
     result['response']['users'] | should.be.a(list)
     result['response']['private'] | should.be.a(bool)
     result['response']['private'] | should.be.false
     result['response']['deleted'] | should.be.a(bool)
Beispiel #10
0
 def setUpClass(cls):
     BaseTest.setUpClass()
     account_data = SignupMethods().create_test_account(generate_fields=True)
     cls.account_id = account_data[1]['response']['id']
     data_to_encode = account_data[0]['username'] + ':' + account_data[0]['password']
     encoded_credentials = cls.encoder.encode_data(data_to_encode)
     cls.thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
     sample_thread = cls.rand.generate_random_string(10)
     logging.info('Creating user and sample thread for tests')
     result = ThreadsMethods().create_sample_thread(authorization=cls.thread_auth_headers, thread_name=sample_thread,
                                                    private=False)
     cls.thread_id = result['response']['id']
     cls.thread_to_delete = cls.thread_id
     cls.auth_header = cls.thread_auth_headers
Beispiel #11
0
 def test_10_create_thread_by_non_existing_user(self):
     sample_thread = self.rand.get_date(
     ) + self.rand.generate_random_string(10)
     logging.info('Trying to create thread with private setting as int')
     thread_headers = {
         'Authorization': 'Basic ' + self.rand.generate_random_string(10)
     }
     try:
         result = ThreadsMethods().create_sample_thread(
             authorization=thread_headers, thread_name=sample_thread)
         result | should.be.none
     except JSONDecodeError as e:
         logging.info('Server responded with %s' % e.doc)
         e.doc.lower() | should.contain('unauthorized access')
Beispiel #12
0
 def setUpClass(cls):
     BaseTest.setUpClass()
     account_data = SignupMethods().create_test_account(
         generate_fields=True)[0]
     data_to_encode = account_data['username'] + ':' + account_data[
         'password']
     encoded_credentials = cls.encoder.encode_data(data_to_encode)
     cls.thread_auth_headers = {
         'Authorization': 'Basic ' + encoded_credentials
     }
     sample_thread = cls.rand.generate_random_string(10)
     ThreadsMethods().create_sample_thread(
         authorization=cls.thread_auth_headers,
         thread_name=sample_thread,
         private=False)
Beispiel #13
0
    def test_09_create_thread_private_not_bool(self):
        sample_thread = self.rand.get_date(
        ) + self.rand.generate_random_string(10)
        private = int(self.rand.get_date())
        logging.info('Trying to create thread with private setting as int')
        result = ThreadsMethods().create_sample_thread(
            authorization=self.thread_headers,
            thread_name=sample_thread,
            private=private)
        logging.info('Server responded with %s' % result)
        result['code'] | should.be.equal.to(422)
        result['response']['message'].lower() | should.contain(
            'private should be bool')

        private = self.rand.generate_random_string(10)
        logging.info('Trying to create thread with private setting as string')
        result = ThreadsMethods().create_sample_thread(
            authorization=self.thread_headers,
            thread_name=sample_thread,
            private=private)
        logging.info('Server responded with %s' % result)
        result['code'] | should.be.equal.to(422)
        result['response']['message'].lower() | should.contain(
            'private should be bool')
Beispiel #14
0
 def test_07_create_message_in_private_thread_as_another_not_invited_user(self):
     sample_thread = self.rand.generate_random_string(10)
     result = ThreadsMethods().create_sample_thread(authorization=self.thread_auth_headers,
                                                    thread_name=sample_thread,
                                                    private=True)
     self.thread_id = result['response']['id']
     account_data = SignupMethods().create_test_account(generate_fields=True)
     data_to_encode = account_data[0]['username'] + ':' + account_data[0]['password']
     encoded_credentials = self.encoder.encode_data(data_to_encode)
     thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
     message = self.rand.generate_random_string(50)
     logging.info('Creating sample message as another user in private thread %s' % self.thread_id)
     result = MessageMethods(self.thread_id).send_message_in_thread(authorization=thread_auth_headers,
                                                                    message=message)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(403)
     result['response']['message'].lower() | should.contain('is not a member of the thread')
Beispiel #15
0
 def test_01_get_last_threads(self):
     logging.info('Trying to get last threads')
     result = ThreadsMethods().get_threads(
         authorization=self.thread_auth_headers)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(200)
     result['response']['itemsFound'] | should.be.a(int)
     result['response']['limit'] | should.be.a(int)
     result['response']['limit'] | should.be.equal.to(100)
     len(result['response']['items']) | should.be.higher.than(0)
     len(result['response']['items']) | should.be.lower.than(101)
     result['response']['items'][0]['createdAt'] | should.be.a(int)
     result['response']['items'][0]['updatedAt'] | should.be.a(int)
     result['response']['items'][0]['id'] | should.be.a(str)
     result['response']['items'][0]['id'] | should.not_be.none
     result['response']['items'][0]['modelType'] | should.be.equal.to(
         'ThreadModel')
     result['response']['items'][0]['name'] | should.be.a(str)
     result['response']['items'][0]['owner'] | should.be.a(str)
     result['response']['items'][0]['users'] | should.be.a(list)
     result['response']['items'][0]['private'] | should.be.a(bool)
     result['response']['items'][0]['deleted'] | should.be.a(bool)
Beispiel #16
0
 def tearDown(self):
     if self.thread_id is not None:
         logging.info('Cleaning up, deleting sample thread')
         ThreadsMethods().delete_thread(authorization=self.thread_headers,
                                        thread_id=self.thread_id)
     BaseTest.tearDown(self)
Beispiel #17
0
 def tearDownClass(cls):
     if cls.auth_header is not None and cls.thread_to_delete is not None:
         logging.info('Deleting sample thread created for tests')
         ThreadsMethods().delete_thread(authorization=cls.auth_header, thread_id=cls.thread_to_delete)