Module data_request_api.tests.test_dump_transformation

Test dump_transformation.py

Classes

class TestCorrectDictionaries (methodName='runTest')
Expand source code
class TestCorrectDictionaries(unittest.TestCase):
    def test_correct(self):
        dict_1 = {"Test1": "dummy1", "&test2": "Dummy2&"}
        new_dict_1 = {"test1": "dummy1", "andtest2": "Dummy2&"}
        self.assertDictEqual(correct_dictionaries(dict_1), new_dict_1)

        dict_2 = {
            "test&1": ["dummy1", "DuMmy2"],
            "TesT 2": {
                "record&1": {"test 1": "Test2"},
                "Record2": {"dummy_1": "&dummy2"},
                "records": {
                    "test 1": "dummy&",
                    "&tesT2": "Dummy2"
                }
            },
            "test3 ": 4
        }
        new_dict_2 = {
            "testand1": ["dummy1", "DuMmy2"],
            "test_2": {
                "recordand1": {"test_1": "Test2"},
                "record2": {"dummy_1": "&dummy2"},
                "records": {
                    "test 1": "dummy&",
                    "&tesT2": "Dummy2"
                }
            },
            "test3": 4
        }
        self.assertDictEqual(correct_dictionaries(dict_2), new_dict_2)

    def test_error(self):
        with self.assertRaises(TypeError):
            correct_dictionaries(4)

        with self.assertRaises(TypeError):
            correct_dictionaries(["dummy", "test"])

        with self.assertRaises(TypeError):
            correct_dictionaries("test")

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • unittest.case.TestCase

Methods

def test_correct(self)
Expand source code
def test_correct(self):
    dict_1 = {"Test1": "dummy1", "&test2": "Dummy2&"}
    new_dict_1 = {"test1": "dummy1", "andtest2": "Dummy2&"}
    self.assertDictEqual(correct_dictionaries(dict_1), new_dict_1)

    dict_2 = {
        "test&1": ["dummy1", "DuMmy2"],
        "TesT 2": {
            "record&1": {"test 1": "Test2"},
            "Record2": {"dummy_1": "&dummy2"},
            "records": {
                "test 1": "dummy&",
                "&tesT2": "Dummy2"
            }
        },
        "test3 ": 4
    }
    new_dict_2 = {
        "testand1": ["dummy1", "DuMmy2"],
        "test_2": {
            "recordand1": {"test_1": "Test2"},
            "record2": {"dummy_1": "&dummy2"},
            "records": {
                "test 1": "dummy&",
                "&tesT2": "Dummy2"
            }
        },
        "test3": 4
    }
    self.assertDictEqual(correct_dictionaries(dict_2), new_dict_2)
def test_error(self)
Expand source code
def test_error(self):
    with self.assertRaises(TypeError):
        correct_dictionaries(4)

    with self.assertRaises(TypeError):
        correct_dictionaries(["dummy", "test"])

    with self.assertRaises(TypeError):
        correct_dictionaries("test")
class TestCorrectKeyString (methodName='runTest')
Expand source code
class TestCorrectKeyString(unittest.TestCase):
    def test_correct(self):
        self.assertEqual(correct_key_string("  This is a test & some specific chars. "),
                         "this_is_a_test_and_some_specific_chars.")
        self.assertEqual(correct_key_string("A string with elements to remove. DumMy test", "dummy", "Test"),
                         "a_string_with_elements_to_remove.")

    def test_error(self):
        with self.assertRaises(TypeError):
            correct_key_string(4)

        with self.assertRaises(TypeError):
            correct_key_string(["dummy", "test"])

        with self.assertRaises(TypeError):
            correct_key_string(dict(test="dummy"))

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • unittest.case.TestCase

Methods

def test_correct(self)
Expand source code
def test_correct(self):
    self.assertEqual(correct_key_string("  This is a test & some specific chars. "),
                     "this_is_a_test_and_some_specific_chars.")
    self.assertEqual(correct_key_string("A string with elements to remove. DumMy test", "dummy", "Test"),
                     "a_string_with_elements_to_remove.")
def test_error(self)
Expand source code
def test_error(self):
    with self.assertRaises(TypeError):
        correct_key_string(4)

    with self.assertRaises(TypeError):
        correct_key_string(["dummy", "test"])

    with self.assertRaises(TypeError):
        correct_key_string(dict(test="dummy"))
