provdbconnector.tests.db_adapters package¶
Subpackages¶
Submodules¶
provdbconnector.tests.db_adapters.test_baseadapter module¶
-
provdbconnector.tests.db_adapters.test_baseadapter.
json_serial
(obj)[source]¶ JSON serializer for objects not serializable by default json code
-
provdbconnector.tests.db_adapters.test_baseadapter.
encode_adapter_result_to_excpect
(dict_vals)[source]¶ This function translate a metadata dict to an expected version of this dict
Parameters: dict_vals – Returns:
-
provdbconnector.tests.db_adapters.test_baseadapter.
insert_document_with_bundles
(instance, identifier_prefix='')[source]¶ This function creates a full bundle on your database adapter, to prepare the test data
Parameters: - instance – The db_adapter instnace
- identifier_prefix – A prefix for the identifiers
Returns: The ids of the records
-
class
provdbconnector.tests.db_adapters.test_baseadapter.
AdapterTestTemplate
(*args, **kwargs)[source]¶ Bases:
unittest.case.TestCase
This test class is a template for each database adapter. The following example show how you implement the test for your adapter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
from provdbconnector.exceptions.database import InvalidOptionsException from provdbconnector.db_adapters.in_memory import SimpleInMemoryAdapter from provdbconnector.prov_db import ProvDb from provdbconnector.tests import AdapterTestTemplate from provdbconnector.tests import ProvDbTestTemplate class SimpleInMemoryAdapterTest(AdapterTestTemplate): """ This class implements the AdapterTestTemplate and only override some functions. """ def setUp(self): """ Connect to your database """ self.instance = SimpleInMemoryAdapter() self.instance.connect(None) def test_connect_invalid_options(self): """ Test your connect function with invalid data """
-
maxDiff
= None¶
-
setUp
()[source]¶ - Setup the instnace of your database adapter
Warning
Override this method otherwise all test will fail
Returns:
-
test_1_save_element
()[source]¶ This test try to save a simple record
Graph-Strucutre
Input-Data
Warning
This is a json representation of the input data and not the real input data. For example metadata.prov_type is a QualifiedName instance
{ "metadata":{ "identifier":"<QualifiedName: prov:example_node>", "namespaces":{ "ex":"http://example.com", "custom":"http://custom.com" }, "prov_type":"<QualifiedName: prov:Activity>", "type_map":{ "int value":"int", "date value":"xds:datetime" } }, "attributes":{ "ex:individual attribute":"Some value", "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:dict value":{ "dict":"value" }, "ex:list value":[ "list", "of", "strings" ], "ex:double value":99.33, "ex:int value":99 } }
Output-Data
The output is only a id as string
4d3cdc76-467d-4db8-89bf-9accc7b27777
-
test_2_save_relation
()[source]¶ This test try to save a simple relation between 2 identifiers
Graph-Strucutre
Input-Data
Warning
This is a json representation of the input data and not the real input data. For example metadata.prov_type is a QualifiedName instance
{ "from_node":"<QualifiedName: ex:Yoda>", "to_node":"<QualifiedName: ex:Luke Skywalker>", "metadata":{ "prov_type":"<QualifiedName: prov:Mention>", "type_map":{ "date value":"xds:datetime", "int value":"int" }, "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"identifier for the relation" }, "attributes":{ "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)" }, }
Output-Data
The output is only the id of the relation as string
4d3cdc76-467d-4db8-89bf-9accc7b27778
-
test_3_save_relation_with_unknown_records
()[source]¶ This test is to test the creation of a relation where the nodes are not in the database :return:
-
test_4_get_record
()[source]¶ Create a record and then try to get it back
Graph-Strucutre
Input-Data
“id-333”
Output-Data
The output is all connected nodes and there relations
[ { "ex:int value":99, "ex:list value":[ "list", "of", "strings" ], "ex:date value":"2005-06-01 13:33:00", "ex:individual attribute":"Some value", "ex:double value":99.33, "ex:dict value":"{"dict": "value"}" }, { "identifier":"prov:example_node", "prov_type":"prov:Activity", "type_map":"{"date value": "xds:datetime", "int value": "int"}", "namespaces":"{"custom": "http://custom.com", "ex": "http://example.com"}" } ]
-
test_6_get_relation
()[source]¶ create a relation between 2 nodes and try to get the relation back
Graph-Strucutre
Input-Data
“id-333”
Output-Data
The output is all connected nodes and there relations
[ { "ex:dict value":"{"dict": "value"}", "ex:int value":99, "ex:individual attribute":"Some value", "ex:date value":"2005-06-01 13:33:00", "ex:list value":[ "list", "of", "strings" ], "ex:double value":99.33 }, { "identifier":"identifier for the relation", "prov_type":"prov:Mention", "namespaces":"{"ex": "http://example.com", "custom": "http://custom.com"}", "type_map":"{"date value": "xds:datetime", "int value": "int"}" } ]
-
test_8_get_records_by_filter
()[source]¶ This test is to get a the whole graph without any filter
Graph-Strucutre
Input-Data
We have no input data for the filter function because we want to get the whole graph
Output-Data
The output is the only node that exist in the database (was also created during the test)
Warning
This is a json representation of the input data and not the real input data. For example metadata.prov_type is a QualifiedName instance
{ "metadata":{ "identifier":"<QualifiedName: prov:example_node>", "namespaces":{ "ex":"http://example.com", "custom":"http://custom.com" }, "prov_type":"<QualifiedName: prov:Activity>", "type_map":{ "int value":"int", "date value":"xds:datetime" } }, "attributes":{ "ex:individual attribute":"Some value", "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:dict value":{ "dict":"value" }, "ex:list value":[ "list", "of", "strings" ], "ex:double value":99.33, "ex:int value":99 } }
-
test_9_get_records_by_filter_with_properties
()[source]¶ This test is to get a specific part of the graph via certain filter criteria
Graph-Strucutre
Get single node
The first part of the test is to try to get a single node based on a attribut
Input-Data
{ "prov:type":"prov:Bundle" }
Output-Data
The output is a list of namedtuples wit the following structure: list(tuple(attributes,metadata))
[ [ { "prov:type": "prov:Bundle" }, { "prov_type": "prov:Entity", "identifier": "ex:bundle name", "type_map": "{\"date value\": \"xds:datetime\", \"int value\": \"int\"}", "namespaces": "{\"ex\": \"http://example.com\"}" } ] ]
Get other nodes
The second part tests the other way to get all other node except the bundle node
Input-Data
The input is a set of attributes
{ "ex:dict value":{ "dict":"value" }, "ex:double value":99.33, "ex:int value":99, "ex:individual attribute":"Some value", "ex:list value":[ "list", "of", "strings" ] }
Output-Data
The output is a list of namedtuple with attributes and metadata
[ [ { "ex:dict value":"{'dict': 'value'}", "ex:double value":99.33, "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"2005-06-01 13:33:00", "ex:individual attribute":"Some value" }, { "identifier":"ex:TO NODE", "type_map":"{'int value': 'int', 'date value': 'xds:datetime'}", "namespaces":"{'ex': 'http://example.com', 'custom': 'http://custom.com'}", "prov_type":"prov:Activity" } ], [ { "ex:dict value":"{'dict': 'value'}", "ex:double value":99.33, "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"2005-06-01 13:33:00", "ex:individual attribute":"Some value" }, { "identifier":"ex:FROM NODE", "type_map":"{'int value': 'int', 'date value': 'xds:datetime'}", "namespaces":"{'ex': 'http://example.com', 'custom': 'http://custom.com'}", "prov_type":"prov:Activity" } ], [ { "ex:dict value":"{'dict': 'value'}", "ex:double value":99.33, "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"2005-06-01 13:33:00", "ex:individual attribute":"Some value" }, { "identifier":"ex:prov:example_node", "type_map":"{'int value': 'int', 'date value': 'xds:datetime'}", "namespaces":"{'ex': 'http://example.com', 'custom': 'http://custom.com'}", "prov_type":"prov:Activity" } ], [ { "ex:dict value":"{'dict': 'value'}", "ex:double value":99.33, "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"2005-06-01 13:33:00", "ex:individual attribute":"Some value" }, { "identifier":"identifier for the relation", "type_map":"{'int value': 'int', 'date value': 'xds:datetime'}", "namespaces":"{'ex': 'http://example.com', 'custom': 'http://custom.com'}", "prov_type":"prov:Mention" } ] ]
:return
-
test_10_get_records_by_filter_with_metadata
()[source]¶ Should test also the filter by metadata
@todo implement test for filter by metadata
Graph-Strucutre
Warning
This test is not implemented jet
Returns:
-
test_11_get_records_tail
()[source]¶ This test is to get the whole provenance from a starting point
Graph-Strucutre
Input-Data
In this case we filter by metadata and by the identifier
{ "identifier":"ex:FROM NODE" }
Output-Data
The output is all connected nodes and there relations
[ [ { "ex:list value":[ "list", "of", "strings" ], "ex:double value":99.33, "ex:int value":99, "ex:individual attribute":"Some value", "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:dict value":{ "dict":"value" } }, { "prov_type":"<QualifiedName: prov:Mention>", "identifier":"identifier for the relation", "type_map":{ "date value":"xds:datetime", "int value":"int" }, "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" } } ], [ { "ex:list value":[ "list", "of", "strings" ], "ex:double value":99.33, "ex:int value":99, "ex:individual attribute":"Some value", "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:dict value":{ "dict":"value" } }, { "prov_type":"<QualifiedName: prov:Activity>", "identifier":"<QualifiedName: ex:TO NODE>", "type_map":{ "date value":"xds:datetime", "int value":"int" }, "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" } } ] ]
-
test_12_get_records_tail_recursive
()[source]¶ Test the same behavior as the test_get_records_tail test but with a recursive data structure
Graph-Strucutre
Input-Data
{ "identifier":"ex:FROM NODE" }
Output-Data
The output is all connected nodes and there relations
[ [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"identifier for the relation", "prov_type":"<QualifiedName: prov:Mention>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"identifier for the relation", "prov_type":"<QualifiedName: prov:Mention>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"<QualifiedName: ex:TO NODE>", "prov_type":"<QualifiedName: prov:Activity>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"<QualifiedName: ex:second_TO NODE>", "prov_type":"<QualifiedName: prov:Activity>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"identifier for the relation", "prov_type":"<QualifiedName: prov:Mention>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"<QualifiedName: ex:FROM NODE>", "prov_type":"<QualifiedName: prov:Activity>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"identifier for the relation", "prov_type":"<QualifiedName: prov:Mention>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ], [ { "ex:dict value":{ "dict":"value" }, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:double value":99.33, "ex:individual attribute":"Some value", "ex:int value":99, "ex:list value":[ "list", "of", "strings" ] }, { "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"<QualifiedName: ex:second_FROM NODE>", "prov_type":"<QualifiedName: prov:Activity>", "type_map":{ "date value":"xds:datetime", "int value":"int" } } ] ]
-
test_13_get_bundle_records
()[source]¶ The get_bundle function is to return the records (relation and nodes) for a bundle identifier
Test the same behavior as the test_get_records_tail test but with a recursive data structure
Graph-Strucutre
Input-Data
{ "identifier":"ex:FROM NODE" }
Output-Data
The output is all connected nodes and there relations
Warning
coming soon!
-
test_15_delete_by_filter_with_properties
()[source]¶ Try to delete by filter, same behavior as get_by_filter
Returns:
-
test_16_delete_by_filter_with_metadata
()[source]¶ Try to delete by metadata, same behavior as get_by_metadata :return:
-
test_19_merge_record
()[source]¶ This function test the merge abbility of your adapter.
Graph-Strucutre
Input-Data
We try to create the node twice, with the following data
{ "metadata":{ "prov_type":"<QualifiedName: prov:Activity>", "namespaces":{ "ex":"http://example.com", "custom":"http://custom.com" }, "identifier":"<QualifiedName: ex:Yoda>", "type_map":{ "int value":"int", "date value":"xds:datetime" } }, "attributes":{ "ex:int value":99, "ex:individual attribute":"Some value", "ex:list value":[ "list", "of", "strings" ], "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:dict value":{ "dict":"value" }, "ex:double value":99.33 } }
Output-Data
The output is one entry with no change of the data
[ { "ex:int value":99, "ex:individual attribute":"Some value", "ex:list value":[ "list", "of", "strings" ], "ex:date value":"2005-06-01 13:33:00", "ex:dict value":"{"dict": "value"}", "ex:double value":99.33 }, { "prov_type":"prov:Activity", "namespaces":"{"ex": "http://example.com", "custom": "http://custom.com"}", "identifier":"ex:Yoda", "type_map":"{"int value": "int", "date value": "xds:datetime"}" } ]
-
test_20_merge_record_complex
()[source]¶ In this example we test if we merge different attributes into one node
Graph-Strucutre
Input-Data
This is the attributes used to create the entry
{ "ex:individual attribute":"Some value", "ex:dict value":{ "dict":"value" }, "ex:double value":99.33, "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)" }
This are the attributes to alter the existing node
{ "ex:a other attribute":true }
Output-Data
The output is one entry with the additional attribute
[ { "ex:individual attribute":"Some value", "ex:dict value":"{"dict": "value"}", "ex:double value":99.33, "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"2005-06-01 13:33:00", "ex:a other attribute":true }, { "type_map":"{"date value": "xds:datetime", "int value": "int"}", "identifier":"ex:Yoda", "prov_type":"prov:Activity", "namespaces":"{"ex": "http://example.com", "custom": "http://custom.com"}" } ]
-
test_21_merge_record_complex_fail
()[source]¶ - In this example we test if we merge different attributes into one node
Graph-Strucutre
This is the attributes used to create the entry
{ "ex:list value":[ "list", "of", "strings" ], "ex:double value":99.33, "ex:date value":"datetime.datetime(2005, 6, 1, 13, 33)", "ex:dict value":{ "dict":"value" }, "ex:int value":99, "ex:individual attribute":"Some value" }
Try to override the existing attribute
{ "ex:int value": 1 }
Output-Data
Should throw an MergeException
-
test_22_merge_record_metadata
()[source]¶ This test try to merge the metadata. This is important if you add some new attributes that uses other namespaces, so you need to merge the namespaces Same behavior for the type_map
Graph-Strucutre
Input-Data
The metadata for the initial record:
{ "type_map":{ "date value":"xds:datetime", "int value":"int" }, "prov_type":"<QualifiedName: prov:Activity>", "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "identifier":"<QualifiedName: ex:Yoda>" }
Try to add a record with some modified namespaces
{ "namespaces":{ "custom":"http://custom.com", "ex":"http://example.com" }, "prov_type":"<QualifiedName: prov:Activity>", "identifier":"<QualifiedName: ex:Yoda>", "type_map":{ "custom_attr_1":"xds:some_value" } }
Output-Data
The output is the merged result of the type map
[ { "ex:individual attribute":"Some value", "ex:list value":[ "list", "of", "strings" ], "ex:int value":99, "ex:date value":"2005-06-01 13:33:00", "ex:dict value":"{"dict": "value"}", "ex:double value":99.33 }, { "prov_type":"prov:Activity", "type_map":"{"custom_attr_1": "xds:some_value", "date value": "xds:datetime", "int value": "int"}", "identifier":"ex:Yoda", "namespaces":"{"custom": "http://custom.com", "ex": "http://example.com"}" } ]
-
test_23_merge_relation
()[source]¶ Merge a relation is pretty similar to merge records. The big difference is the different rules for uniques
Graph-Strucutre
A relation is unique if:
- The relation type is the same
- all other formal attributes (see SimpleDbAdapter) are the same
otherwise it is not the same relation.
-