コード例 #1
0
    def test_patch_results_endpoint_with_advanced_level_authorization_updates_result_data(
            self):
        post_data = {
            'test_id': self.create_test(),
            'time': datetime.datetime.utcnow(),
            'value': 3
        }

        res = self.client().post('/results',
                                 json=post_data,
                                 headers=advanced_auth_header(True))
        data = json.loads(res.data)
        post_result = self.check_if_operation_was_successful_and_get_payload(
            data)

        patch_data = {'value': 4}

        res = self.client().patch('/results/' + str(post_result['id']),
                                  json=patch_data,
                                  headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_was_successful_and_get_payload(data)

        res = self.client().get('/results', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)

        self.assertTrue(len(message['data']) == 1)
        self.assertTrue(message['data'][0]['value'] == patch_data['value'])
コード例 #2
0
    def test_get_user_results_endpoint_with_advanced_level_authorization_returns_list_of_results_of_user(
            self):
        res = self.client().get('/profile', headers=basic_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        user_id = message['id']

        post_data = {
            'test_id': self.create_test(),
            'time': datetime.datetime.utcnow(),
            'value': 3
        }

        self.client().post('/results',
                           json=post_data,
                           headers=basic_auth_header(True))
        self.client().post('/results',
                           json=post_data,
                           headers=basic_auth_header(True))
        self.client().post('/results',
                           json=post_data,
                           headers=basic_auth_header(True))

        res = self.client().get('/users/' + str(user_id) + '/results',
                                headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)

        self.assertTrue(len(message['data']) == 3)
コード例 #3
0
 def test_get_profile_endpoint_with_advanced_level_authorization_returns_user_info(
         self):
     res = self.client().get('/profile', headers=advanced_auth_header())
     data = json.loads(res.data)
     message = self.check_if_operation_was_successful_and_get_payload(data)
     self.assertTrue(message['name'] == 'Unknown')
     self.assertTrue(len(message['tests']) == 0)
コード例 #4
0
 def create_test(self):
     post_data = {'name': 'someName'}
     res = self.client().post('/tests',
                              json=post_data,
                              headers=advanced_auth_header(True))
     data = json.loads(res.data)
     message = self.check_if_operation_was_successful_and_get_payload(data)
     return message['id']
コード例 #5
0
    def test_patch_profile_endpoint_with_advanced_level_authorization_without_name_in_payload_returns_422(
            self):
        patch_data = {}

        res = self.client().patch('/profile',
                                  json=patch_data,
                                  headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_failed_with_error_code(data, 422)
コード例 #6
0
    def test_post_results_endpoint_with_advanced_level_authorization_registers_new_result(
            self):
        post_data = {
            'test_id': self.create_test(),
            'time': datetime.datetime.utcnow(),
            'value': 3
        }

        res = self.client().post('/results',
                                 json=post_data,
                                 headers=advanced_auth_header(True))
        data = json.loads(res.data)
        result = self.check_if_operation_was_successful_and_get_payload(data)

        res = self.client().get('/results', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)

        self.assertTrue(self.is_result_in_list(message['data'], result))
コード例 #7
0
    def test_patch_profile_endpoint_with_advanced_level_authorization_updates_user_info(
            self):
        patch_data = {'name': 'newName'}

        res = self.client().get('/profile', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        self.assertFalse(message['name'] == patch_data['name'])

        res = self.client().patch('/profile',
                                  json=patch_data,
                                  headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_was_successful_and_get_payload(data)

        res = self.client().get('/profile', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        self.assertTrue(message['name'] == patch_data['name'])
コード例 #8
0
    def test_get_users_endpoint_with_advanced_level_authorization_returns_list_of_users(self):
        self.add_data_to_database([
            {'test': 1, 'user': 1, 'data': 10},
            {'test': 2, 'user': 2, 'data': 10}])

        res = self.client().get('/users', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        
        self.assertTrue(len(message) == 3)
コード例 #9
0
    def test_delete_results_endpoint_with_result_id_belonging_to_other_user_throws_403(self):
        post_data = {'test_id': self.create_test(), 'time': datetime.datetime.utcnow(), 'value': 3}

        res = self.client().post('/results', json=post_data, headers=basic_auth_header(True))
        data = json.loads(res.data)
        post_result = self.check_if_operation_was_successful_and_get_payload(data)

        res = self.client().delete('/results/' + str(post_result['id']), headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_failed_with_error_code(data, 403)
コード例 #10
0
    def test_post_tests_endpoint_with_advanced_level_authorization_and_existing_test_name_returns_422(
            self):
        post_data = {'name': 'someName'}

        res = self.client().get('/tests', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        self.assertEqual(len(message), 0)

        res = self.client().post('/tests',
                                 json=post_data,
                                 headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_was_successful_and_get_payload(data)

        res = self.client().post('/tests',
                                 json=post_data,
                                 headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_failed_with_error_code(data, 422)
コード例 #11
0
    def test_post_tests_endpoint_with_advanced_level_authorization_registers_new_test(
            self):
        post_data = {'name': 'someName'}

        res = self.client().get('/tests', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        self.assertEqual(len(message), 0)

        res = self.client().post('/tests',
                                 json=post_data,
                                 headers=advanced_auth_header(True))
        data = json.loads(res.data)
        self.check_if_operation_was_successful_and_get_payload(data)

        res = self.client().get('/tests', headers=advanced_auth_header())
        data = json.loads(res.data)
        message = self.check_if_operation_was_successful_and_get_payload(data)
        self.assertEqual(len(message), 1)
        self.assertTrue(message[0]['name'] == post_data['name'])
コード例 #12
0
 def test_get_results_endpoint_with_advanced_level_authorization_returns_results_of_user(
         self):
     res = self.client().get('/results', headers=advanced_auth_header())
     data = json.loads(res.data)
     message = self.check_if_operation_was_successful_and_get_payload(data)
     self.assertTrue(len(message['data']) == 0)