コード例 #1
0
class SignupMethods:
    rand = RandomGenerator()
    rm = RequestManager()
    CONFIG = ConfigReader().load_configuration_from_file('configuration.json')
    url = CONFIG['API_ADDRESS'] + '/signup'
    headers = {'Content-Type': 'application/vnd.api+json'}

    def create_test_account(self,
                            unique_username=True,
                            generate_fields=False,
                            user_name=None,
                            password=None,
                            firstname=None,
                            lastname=None):
        if unique_username:
            username = '******' + self.rand.get_date()
        else:
            username = user_name
        if generate_fields:
            password = self.rand.generate_random_string(10)
            firstname = self.rand.generate_random_string(10)
            lastname = self.rand.generate_random_string(10)
        data = {
            "username": username,
            "password": password,
            "firstname": firstname,
            "lastname": lastname
        }
        result = self.rm.post_request(url=self.url,
                                      data=data,
                                      headers=self.headers)
        return [data, result]
コード例 #2
0
class MessageMethods:

    rand = RandomGenerator()
    rm = RequestManager()

    def __init__(self, thread_id):
        self.thread_id = thread_id
        CONFIG = ConfigReader().load_configuration_from_file(
            'configuration.json')
        self.url = CONFIG[
            'API_ADDRESS'] + '/threads/id/' + self.thread_id + '/messages'
        self.message_url = self.url + '/id/'

    def view_messages(self, authorization):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        result = self.rm.get_request(self.url, headers=headers)
        return result

    def send_message_in_thread(self, authorization, message=None):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        data = {"message": message}
        result = self.rm.post_request(url=self.url, headers=headers, data=data)
        return result
コード例 #3
0
class ThreadsMethods:
    rand = RandomGenerator()
    rm = RequestManager()
    CONFIG = ConfigReader().load_configuration_from_file('configuration.json')
    url = CONFIG['API_ADDRESS'] + '/threads'
    thread_url = CONFIG['API_ADDRESS'] + '/threads/id'

    def get_threads(self, authorization):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        result = self.rm.get_request(self.url, headers=headers)
        return result

    def create_sample_thread(self,
                             authorization,
                             thread_name=None,
                             private=None):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        data = {"name": thread_name, "private": private}
        result = self.rm.post_request(url=self.url, headers=headers, data=data)
        return result

    def get_thread(self, authorization, thread_id):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        result = self.rm.get_request(url=self.thread_url + '/' + thread_id,
                                     headers=headers)
        return result

    def delete_thread(self, authorization, thread_id):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        result = self.rm.delete_request(url=self.thread_url + '/' + thread_id,
                                        headers=headers)
        return result

    def invite_user_to_thread(self, authorization, thread_id, user_id):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        data = {"users": user_id}
        result = self.rm.post_request(url=self.thread_url + '/' + thread_id +
                                      '/invite',
                                      headers=headers,
                                      data=data)
        return result

    def accept_invitation_to_thread(self,
                                    authorization,
                                    invitation_id,
                                    accept=True):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        data = {"accept": accept}
        result = self.rm.post_request(url=self.url + '/invitations/id/' +
                                      invitation_id,
                                      headers=headers,
                                      data=data)
        return result

    def kick_user_from_thread(self, authorization, thread_id, user_id):
        headers = authorization
        headers['Content-Type'] = 'application/json'
        data = {"users": user_id}
        result = self.rm.post_request(url=self.thread_url + '/' + thread_id +
                                      '/kick',
                                      headers=headers,
                                      data=data)
        return result
コード例 #4
0
class ViewThreadsTest(BaseTest):
    rand = RandomGenerator()
    rm = RequestManager()
    encoder = Encoder()

    @classmethod
    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)

    def setUp(self):
        BaseTest.setUp(self)
        self.threads_url = self.CONFIG['API_ADDRESS'] + '/threads'

    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)

    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)
