def test_enclosed_by_should_sync_references(self): sut = Place('1', [LocalizedName('one')]) enclosing_place = Place('2', [LocalizedName('two')]) sut.enclosed_by = enclosing_place self.assertEquals(enclosing_place, sut.enclosed_by) self.assertIn(sut, enclosing_place.encloses) sut.enclosed_by = None self.assertIsNone(sut.enclosed_by) self.assertCountEqual([], enclosing_place.encloses)
def test_place_should_encode_full(self): place_id = 'the_place' name = 'The Place' locale = 'nl-NL' latitude = 12.345 longitude = -54.321 coordinates = Point(latitude, longitude) place = Place(place_id, [LocalizedName(name, locale)]) place.coordinates = coordinates place.enclosed_by = Place('the_enclosing_place', []) place.encloses.append(Place('the_enclosed_place', [])) place.links.add( Link('https://example.com/the-place', 'The Place Online')) place.events.append(IdentifiableEvent('E1', Event.Type.BIRTH)) expected = { '$schema': '/schema.json#/definitions/place', '@context': { 'encloses': 'https://schema.org/containsPlace', 'events': 'https://schema.org/event', 'enclosedBy': 'https://schema.org/containedInPlace', 'coordinates': 'https://schema.org/geo', }, '@type': 'https://schema.org/Place', 'id': place_id, 'names': [ { 'name': name, 'locale': 'nl-NL', }, ], 'events': [ '/event/E1/index.json', ], 'links': [ { 'url': 'https://example.com/the-place', 'label': 'The Place Online', }, ], 'coordinates': { '@context': { 'latitude': 'https://schema.org/latitude', 'longitude': 'https://schema.org/longitude', }, '@type': 'https://schema.org/GeoCoordinates', 'latitude': latitude, 'longitude': longitude, }, 'encloses': [ '/place/the_enclosed_place/index.json', ], 'enclosedBy': '/place/the_enclosing_place/index.json', } self.assert_encodes(expected, place, 'place')