Example #1
0
    def test_generate_name(self):
        params = {
            "param_1": "param_1_str",
            "param_2": 2,
            "param_3": "param_3_str",
            "param_4": 4
        }

        api_data = {
            "url": "https://jsonplaceholder.typicode.com/comments",
            "method": "get",
            "params": params
        }

        api = API(api_data, Options())
        actual = TestFunctionBuilder._generate_name(api)

        split_to_url_and_parameters = actual.split('?')
        self.assertEqual(len(split_to_url_and_parameters), 2)

        actual_url = split_to_url_and_parameters[0]
        actual_parameters = split_to_url_and_parameters[1]

        expected_url = 'test_%s' % api.url
        self.assertEqual(actual_url, expected_url)

        actual_parameter_list = actual_parameters.split('&')
        expected_parameter_list = [
            '%s=%s' % (key, value) for key, value in params.items()
        ]

        self.assertTrue(
            are_equal_lists(actual_parameter_list, expected_parameter_list))
Example #2
0
    def test_insecure(self):
        insecure = True
        options = Options(insecure=insecure)

        expected = insecure

        self.assertEqual(expected, options.insecure)
Example #3
0
    def generate_test_function(json_file):
        json_data = load_json_data(json_file)

        setting = TestSetting(json_data, Options())

        builder = MultipleTargetsTestFunctionBuilder(setting)
        return builder.build()
    def test_main_fail(self):
        test_suites_dir = '%s/resources_fail/' % self.current_dir_path

        options = Options(base_url=None)

        generate_test_functions(TestsContainerFail, test_suites_dir, options)
        self.assertFalse(run_test_functions(TestsContainerFail))
    def test_main_success(self):
        test_suites_dir = '%s/resources_success/' % self.current_dir_path

        options = Options(base_url=None)

        generate_test_functions(TestsContainerSuccess, test_suites_dir,
                                options)
        self.assertTrue(run_test_functions(TestsContainerSuccess))
Example #6
0
    def test_add_base_url(self):
        base_url = 'http://localhost:3000'
        test_suites_dir = '%s/resources/' % self.current_dir_path

        options = Options(base_url=base_url)

        generate_test_functions(TestsContainer, test_suites_dir, options)
        self.assertTrue(run_test_functions(TestsContainer))
Example #7
0
    def test_single(self):
        json_file = '%s/resources/test_function_init_single.json' % self.current_dir_path
        json_data = load_json_data(json_file)

        setting = TestSetting(json_data, Options())

        builder = TestFunctionBuilderFactory.get_builder(setting)
        self.assertTrue(isinstance(builder, SingleTargetTestFunctionBuilder))
Example #8
0
    def test_read_authentication(self):
        user = '******'
        password = '******'

        actual = Options._read_authentication(user + ':' + password)
        expected = (user, password)

        self.assertEqual(expected, actual)
Example #9
0
    def test_auth(self):
        user = '******'
        password = '******'

        options = Options(auth=user + ':' + password)

        expected = (user, password)

        self.assertEqual(expected, options.auth)
    def test_target(self):
        json_file = '%s/resources/test_target.json' % self.current_dir_path
        json_data = load_json_data(json_file)

        test_target = TestTarget(json_data, Options())

        self.assertEqual(json_data[TestTarget.KEY_API],
                         convert_api_to_dict(test_target.api))
        self.assertEqual(json_data[TestTarget.KEY_TESTS],
                         convert_tests_to_dict(test_target.tests))
Example #11
0
    def test_single(self):
        json_file = '%s/resources/test_setting_single.json' % self.current_dir_path
        json_data = load_json_data(json_file)

        setting = TestSetting(json_data, Options())

        self.assertFalse(setting.has_multiple_targets())

        self.assertEqual(json_data[TestTarget.KEY_API],
                         convert_api_to_dict(setting.targets[0].api))
        self.assertEqual(json_data[TestTarget.KEY_TESTS],
                         convert_tests_to_dict(setting.targets[0].tests))
Example #12
0
    def test_multiple(self):
        json_file = '%s/resources/test_setting_multiple.json' % self.current_dir_path
        json_data = load_json_data(json_file)

        setting = TestSetting(json_data, Options())

        self.assertTrue(setting.has_multiple_targets())

        for idx, target in enumerate(setting.targets):
            self.assertEqual(json_data[idx][TestTarget.KEY_API],
                             convert_api_to_dict(target.api))
            self.assertEqual(json_data[idx][TestTarget.KEY_TESTS],
                             convert_tests_to_dict(target.tests))
Example #13
0
    def test_generate_name_no_param(self):
        api_data = {
            "url": "https://jsonplaceholder.typicode.com/comments",
            "method": "get",
            "params": {}
        }

        api = API(api_data, Options())

        actual = TestFunctionBuilder._generate_name(api)
        expected = 'test_%s' % api.url

        self.assertEqual(actual, expected)
Example #14
0
    def test_insecure_default(self):
        options = Options()

        self.assertFalse(options.insecure)
Example #15
0
    def test_read_authentication_fail(self):
        user = '******'
        password = '******'

        with self.assertRaises(AuthenticationError):
            Options._read_authentication(user + password)
    def test_target_missing_response(self):
        json_file = '%s/resources/test_target_missing_response.json' % self.current_dir_path
        json_data = load_json_data(json_file)

        with self.assertRaises(IncompleteTargetInformationError):
            TestTarget(json_data, Options())
Example #17
0
    def test_base_url(self):
        base_url = 'http://localhost:3000'

        options = Options(base_url=base_url)
        self.assertEqual(base_url, options.base_url)