oaebu_workflows.tests.test_onix_utils

Module Contents

Classes

TestOnixTransformer

Tests for the ONIX transformer end to end

TestOnixFunctions

Tests for the ONIX telescope

TestCreatePersonnameFields

A class whose instances are single test cases.

TestNormaliseRelatedProducts

Contains tests for normalise_related_products and elevate_product_identifiers

TestElevateRelatedProducts

A class whose instances are single test cases.

TestFilterThroughSchema

A class whose instances are single test cases.

TestRemoveInvalidProducts

A class whose instances are single test cases.

TestFindOnixProduct

A class whose instances are single test cases.

TestDeduplicateRelatedProducts

A class whose instances are single test cases.

Attributes

FIXTURES_FOLDER

oaebu_workflows.tests.test_onix_utils.FIXTURES_FOLDER[source]
class oaebu_workflows.tests.test_onix_utils.TestOnixTransformer[source]

Bases: observatory.platform.observatory_environment.ObservatoryTestCase

Tests for the ONIX transformer end to end

filtered_name = 'filtered.xml'[source]
errors_removed_name = 'errors_removed.xml'[source]
normalised_name = 'normalised.xml'[source]
deduplicated_name = 'deduplicated.xml'[source]
elevated_name = 'elevated.xml'[source]
parsed_name = 'full.jsonl'[source]
apply_names_name = 'name_applied.jsonl'[source]
collapsed_name = 'collapsed.jsonl'[source]
test_input_metadata[source]
test_output_parse_only[source]
test_output_metadata[source]
test_e2e()[source]
test_save_formats()[source]

Tests that each of the posible save formats works

class oaebu_workflows.tests.test_onix_utils.TestOnixFunctions[source]

Bases: observatory.platform.observatory_environment.ObservatoryTestCase

Tests for the ONIX telescope

test_onix_parser_download_execute()[source]

Tests the onix_parser_download and onix_parser_execute functions

test_collapse_subjects()[source]

Tests the thoth_collapse_subjects function

class oaebu_workflows.tests.test_onix_utils.TestCreatePersonnameFields(methodName='runTest')[source]

Bases: unittest.TestCase

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.

test_populate_personname_field()[source]

Given a list of ONIX products with Contributors that have both NamesBeforeKey and KeyNames fields, the function should populate the PersonName field with the concatenation of NamesBeforeKey and KeyNames, and also populate the PersonNameInverted field with the concatenation of KeyNames and NamesBeforeKey

test_no_modification()[source]

Should not modify when there is not enough information to populate PersonName or PersonNameInverted

test_prepopulated_personnames()[source]

Should not modify when PersonName fields are already populated

class oaebu_workflows.tests.test_onix_utils.TestNormaliseRelatedProducts(methodName='runTest')[source]

Bases: unittest.TestCase

Contains tests for normalise_related_products and elevate_product_identifiers

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.

Should correctly elevate <ProductIdentifier> elements to <RelatedProduct> elements

test_elevate_product_identifiers()[source]

Should return a list of <RelatedProduct> structured elements. There should be one elements for each unique <ProductIdentifier><IDValue>. If there are multiple <ProductIdentifier><IDValue> elements with different <ProductIDType> then these are grouped in the return

test_duplicate_entries()[source]

Should return a list with a single element when given duplicate entries

class oaebu_workflows.tests.test_onix_utils.TestElevateRelatedProducts(methodName='runTest')[source]

Bases: unittest.TestCase

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.

test_no_parent_isbn()[source]

Should return the same input list if the parent product has no ISBN

test_relation_code()[source]

Shuold not elevate related products if the relation code is no ‘06’

test_duplicate_ids()[source]

Should not elevate related products if the ID is a duplicate of an existing parent product

Should elevate ISBN related products to the product level when the parent product has an ISBN

class oaebu_workflows.tests.test_onix_utils.TestFilterThroughSchema(methodName='runTest')[source]

Bases: unittest.TestCase

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.

test_filter_through_schema()[source]

Tests the generic use case of the function

test_matching_keys()[source]

Tests that the function correctly processes the input dictionary when all nested keys match the schema

test_empty_input()[source]

Tests that the function correctly handles an empty input dictionary

test_no_matching_keys()[source]

Tests that the function correctly handles an input dictionary with no matching keys in the schema

test_edge_case_empty_schema()[source]

Tests that the function correctly handles an empty schema

class oaebu_workflows.tests.test_onix_utils.TestRemoveInvalidProducts(methodName='runTest')[source]

Bases: unittest.TestCase

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.

oapen_metadata_fixtures[source]
valid_parsed_xml[source]
invalid_products_removed_xml[source]
empty_xml[source]
invalid_products_xml[source]
test_remove_invalid_products()[source]

Tests the function used to remove invalid products from an xml file

test_empty_xml()[source]

Tests the function used to remove invalid products from an xml file

class oaebu_workflows.tests.test_onix_utils.TestFindOnixProduct(methodName='runTest')[source]

Bases: unittest.TestCase

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.

valid_input = ['<ONIXMessage>', '<Product>', '<RecordReference>1</RecordReference>', '</Product>',...[source]
test_find_onix_product()[source]

Test that the function can extract multiple products from a valid input xml

test_out_of_bounds_supplied()[source]

Test that errors are thrown when improper input is supplied

test_missing_record_reference()[source]

Tests that a product without a RecordReference raises a KeyError

test_empty_product()[source]

Tests that a product without a RecordReference raises a KeyError

test_no_product_tags()[source]

Tests that the function raises a ValueError when <Product> tags are not closed or missing

class oaebu_workflows.tests.test_onix_utils.TestDeduplicateRelatedProducts(methodName='runTest')[source]

Bases: unittest.TestCase

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.

Should return the same list if there are no duplicated related products in any of the products

Should remove duplicated related products from a single product

test_empty_input_list()[source]

Should return an empty list if the input list is empty