Exemplo n.º 1
0
 def test_read_constant(self):
     """ test Read and Parse """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "repository","required": false,"duplicatesAllowed": false,'
         + '"xpath": "required, but not used here.","constant": "Snite"}')
     field = GetEmbarkField(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     self.assertTrue(
         json.loads('{"repository": "Snite"}') == json_of_embark_field)
Exemplo n.º 2
0
 def test_read_creator(self):
     """ test Read and Parse """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "creator","required": false,"duplicatesAllowed": false,'
         + '"xpath": "./variable[@id=\'object_00060\']"}')
     field = GetEmbarkField(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     self.assertTrue(
         json.loads('{"creator": "Paul Wood"}') == json_of_embark_field)
Exemplo n.º 3
0
 def test_read_record_id(self):
     """ test Read and Parse """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "recordId","required": true,"duplicatesAllowed": false,'
         + '"xpath": "./variable[@id=\'object_00055\']"}')
     field = GetEmbarkField(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     self.assertTrue(
         json.loads('{"recordId": "1976.057"}') == json_of_embark_field)
Exemplo n.º 4
0
 def parse_embark_record(self, embark_item_xml):
     """ This translates information from EmbArk XML representing an
         individual museum item to JSON """
     fields_definition = self.fields_definition
     self.output = {}  # reset at beginning of each EmbArk Item
     node = {}
     for field in fields_definition:
         get_embark_field_instance = GetEmbarkField(field)
         node = get_embark_field_instance.get_json_representation_of_field(
             embark_item_xml)
         if 'recordId' in node:
             self.id = node['recordId']
         self.output.update(node)
     return self.output
Exemplo n.º 5
0
 def test_read_exhibition(self):
     """ test Read and Parse """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "exhibition","required": false,"duplicatesAllowed": true,"xpath":'
         +
         ' "./group[@id=\'object_00002\']/variable[@id=\'object_00002\']"}')
     field = GetEmbarkField(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     self.assertTrue(
         json.loads(
             '{"exhibition": [{"name": "Picturing History", "startDate": "09/01/94",'
             + '"endDate": "12/01/94"}]}') == json_of_embark_field)
Exemplo n.º 6
0
 def test_read_keyword(self):
     """ test keyword """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "keyword","required": false,"duplicatesAllowed": true,"xpath":'
         +
         '"./group[@id=\'object_00080\']/variable[@id=\'object_00080\']"}')
     field = GetEmbarkField(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     for keyword in json_of_embark_field['keyword']:
         value = keyword['value']
         self.assertTrue(value == 'confederate')
         break
Exemplo n.º 7
0
 def test_read_default(self):
     """ test default """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "classification","required": false,"duplicatesAllowed": false,'
         +
         '"xpath": "./variable[@name=\'[Object]Class 2\']","default": "painting"}'
     )
     field = GetEmbarkField(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     # print(json_of_embark_field)
     self.assertTrue(
         json.loads('{"classification": "painting"}') ==
         json_of_embark_field)
Exemplo n.º 8
0
 def test_try_to_throw_required_value_missing_error(self):
     """ test default """
     xml_of_embark_item = self.get_xml_doc()
     json_of_embark_field = {}
     field_definition = json.loads(
         '{"name": "classification","required": true,"duplicatesAllowed":' +
         ' false,"xpath": "./variable[@name=\'[Object]Class 2\']"}')
     field = GetEmbarkField(field_definition)
     self.assertRaises(ValueError, field.get_json_representation_of_field,
                       xml_of_embark_item)
     field_definition = json.loads(
         '{"name": "classification","required": true,"duplicatesAllowed":' +
         ' false,"xpath": "./variable[@name=\'[Object]Class 2\']","default":'
         + ' "painting"}')
     field.load_json_field_definition(field_definition)
     json_of_embark_field = field.get_json_representation_of_field(
         xml_of_embark_item)
     self.assertTrue(
         json.loads('{"classification": "painting"}') ==
         json_of_embark_field)