Example #1
0
 def test_get_user_with_id(self, user_id: str, name: str):
     response = Request.get(f'user/{user_id}')
     Asserts.assert_code_status(response, 200)
     Asserts.assert_json_value_by_key(response, "username", name)
     Asserts.assert_json_has_no_key(response, "firstName")
     Asserts.assert_json_has_no_key(response, "lastName")
     Asserts.assert_json_has_no_key(response, "email")
Example #2
0
 def test_not_enough_data(self):
     response = Request.post('user')
     Asserts.assert_code_status(response, 400)
     Asserts.assert_response_text(
         response,
         "The following required params are missed: email, password, "
         "username, firstName, lastName")
Example #3
0
    def test_create_user_successfully(self):
        data = {
            'email': self.create_unique_email('test'),
            'password': '******',
            'username': '******',
            'firstName': 'Vitalii',
            'lastName': 'Kotov',
        }

        response = Request.post('user', data)
        Asserts.assert_code_status(response, 200)
        Asserts.assert_json_has_key(response, "id")
Example #4
0
    def test_email_is_not_valid(self):
        data = {
            'email': 'vinkotov',
            'password': '******',
            'username': '******',
            'firstName': 'Vitalii',
            'lastName': 'Kotov',
        }

        response = Request.post('user', data)
        Asserts.assert_code_status(response, 400)
        Asserts.assert_response_text(response, "Invalid email format")
Example #5
0
    def test_no_email(self):
        data = {
            'password': '******',
            'username': '******',
            'firstName': 'Vitalii',
            'lastName': 'Kotov',
        }

        response = Request.post('user', data)
        Asserts.assert_code_status(response, 400)
        Asserts.assert_response_text(
            response, "The following required params are missed: email")
Example #6
0
    def test_username_is_too_short(self):
        data = {
            'email': self.create_unique_email('test'),
            'password': '******',
            'username': '******',
            'firstName': 'Vitalii',
            'lastName': 'Kotov',
        }

        response = Request.post('user', data)
        Asserts.assert_code_status(response, 400)
        Asserts.assert_response_text(
            response, "The value of 'username' field is too short")
Example #7
0
    def test_email_is_already_in_system(self):
        data = {
            'email': '*****@*****.**',
            'password': '******',
            'username': '******',
            'firstName': 'Vitalii',
            'lastName': 'Kotov',
        }

        response = Request.post('user', data)
        Asserts.assert_code_status(response, 400)
        Asserts.assert_response_text(
            response, f"Users with email '{data['email']}' already exists")
Example #8
0
    def test_wrong_data(self):
        data = {'email': '*****@*****.**', 'password': '******'}

        response = Request.post('user/login', data)
        Asserts.assert_code_status(response, 400)
        Asserts.assert_response_text(response,
                                     "Invalid username/password supplied")
        Asserts.assert_response_not_has_cookie(response, 'auth_sid')
        Asserts.assert_response_not_has_headers(response, "x-csrf-token")
Example #9
0
    def test_get_user_with_id(self):
        data = {'email': '*****@*****.**', 'password': '******'}

        response = Request.post('user/login', data)

        Asserts.assert_json_has_key(response, 'user_id')

        auth_cookie = self.get_cookie(response, 'auth_sid')
        auth_header = self.get_header(response, 'x-csrf-token')
        user_id = response.json()['user_id']

        response = Request.get(f'user/{user_id}',
                               headers=auth_header,
                               cookies=auth_cookie)

        Asserts.assert_code_status(response, 200)
        Asserts.assert_json_has_key(response, 'firstName')
        Asserts.assert_json_has_key(response, 'lastName')
        Asserts.assert_json_has_key(response, 'email')
Example #10
0
    def test_auth_successfully(self):
        data = {'email': '*****@*****.**', 'password': '******'}

        response = Request.post('user/login', data)
        Asserts.assert_code_status(response, 200)
        Asserts.assert_response_has_cookie(response, 'auth_sid')
        Asserts.assert_response_has_headers(response, "x-csrf-token")
Example #11
0
    def test_change_created_user_data(self):
        email = self.create_unique_email('vinkotov')
        password = '******'
        username = '******'

        data = {
            'email': email,
            'password': password,
            'username': username,
            'firstName': 'Vitalii',
            'lastName': 'Kotov',
        }

        response = Request.post('user', data)
        user_id_after_registration = response.json()['id']

        response = Request.post('user/login', {
            'password': password,
            'email': email
        })
        user_id_after_auth = response.json()['user_id']

        Asserts.assert_equals(user_id_after_registration, user_id_after_auth,
                              "I've logged in as another user")

        auth_cookie = self.get_cookie(response, 'auth_sid')
        auth_header = self.get_header(response, 'x-csrf-token')

        response = Request.get(f'user/{user_id_after_auth}',
                               headers=auth_header,
                               cookies=auth_cookie)
        Asserts.assert_equals(username,
                              response.json()['username'],
                              "I've logged in as another user")

        new_user_name = "Vitaliy"
        response = Request.put(f'user/{user_id_after_auth}',
                               data={'username': new_user_name},
                               headers=auth_header,
                               cookies=auth_cookie)
        Asserts.assert_code_status(response, 200)

        response = Request.get(f'user/{user_id_after_auth}',
                               headers=auth_header,
                               cookies=auth_cookie)
        Asserts.assert_equals(new_user_name,
                              response.json()['username'],
                              "Couldn't change name via put request")
Example #12
0
    def test_get_user_without_id(self):
        response = Request.get('user')

        Asserts.assert_code_status(response, 400)
        Asserts.assert_response_text(response, "Wrong HTTP method")
        Asserts.assert_time_is_less_than(response, 1)