Пример #1
0
 def test_init_params(self):
     p1 = model.Person(ident="urn:uuid:1234")
     self.assertEqual(p1.id, "urn:uuid:1234")
     p2 = model.Person(ident="http://schema.org/Foo")
     self.assertEqual(p2.id, "schema:Foo")
     p3 = model.Name(content="Test")
     self.assertEqual(p3.content, "Test")
Пример #2
0
 def test_int_per_type(self):
     model.factory.auto_id_type = "int-per-type"
     p = model.Person()
     p2 = model.Person()
     self.assertEqual(int(p.id[-1]), int(p2.id[-1]) - 1)
     p3 = model.Activity()
     self.assertEqual(int(p.id[-1]), int(p3.id[-1]))
Пример #3
0
 def test_set_magic_resource_inverse(self):
     model.factory.materialize_inverses = True
     artist = model.Person('00001', 'Jane Doe')
     son = model.Person('00002', 'John Doe')
     artist._set_magic_resource('parent_of', son)
     self.assertEqual(son.parent, [artist])
     model.factory.materialize_inverses = False
Пример #4
0
 def test_other_uris(self):
     p1 = model.Person(ident="tag:some-info-about-person")
     self.assertEqual(p1.id, "tag:some-info-about-person")
     p2 = model.Person(ident="info:ulan/500012345")
     self.assertEqual(p2.id, "info:ulan/500012345")
     p3 = model.Person(ident="some:random:thing:with:colons")
     self.assertFalse(p3.id == "some:random:thing:with:colons")
Пример #5
0
    def test_set_magic_resource(self):
        artist = model.Person('00001', 'Jane Doe')
        son = model.Person('00002', 'John Doe')
        daughter = model.Person('00002', 'Jenny Doe')
        son2 = model.Person('00002', 'Jim Doe')
        artist._set_magic_resource('parent_of', son)
        self.assertEqual(artist.parent_of, son)
        artist._set_magic_resource('parent_of', daughter)
        try:
            self.assertIn(son, artist.parent_of)
            self.assertIn(daughter, artist.parent_of)
        except:
            # 2.6 doesn't have assertIn
            self.assertTrue(son in artist.parent_of)
            self.assertTrue(daughter in artist.parent_of)

        artist._set_magic_resource('parent_of', son2)
        try:
            self.assertIn(son, artist.parent_of)
            self.assertIn(daughter, artist.parent_of)
            self.assertIn(son2, artist.parent_of)
        except:
            self.assertTrue(son in artist.parent_of)
            self.assertTrue(daughter in artist.parent_of)
            self.assertTrue(son2 in artist.parent_of)
Пример #6
0
	def test_set_magic_lang(self):
		model.factory.default_lang = 'en'
		artist = model.Person('00001', 'Jane Doe')
		self.assertEqual(artist.label, {'en': 'Jane Doe'})
		artist._set_magic_lang('label', 'Janey')
		self.assertEqual(artist.label, {'en': ['Jane Doe', 'Janey']})
		son = model.Person('00002', 'John Doe')
		self.assertRaises(model.DataError, artist._set_magic_lang, 'parent_of', son)
Пример #7
0
 def test_in_value(self):
     people = (
         model.Person('00001', 'Jane Doe'),  # artist
         model.Person('00002', 'Jim Doe')  # son2
     )
     self.assertIn(self.artist, people)
     self.assertNotIn(self.son, people)
     self.assertNotIn(self.daughter, people)
     self.assertIn(self.son2, people)
Пример #8
0
    def test_prefixes(self):

        model.factory.prefixes = {'fish': 'http://example.org/ns/'}
        p3 = model.Person('fish:3')
        self.assertEqual(p3.id, 'fish:3')
        self.assertEqual(p3._full_id, 'http://example.org/ns/3')

        model.factory.prefixes = {}
        p4 = model.Person('fish:4')
        self.assertTrue(p4.id.startswith(model.factory.base_url))