コード例 #5
0
class CreateMessagesTest(BaseTest):
    rand = RandomGenerator()
    rm = RequestManager()
    encoder = Encoder()
    auth_header = None
    thread_to_delete = None

    @classmethod
    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

    def setUp(self):
        BaseTest.setUp(self)

    def test_01_create_max_long_message(self):
        message = self.rand.generate_random_string(300)
        logging.info('Creating sample message in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers,
                                                                       message=message)
        logging.info('Server returned %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('ThreadMessageModel')
        result['response']['user'] | should.be.a(str)
        result['response']['user'] | should.be.equal.to(self.account_id)
        result['response']['thread'] | should.be.a(str)
        result['response']['thread'] | should.be.equal.to(self.thread_id)
        result['response']['message'] | should.be.a(str)
        result['response']['message'] | should.be.equal.to(message)
        result['response']['deleted'] | should.be.a(bool)
        result['response']['deleted'] | should.be.equal.to(False)

    def test_02_create_min_long_message(self):
        message = self.rand.generate_random_string(1)
        logging.info('Creating sample message in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers,
                                                                       message=message)
        logging.info('Server returned %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('ThreadMessageModel')
        result['response']['user'] | should.be.a(str)
        result['response']['user'] | should.be.equal.to(self.account_id)
        result['response']['thread'] | should.be.a(str)
        result['response']['thread'] | should.be.equal.to(self.thread_id)
        result['response']['message'] | should.be.a(str)
        result['response']['message'] | should.be.equal.to(message)
        result['response']['deleted'] | should.be.a(bool)
        result['response']['deleted'] | should.be.equal.to(False)

    def test_03_create_too_short_message(self):
        message = ''
        logging.info('Creating sample message in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers,
                                                                       message=message)
        logging.info('Server returned %s' % result)
        result['code'] = 422
        result['response']['message'].lower() | should.contain('text has to be between 1 and 300 characters')

    def test_04_create_too_long_message(self):
        message = self.rand.generate_random_string(301)
        logging.info('Creating sample message in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers,
                                                                       message=message)
        logging.info('Server returned %s' % result)
        result['code'] = 422
        result['response']['message'].lower() | should.contain('text has to be between 1 and 300 characters')

    def test_05_create_message_no_message(self):
        logging.info('Creating sample message without message in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers)
        logging.info('Server returned %s' % result)
        result['code'] | should.be.equal.to(409)
        result['response']['message'].lower() | should.contain('text required')

    def test_06_create_message_in_public_thread_as_another_not_invited_user(self):
        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 public 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_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')

    def test_08_create_message_by_non_existing_user(self):
        logging.info('Creating sample message by non existing user in public thread %s' % self.thread_id)
        thread_auth_headers = {'Authorization': 'Basic ' + self.rand.generate_random_string(10)}
        message = self.rand.generate_random_string(50)
        try:
            result = MessageMethods(self.thread_id).send_message_in_thread(authorization=thread_auth_headers,
                                                                           message=message)
            result | should.be.none
        except JSONDecodeError as e:
            logging.info('Server responded with %s' % e.doc)
            e.doc.lower() | should.contain('unauthorized access')

    def test_09_create_message_by_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']
        message = self.rand.generate_random_string(50)
        logging.info('Creating sample message as invited 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')
        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('Creating sample message as invited and accepted 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(200)

    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')

    @classmethod
    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)
コード例 #6
0
class SignupTest(BaseTest):
    rand = RandomGenerator()
    rm = RequestManager()

    def setUp(self):
        BaseTest.setUp(self)
        self.url = self.CONFIG['API_ADDRESS'] + '/signup'
        self.headers = {'Content-Type': 'application/vnd.api+json'}
        self.signup = SignupMethods()

    def test_01_add_new_account_min_allowable_chars(self):
        password = self.rand.generate_random_string(4)
        first_name = self.rand.generate_random_string(2)
        last_name = self.rand.generate_random_string(2)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(200)
        result[1]['response']['id'] | should.not_be.none
        result[1]['response']['id'] | should.be.a(str)
        result[1]['response']['firstname'] | should.be.equal.to(
            result[0]['firstname'])
        result[1]['response']['lastname'] | should.be.equal.to(
            result[0]['lastname'])
        result[1]['response']['username'] | should.be.equal.to(
            result[0]['username'])
        result[1]['response']['createdAt'] | should.not_be.none
        result[1]['response']['createdAt'] | should.be.a(int)
        result[1]['response']['updatedAt'] | should.not_be.none
        result[1]['response']['updatedAt'] | should.be.a(int)
        result[1]['response']['modelType'] | should.be.equal.to('UserModel')

    def test_02_add_new_account_max_allowable_chars(self):
        password = self.rand.generate_random_string(20)
        first_name = self.rand.generate_random_string(20)
        last_name = self.rand.generate_random_string(50)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(200)
        result[1]['response']['id'] | should.not_be.none
        result[1]['response']['id'] | should.be.a(str)
        result[1]['response']['firstname'] | should.be.equal.to(
            result[0]['firstname'])
        result[1]['response']['lastname'] | should.be.equal.to(
            result[0]['lastname'])
        result[1]['response']['username'] | should.be.equal.to(
            result[0]['username'])
        result[1]['response']['createdAt'] | should.not_be.none
        result[1]['response']['createdAt'] | should.be.a(int)
        result[1]['response']['updatedAt'] | should.not_be.none
        result[1]['response']['updatedAt'] | should.be.a(int)
        result[1]['response']['modelType'] | should.be.equal.to('UserModel')

    def test_03_add_account_same_login(self):
        username = '******' + self.rand.get_date()
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with login %s' % username)
        result = self.signup.create_test_account(unique_username=False,
                                                 user_name=username,
                                                 password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        logging.info('Trying to create same test user with login %s' %
                     username)
        result = self.signup.create_test_account(unique_username=False,
                                                 user_name=username,
                                                 password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(409)
        result[1]['response']['message'].lower() | should.contain(
            'username already taken')

    def test_04_add_account_login_too_short(self):
        username = '******'
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with login %s' % username)
        result = self.signup.create_test_account(unique_username=False,
                                                 user_name=username,
                                                 password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'username length must be between 2 and 20 characters')

    def test_05_add_account_too_long_login(self):
        username = '******' + self.rand.get_date()
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with login %s' % username)
        result = self.signup.create_test_account(unique_username=False,
                                                 user_name=username,
                                                 password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'username length must be between 2 and 20 characters')

    def test_06_add_account_no_login(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with empty login %s')
        result = self.signup.create_test_account(unique_username=False,
                                                 password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(409)
        result[1]['response']['message'].lower() | should.contain(
            'username required')

    def test_07_add_account_no_password(self):
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with no password')
        result = self.signup.create_test_account(unique_username=True,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(409)
        result[1]['response']['message'].lower() | should.contain(
            'password required')

    def test_08_add_account_no_firstname(self):
        password = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with no password')
        result = self.signup.create_test_account(unique_username=True,
                                                 password=password,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(409)
        result[1]['response']['message'].lower() | should.contain(
            'firstname required')

    def test_09_add_account_no_lastname(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user with no password')
        result = self.signup.create_test_account(unique_username=True,
                                                 password=password,
                                                 firstname=first_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(409)
        result[1]['response']['message'].lower() | should.contain(
            'firstname required')

    def test_10_add_account_pass_too_short(self):
        password = self.rand.generate_random_string(3)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'password length must be between 4 and 20 characters')

    def test_11_add_account_pass_too_long(self):
        password = self.rand.generate_random_string(21)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'password length must be between 4 and 20 characters')

    def test_12_add_account_firstname_too_short(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(1)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'first name length must be between 2 and 20 '
            'characters')

    def test_13_add_account_firstname_too_long(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(21)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'first name length must be between 2 and 20 '
            'characters')

    def test_14_add_account_lastname_too_short(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(1)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'last name length must be between 2 and 50 '
            'characters')

    def test_15_add_account_lastname_too_long(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(51)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'last name length must be between 2 and 50 '
            'characters')

    def test_16_add_account_username_not_string(self):
        username = self.rand.get_date()
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(unique_username=False,
                                                 user_name=username,
                                                 password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['code'] | should.be.equal.to(422)
        result[1]['response']['message'].lower() | should.contain(
            'username must not be a number')

    def test_17_add_second_account_check_user_id(self):
        password = self.rand.generate_random_string(5)
        first_name = self.rand.generate_random_string(5)
        last_name = self.rand.generate_random_string(5)
        logging.info('Trying to create new test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        user_id = result[1]['response']['id']
        logging.info('Trying to create another test user')
        result = self.signup.create_test_account(password=password,
                                                 firstname=first_name,
                                                 lastname=last_name)
        logging.info('Server responded with %s' % result[1])
        result[1]['response']['id'] | should.not_be.equal.to(user_id)
コード例 #7
0
class CreateThreadsTest(BaseTest):
    rand = RandomGenerator()
    rm = RequestManager()
    encoder = Encoder()

    @classmethod
    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_headers = {'Authorization': 'Basic ' + encoded_credentials}

    def setUp(self):
        BaseTest.setUp(self)
        self.threads_url = self.CONFIG['API_ADDRESS'] + '/threads'
        self.thread_id = None

    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)

    def test_02_create_private_thread(self):
        sample_thread = self.rand.generate_random_string(10)
        logging.info('Trying to create new private thread')
        result = ThreadsMethods().create_sample_thread(
            authorization=self.thread_headers,
            thread_name=sample_thread,
            private=True)
        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.true
        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.true
        result['response']['deleted'] | should.be.a(bool)

    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')

    def test_04_create_thread_name_too_long(self):
        sample_thread = self.rand.get_date(
        ) + self.rand.generate_random_string(35)
        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')

    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')

    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')

    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')

    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')

    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')

    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')

    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)
コード例 #8
0
class ViewMessagesTest(BaseTest):
    rand = RandomGenerator()
    rm = RequestManager()
    encoder = Encoder()

    @classmethod
    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)
        result = ThreadsMethods().create_sample_thread(
            authorization=cls.thread_auth_headers,
            thread_name=sample_thread,
            private=False)
        cls.thread_id = result['response']['id']

    def setUp(self):
        BaseTest.setUp(self)

    def test_01_view_message(self):
        message = self.rand.generate_random_string(50)
        logging.info('Creating sample message in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(
            authorization=self.thread_auth_headers, message=message)
        logging.info('Server returned %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(
            'ThreadMessageModel')
        result['response']['user'] | should.be.a(str)
        result['response']['user'] | should.be.equal.to(self.account_id)
        result['response']['thread'] | should.be.a(str)
        result['response']['thread'] | should.be.equal.to(self.thread_id)
        result['response']['message'] | should.be.a(str)
        result['response']['message'] | should.be.equal.to(message)
        result['response']['deleted'] | should.be.a(bool)
        result['response']['deleted'] | should.be.equal.to(False)
        logging.info('Getting messages list from thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).view_messages(
            authorization=self.thread_auth_headers)
        logging.info('Server returned %s' % result)
        result['code'] | should.be.equal.to(200)
        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(
            'ThreadMessageModel')
        result['response']['items'][0]['user'] | should.be.a(str)
        result['response']['items'][0]['user'] | should.be.equal.to(
            self.account_id)
        result['response']['items'][0]['thread'] | should.be.a(str)
        result['response']['items'][0]['thread'] | should.be.equal.to(
            self.thread_id)
        result['response']['items'][0]['message'] | should.be.a(str)
        result['response']['items'][0]['message'] | should.be.equal.to(message)
        result['response']['items'][0]['deleted'] | should.be.a(bool)
        result['response']['items'][0]['deleted'] | should.be.equal.to(False)

    def test_02_view_last_100_messages(self):
        logging.info('Creating 100 sample messages in thread %s' %
                     self.thread_id)
        for i in range(0, 102):
            message = self.rand.generate_random_string(300)
            MessageMethods(self.thread_id).send_message_in_thread(
                authorization=self.thread_auth_headers, message=message)
        logging.info('Getting messages list from thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).view_messages(
            authorization=self.thread_auth_headers)
        logging.info('Server returned %s' % result)
        result['code'] | should.be.equal.to(200)
        len(result['response']['items']) | should.be.equal.to(100)

    def test_03_view_messages_as_non_invited_user(self):
        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}
        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')

    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)

    def test_05_view_messages_as_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)
        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')