class TestTransformContent (methodName='runTest')
Expand source code
class TestTransformContent(unittest.TestCase):
    def setUp(self):
        self.version = "test"
        self.one_base_input = read_json_file(filepath("one_base_input.json"))
        self.one_base_output_format = read_json_file(filepath("one_base_output_format.json"))
        self.one_base_output_transform = read_json_file(filepath("one_base_output_transform.json"))
        self.one_base_VS_output = read_json_file(filepath("one_base_VS_output.json"))
        self.one_base_DR_output = read_json_file(filepath("one_base_DR_output.json"))
        self.one_base_VS_output_noversion = copy.deepcopy(self.one_base_VS_output)
        del self.one_base_VS_output_noversion["version"]
        self.one_base_DR_output_noversion = copy.deepcopy(self.one_base_DR_output)
        del self.one_base_DR_output_noversion["version"]
        self.several_bases_input = read_json_file(filepath("several_bases_input.json"))
        self.several_bases_output_format = read_json_file(filepath("several_bases_output_format.json"))
        self.several_bases_output_transform = read_json_file(filepath("several_bases_output_transform.json"))
        self.several_bases_VS_output = read_json_file(filepath("several_bases_VS_output.json"))
        self.several_bases_DR_output = read_json_file(filepath("several_bases_DR_output.json"))
        self.several_bases_VS_output_noversion = copy.deepcopy(self.several_bases_VS_output)
        del self.several_bases_VS_output_noversion["version"]
        self.several_bases_DR_output_noversion = copy.deepcopy(self.several_bases_DR_output)
        del self.several_bases_DR_output_noversion["version"]
        self.transform_settings = get_transform_settings(self.version)

    def test_one_base_correct(self):
        format_output = correct_dictionaries(self.one_base_input)
        self.assertDictEqual(format_output, self.one_base_output_format)
        transform_output = transform_content_inner(format_output, get_transform_settings(self.version)["one_to_transform"])
        self.assertDictEqual(transform_output, self.one_base_output_transform)
        DR_output, VS_output = split_content_one_base(transform_output)
        self.assertDictEqual(DR_output, self.one_base_DR_output_noversion)
        self.assertDictEqual(VS_output, self.one_base_VS_output_noversion)

    def test_all_correct_from_one(self):
        DR_output, VS_output = transform_content(self.one_base_input, version=self.version)
        self.assertDictEqual(DR_output, self.one_base_DR_output)
        self.assertDictEqual(VS_output, self.one_base_VS_output)

    def test_several_bases_correct(self):
        format_output = correct_dictionaries(self.several_bases_input)
        self.assertDictEqual(format_output, self.several_bases_output_format)
        transform_output = transform_content_inner(format_output, self.transform_settings["several_to_transform"], change_tables=True)
        self.assertDictEqual(transform_output, self.several_bases_output_transform)
        DR_output, VS_output = split_content_one_base(transform_output)
        self.assertDictEqual(DR_output, self.several_bases_DR_output_noversion)
        self.assertDictEqual(VS_output, self.several_bases_VS_output_noversion)

    def test_all_correct_from_several(self):
        DR_output, VS_output = transform_content(self.several_bases_input, version=self.version)
        self.assertDictEqual(DR_output, self.several_bases_DR_output)
        self.assertDictEqual(VS_output, self.several_bases_VS_output)

    def test_transform_inner_error(self):
        with self.assertRaises(TypeError):
            transform_content_inner(self.several_bases_input)

        with self.assertRaises(TypeError):
            transform_content_inner(self.one_base_input)

        with self.assertRaises(TypeError):
            transform_content_inner(["dummy", "test"])

        with self.assertRaises(ValueError):
            transform_content_inner(self.several_bases_input, self.transform_settings["one_to_transform"])

        with self.assertRaises(TypeError):
            transform_content_inner(["dummy", "test"], self.transform_settings["one_to_transform"])

        with self.assertRaises(ValueError):
            transform_content_inner(self.several_bases_input, self.transform_settings["several_to_transform"])

        with self.assertRaises(TypeError):
            transform_content_inner(["dummy", "test"], self.transform_settings["several_to_transform"])

    def test_all_error(self):
        with self.assertRaises(TypeError):
            transform_content(self.one_base_input)

        with self.assertRaises(TypeError):
            transform_content(["dummy", "test"], version="test")

        with self.assertRaises(TypeError):
            transform_content(4, version="test")

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the init method, the base class init method must always be called. It is important that subclasses should not change the signature of their init method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Ancestors

  • unittest.case.TestCase

Methods