Пример #9
0
 def test_init_params(self):
     p1 = model.Person(ident="urn:uuid:1234")
     self.assertEqual(p1.id, "urn:uuid:1234")
     p2 = model.Person(ident="http://schema.org/Foo")
     self.assertEqual(p2.id, "schema:Foo")
     p3 = model.Name(content="Test")
     self.assertEqual(p3.content, "Test")
     c = model.MonetaryAmount(value=10)
     self.assertEqual(c.value, 10)
     n = model.Name(value="Rob")
     self.assertEqual(n.content, "Rob")
     i = model.Identifier(content="xyz123")
     self.assertEqual(i.content, "xyz123")
     i2 = model.Identifier(value="abc")
     self.assertEqual(i2.content, "abc")
Пример #10
0
	def test_boundary_setter(self):
		vocab.add_linked_art_boundary_check()
		p = model.Person()
		p2 = model.Person()
		n = model.Name()
		n.content = "Test"
		p2.identified_by = n
		p.exact_match = p2
		# Now, Test should not appear in the resulting JSON of p
		factory.linked_art_boundaries = True
		js = factory.toJSON(p)
		self.assertTrue(not 'identified_by' in js['exact_match'][0])
		factory.linked_art_boundaries = False
		js = factory.toJSON(p)
		self.assertTrue('identified_by' in js['exact_match'][0])		
Пример #11
0
 def test_list_my_props(self):
     p1 = model.Person()
     p1.classified_as = model.Type()
     props = p1.list_my_props()
     self.assertEqual(set(props), set(['classified_as', 'id']))
     props = p1.list_my_props(filter=model.Type)
     self.assertEqual(props, ['classified_as'])
Пример #12
0
	def test_prefixes(self):
		p = model.Person("ulan:1")
		self.assertEqual(p.id, "ulan:1")
		self.assertEqual(p._full_id, "http://vocab.getty.edu/ulan/1")

		p2 = model.Person('http://vocab.getty.edu/ulan/2')
		self.assertEqual(p2.id, 'ulan:2')
		self.assertEqual(p2._full_id, 'http://vocab.getty.edu/ulan/2')

		model.factory.prefixes = {'fish':'http://example.org/ns/'}
		p3 = model.Person('fish:3')
		self.assertEqual(p3.id, 'fish:3')
		self.assertEqual(p3._full_id, 'http://example.org/ns/3')

		model.factory.prefixes = {}
		p4 = model.Person('fish:4')
		self.assertTrue(p4.id.startswith(model.factory.base_url))
Пример #13
0
 def test_validate_profile_off(self):
     model.factory.validate_profile = False
     ia = model.IdentifierAssignment()
     # If it's not turned off this should raise
     model.factory.validate_profile = True
     self.assertRaises(model.ProfileError, model.IdentifierAssignment)
     p1 = model.Person()
     self.assertRaises(model.ProfileError, p1.__setattr__, 'documented_in',
                       "foo")
Пример #14
0
 def test_int_per_segment(self):
     model.factory._auto_id_segments = {}
     model.factory.auto_id_type = "int-per-segment"
     model.Activity._uri_segment = model.Person._uri_segment
     p = model.Person()
     p2 = model.Activity()
     self.assertEqual(int(p.id[-1]), int(p2.id[-1]) - 1)
     p3 = model.TimeSpan()
     self.assertEqual(int(p.id[-1]), int(p3.id[-1]))
Пример #15
0
 def test_neq(self):
     self.assertNotEqual(self.artist, self.son)
     self.assertNotEqual(self.artist, model.Person('00001',
                                                   'Jane'))  # label differs
     self.assertNotEqual(self.artist, self.daughter)
     self.assertNotEqual(self.artist, self.son2)
     self.assertNotEqual(self.son, self.daughter)
     self.assertNotEqual(self.son, self.son2)
     self.assertNotEqual(self.daughter, self.son2)
