Example #1
0
 def test_should_remove_contained_by(self) -> None:
     source = Source('S0', 'The Source')
     contained_by = Source(None, 'The Source')
     source.contained_by = contained_by
     anonymous_source = AnonymousSource()
     anonymize_source(source, anonymous_source)
     self.assertIsNone(source.contained_by)
Example #2
0
    def test_clean_should_not_clean_source_with_contains(self) -> None:
        ancestry = Ancestry()

        source = Source('S0', 'The Source')
        ancestry.entities.append(source)

        contains = Source('S1', 'The Source')
        contains.contained_by = source
        ancestry.entities.append(contains)

        clean(ancestry)

        self.assertEqual(source, ancestry.entities[Source][source.id])
        self.assertEqual(source, contains.contained_by)
        self.assertEqual(contains, ancestry.entities[Source][contains.id])
Example #3
0
 def test_contained_by(self) -> None:
     contained_by_source = Source(None)
     sut = Source(None)
     self.assertIsNone(sut.contained_by)
     sut.contained_by = contained_by_source
     self.assertEquals(contained_by_source, sut.contained_by)
Example #4
0
 async def test_source_should_encode_full(self):
     source = Source('the_source', 'The Source')
     source.author = 'The Author'
     source.publisher = 'The Publisher'
     source.date = Date(2000, 1, 1)
     source.contained_by = Source('the_containing_source',
                                  'The Containing Source')
     link = Link('https://example.com/the-source')
     link.label = 'The Source Online'
     source.links.add(link)
     source.contains.append(
         Source('the_contained_source', 'The Contained Source'))
     Citation('the_citation', source)
     expected = {
         '$schema':
         '/schema.json#/definitions/source',
         '@context': {
             'name': 'https://schema.org/name',
         },
         '@type':
         'https://schema.org/Thing',
         'id':
         'the_source',
         'name':
         'The Source',
         'author':
         'The Author',
         'publisher':
         'The Publisher',
         'contains': [
             '/en/source/the_contained_source/index.json',
         ],
         'citations': [
             '/en/citation/the_citation/index.json',
         ],
         'containedBy':
         '/en/source/the_containing_source/index.json',
         'date': {
             'year': 2000,
             'month': 1,
             'day': 1,
         },
         'links': [
             {
                 'url': '/en/source/the_source/index.json',
                 'relationship': 'canonical',
                 'mediaType': 'application/json',
             },
             {
                 'url': '/nl/source/the_source/index.json',
                 'relationship': 'alternate',
                 'locale': 'nl-NL',
             },
             {
                 'url': '/en/source/the_source/index.html',
                 'relationship': 'alternate',
                 'mediaType': 'text/html',
             },
             {
                 'url': 'https://example.com/the-source',
                 'label': 'The Source Online',
             },
         ],
     }
     await self.assert_encodes(expected, source, 'source')