def setUp(self)
Expand source code
def setUp(self):
    self.version = "test"
    self.one_base_input = read_json_file(filepath("one_base_input.json"))
    self.one_base_output_format = read_json_file(filepath("one_base_output_format.json"))
    self.one_base_output_transform = read_json_file(filepath("one_base_output_transform.json"))
    self.one_base_VS_output = read_json_file(filepath("one_base_VS_output.json"))
    self.one_base_DR_output = read_json_file(filepath("one_base_DR_output.json"))
    self.one_base_VS_output_noversion = copy.deepcopy(self.one_base_VS_output)
    del self.one_base_VS_output_noversion["version"]
    self.one_base_DR_output_noversion = copy.deepcopy(self.one_base_DR_output)
    del self.one_base_DR_output_noversion["version"]
    self.several_bases_input = read_json_file(filepath("several_bases_input.json"))
    self.several_bases_output_format = read_json_file(filepath("several_bases_output_format.json"))
    self.several_bases_output_transform = read_json_file(filepath("several_bases_output_transform.json"))
    self.several_bases_VS_output = read_json_file(filepath("several_bases_VS_output.json"))
    self.several_bases_DR_output = read_json_file(filepath("several_bases_DR_output.json"))
    self.several_bases_VS_output_noversion = copy.deepcopy(self.several_bases_VS_output)
    del self.several_bases_VS_output_noversion["version"]
    self.several_bases_DR_output_noversion = copy.deepcopy(self.several_bases_DR_output)
    del self.several_bases_DR_output_noversion["version"]
    self.transform_settings = get_transform_settings(self.version)

Hook method for setting up the test fixture before exercising it.

def test_all_correct_from_one(self)
Expand source code
def test_all_correct_from_one(self):
    DR_output, VS_output = transform_content(self.one_base_input, version=self.version)
    self.assertDictEqual(DR_output, self.one_base_DR_output)
    self.assertDictEqual(VS_output, self.one_base_VS_output)
def test_all_correct_from_several(self)
Expand source code
def test_all_correct_from_several(self):
    DR_output, VS_output = transform_content(self.several_bases_input, version=self.version)
    self.assertDictEqual(DR_output, self.several_bases_DR_output)
    self.assertDictEqual(VS_output, self.several_bases_VS_output)
def test_all_error(self)
Expand source code
def test_all_error(self):
    with self.assertRaises(TypeError):
        transform_content(self.one_base_input)

    with self.assertRaises(TypeError):
        transform_content(["dummy", "test"], version="test")

    with self.assertRaises(TypeError):
        transform_content(4, version="test")
def test_one_base_correct(self)
Expand source code
def test_one_base_correct(self):
    format_output = correct_dictionaries(self.one_base_input)
    self.assertDictEqual(format_output, self.one_base_output_format)
    transform_output = transform_content_inner(format_output, get_transform_settings(self.version)["one_to_transform"])
    self.assertDictEqual(transform_output, self.one_base_output_transform)
    DR_output, VS_output = split_content_one_base(transform_output)
    self.assertDictEqual(DR_output, self.one_base_DR_output_noversion)
    self.assertDictEqual(VS_output, self.one_base_VS_output_noversion)
def test_several_bases_correct(self)
Expand source code
def test_several_bases_correct(self):
    format_output = correct_dictionaries(self.several_bases_input)
    self.assertDictEqual(format_output, self.several_bases_output_format)
    transform_output = transform_content_inner(format_output, self.transform_settings["several_to_transform"], change_tables=True)
    self.assertDictEqual(transform_output, self.several_bases_output_transform)
    DR_output, VS_output = split_content_one_base(transform_output)
    self.assertDictEqual(DR_output, self.several_bases_DR_output_noversion)
    self.assertDictEqual(VS_output, self.several_bases_VS_output_noversion)
def test_transform_inner_error(self)
Expand source code
def test_transform_inner_error(self):
    with self.assertRaises(TypeError):
        transform_content_inner(self.several_bases_input)

    with self.assertRaises(TypeError):
        transform_content_inner(self.one_base_input)

    with self.assertRaises(TypeError):
        transform_content_inner(["dummy", "test"])

    with self.assertRaises(ValueError):
        transform_content_inner(self.several_bases_input, self.transform_settings["one_to_transform"])

    with self.assertRaises(TypeError):
        transform_content_inner(["dummy", "test"], self.transform_settings["one_to_transform"])

    with self.assertRaises(ValueError):
        transform_content_inner(self.several_bases_input, self.transform_settings["several_to_transform"])

    with self.assertRaises(TypeError):
        transform_content_inner(["dummy", "test"], self.transform_settings["several_to_transform"])