Пример #16
0
 def test_validate_multiplicity(self):
     model.factory.validate_multiplicity = True
     who = model.Person()
     b1 = model.Birth()
     who.born = b1
     b2 = model.Birth()
     self.assertRaises(model.ProfileError, who.__setattr__, 'born', b2)
     model.factory.validate_multiplicity = False
     who.born = b2
     self.assertEqual(who.born, [b1, b2])
Пример #17
0
 def test_collapse_json(self):
     p = model.Person()
     p.classified_as = model.Type(ident="http://example.org/Type",
                                  label="Test")
     res1 = model.factory.toString(p, compact=False,
                                   collapse=60)  # all new lines
     res2 = model.factory.toString(p, compact=False,
                                   collapse=120)  # compact list of type
     self.assertEqual(len(res1.splitlines()), 12)
     self.assertEqual(len(res2.splitlines()), 6)
Пример #18
0
 def test_collapse_json(self):
     model.factory.auto_id_type = "uuid"
     model.factory.base_url = "http://lod.example.org/museum/"
     model.factory.context_uri = "https://linked.art/ns/v1/linked-art.json"
     p = model.Person()
     p.classified_as = model.Type(ident="http://example.org/Type",
                                  label="Test")
     res1 = model.factory.toString(p, compact=False,
                                   collapse=60)  # all new lines
     res2 = model.factory.toString(p, compact=False,
                                   collapse=120)  # compact list of type
     self.assertEqual(len(res1.splitlines()), 12)
     self.assertEqual(len(res2.splitlines()), 6)
Пример #19
0
	def test_toJSON_full(self):
		expect = OrderedDict([(u'@context', 'http://lod.getty.edu/context.json'), 
			(u'@id', u'http://lod.example.org/museum/Person/1'), (u'@type', u'crm:E21_Person'),
			('rdfs:label', 'Test Person')])
		model.factory.context_uri = 'http://lod.getty.edu/context.json'
		model.factory.full_names = True
		p = model.Person("1")
		p.label = "Test Person"
		outj = model.factory.toJSON(p)
		self.assertEqual(expect, outj)
		# reset
		model.factory.full_names = False
		model.factory.context_uri = ""
Пример #20
0
    def test_ordering(self):
        p = model.Person(label="Person")
        p.classified_as = model.Type(ident="type-uri")
        p.referred_to_by = model.LinguisticObject(content="text")
        p.dimension = model.Dimension(value=1)

        outstr = model.factory.toString(p)
        lbl = outstr.index("_label")
        clsf = outstr.index("classified_as")
        r2b = outstr.index("referred_to_by")
        dim = outstr.index("dimension")
        self.assertTrue(lbl < clsf)
        self.assertTrue(clsf < r2b)
        self.assertTrue(r2b < dim)
Пример #21
0
    def test_production_mode(self):

        # model.factory.production_mode()
        # Can't unset the cached hierarchy
        # and it causes the test for the hierarchy to fail
        model.factory.validate_profile = False
        model.factory.validate_properties = False
        model.factory.validate_range = False
        model.factory.validate_multiplicity = False

        p = model.Person()
        p.identified_by = model.Name(value="abc")
        p.part = model.HumanMadeObject()
        js = model.factory.toJSON(p)

        model.factory.production_mode(state=False)
Пример #22
0
    def setup_static_instances(self):
        '''
		These are instances that are used statically in the code. For example, when we
		provide attribution of an identifier to Getty, or use a Lugt number, we need to
		serialize the related Group or Person record for that attribution, even if it does
		not appear in the source data.
		'''
        lugt_ulan = 500321736
        gri_ulan = 500115990
        gci_ulan = 500115991
        GETTY_GRI_URI = self.helper.make_proj_uri('ORGANIZATION',
                                                  'LOCATION-CODE', 'JPGM')
        GETTY_GCI_URI = self.helper.make_shared_uri(
            'STATIC', 'ORGANIZATION', 'Getty Conservation Institute')
        LUGT_URI = self.helper.make_proj_uri('PERSON', 'ULAN', lugt_ulan)

        gci = model.Group(ident=GETTY_GCI_URI,
                          label='Getty Conservation Institute')
        gci.identified_by = vocab.PrimaryName(
            ident='', content='Getty Conservation Institute')
        gci.exact_match = model.BaseResource(
            ident=f'http://vocab.getty.edu/ulan/{gci_ulan}')

        gri = model.Group(ident=GETTY_GRI_URI,
                          label='Getty Research Institute')
        gri.identified_by = vocab.PrimaryName(
            ident='', content='Getty Research Institute')
        gri.exact_match = model.BaseResource(
            ident=f'http://vocab.getty.edu/ulan/{gri_ulan}')

        lugt = model.Person(ident=LUGT_URI, label='Frits Lugt')
        lugt.identified_by = vocab.PrimaryName(ident='', content='Frits Lugt')
        lugt.exact_match = model.BaseResource(
            ident=f'http://vocab.getty.edu/ulan/{lugt_ulan}')

        instances = defaultdict(dict)
        instances.update({
            'Group': {
                'gci': gci,
                'gri': gri
            },
            'Person': {
                'lugt': lugt
            }
        })
        return instances
Пример #23
0
    def test_not_multiple_instance(self):
        who = model.Person()
        n = model.Name(content="Test")
        who.identified_by = n

        model.factory.multiple_instances_per_property = "error"
        self.assertRaises(model.DataError, who.__setattr__, 'identified_by', n)
        self.assertEqual(who.identified_by, [n])

        model.factory.multiple_instances_per_property = "drop"
        who.identified_by = n
        self.assertEqual(who.identified_by, [n, n])
        # and check that only serialized once
        js = model.factory.toJSON(who)
        self.assertEqual(len(js['identified_by']), 1)

        model.factory.multiple_instances_per_property = "allow"
        js = model.factory.toJSON(who)
        self.assertEqual(len(js['identified_by']), 2)
Пример #24
0
    def test_no_ident(self):

        model.factory.auto_assign_id = True
        p1 = model.Person()  # auto assigned
        p2 = model.Person(ident=None)  # auto assigned
        p3 = model.Person(ident="")  # bnode explicitly

        self.assertTrue(p1.id.startswith('http'))
        self.assertTrue(p2.id.startswith('http'))
        self.assertEqual(p3.id, '')

        model.factory.auto_assign_id = False
        p4 = model.Person()  # bnode is default
        p5 = model.Person(ident=None)  # bnode is default
        p6 = model.Person(ident="")  # bnode explicitly

        self.assertEqual(p4.id, '')
        self.assertEqual(p5.id, '')
        self.assertEqual(p6.id, '')
Пример #25
0
 def test_validation_off(self):
     model.factory.validate_properties = False
     artist = model.Person('00001', 'Jane Doe')
     artist.unknown_property = 1
     self.assertEqual(artist.unknown_property, 1)
Пример #26
0
 def test_validation_wrong_type(self):
     model.factory.validate_properties = True
     artist = model.Person('00001', 'Jane Doe')
     self.assertRaises(model.DataError, artist.__setattr__, 'parent_of',
                       'Bad Value')
Пример #27
0
 def test_validation_unknown(self):
     model.factory.validate_properties = True
     artist = model.Person('00001', 'Jane Doe')
     self.assertRaises(model.DataError, artist.__setattr__,
                       'unknown_property', 1)
Пример #28
0
 def setUp(self):
     self.artist = model.Person('00001', 'Jane Doe')
     self.son = model.Person('00002', 'John Doe')
     model.Person._properties['parent_of']['okayToUse'] = 1
Пример #29
0
 def test_uuid(self):
     model.factory.auto_id_type = "uuid"
     p = model.Person()
     self.assertTrue(p.id.startswith('urn:uuid:'))
Пример #30
0
 def test_int(self):
     model.factory.auto_id_type = "int"
     p = model.Person()
     p2 = model.Activity()
     self.assertEqual(int(p.id[-1]), int(p2.id[-1]) - 1)