Ejemplo n.º 1
0
    async def test_post_parse(self):
        person = Person('P0')
        Presence(person, Subject(), Event(Birth()))

        source_file = File('F0', __file__)
        source = IdentifiableSource('S0', 'The Source')
        source.private = True
        source.files.append(source_file)

        citation_file = File('F0', __file__)
        citation_source = Source('The Source')
        citation = IdentifiableCitation('C0', citation_source)
        citation.private = True
        citation.files.append(citation_file)

        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'https://example.com')
            configuration.plugins[Privatizer] = None
            async with Site(configuration) as site:
                site.ancestry.people[person.id] = person
                site.ancestry.sources[source.id] = source
                site.ancestry.citations[citation.id] = citation
                await parse(site)

            self.assertTrue(person.private)
            self.assertTrue(source_file.private)
            self.assertTrue(citation_file.private)
Ejemplo n.º 2
0
class ImageTest(TemplateTestCase):
    image_path = join(dirname(dirname(__file__)), 'assets', 'public', 'static',
                      'betty-512x512.png')

    @parameterized.expand([
        ('/file/F1-99x-.png', '{{ file | image(width=99) }}',
         File('F1', image_path)),
        ('/file/F1--x99.png', '{{ file | image(height=99) }}',
         File('F1', image_path)),
        ('/file/F1-99x99.png', '{{ file | image(width=99, height=99) }}',
         File('F1', image_path)),
        ('/file/F1-99x99.png:/file/F1-99x99.png',
         '{{ file | image(width=99, height=99) }}:{{ file | image(width=99, height=99) }}',
         File('F1', image_path)),
    ])
    @sync
    async def test(self, expected, template, file):
        async with self._render(template_string=template,
                                data={
                                    'file': file,
                                }) as (actual, site):
            self.assertEquals(expected, actual)
            for file_path in actual.split(':'):
                self.assertTrue(
                    exists(
                        join(site.configuration.www_directory_path,
                             file_path[1:])))
Ejemplo n.º 3
0
 def test_privatize_person_should_privatize_if_private(self):
     source_file = File('F0', __file__)
     source = Source('The Source')
     source.files.append(source_file)
     citation_file = File('F1', __file__)
     citation = IdentifiableCitation('C0', source)
     citation.files.append(citation_file)
     event_as_subject = Event(Birth())
     event_as_attendee = Event(Marriage())
     person_file = File('F2', __file__)
     person = Person('P0')
     person.private = True
     person.citations.append(citation)
     person.files.append(person_file)
     Presence(person, Subject(), event_as_subject)
     Presence(person, Attendee(), event_as_attendee)
     privatize_person(person, 125)
     self.assertTrue(person.private)
     self.assertTrue(citation.private)
     self.assertTrue(source.private)
     self.assertTrue(person_file.private)
     self.assertTrue(citation_file.private)
     self.assertTrue(source_file.private)
     self.assertTrue(event_as_subject.private)
     self.assertIsNone(event_as_attendee.private)
Ejemplo n.º 4
0
class FilterImageTest(TemplateTestCase):
    image_path = path.join(path.dirname(path.dirname(__file__)), 'assets', 'public', 'static', 'betty-512x512.png')

    @parameterized.expand([
        ('/file/F1-99x-.png',
         '{{ file | image(width=99) }}', File('F1', image_path, media_type=MediaType('image/png'))),
        ('/file/F1--x99.png',
         '{{ file | image(height=99) }}', File('F1', image_path, media_type=MediaType('image/png'))),
        ('/file/F1-99x99.png',
         '{{ file | image(width=99, height=99) }}', File('F1', image_path, media_type=MediaType('image/png'))),
        ('/file/F1-99x99.png:/file/F1-99x99.png',
         '{{ file | image(width=99, height=99) }}:{{ file | image(width=99, height=99) }}', File('F1', image_path, media_type=MediaType('image/png'))),
    ])
    @sync
    async def test(self, expected, template, file):
        async with self._render(template_string=template, data={
            'file': file,
        }) as (actual, site):
            self.assertEquals(expected, actual)
            for file_path in actual.split(':'):
                self.assertTrue(path.exists(path.join(site.configuration.www_directory_path, file_path[1:])))

    @sync
    async def test_without_width(self):
        file = File('F1', self.image_path, media_type=MediaType('image/png'))
        with self.assertRaises(ValueError):
            async with self._render(template_string='{{ file | image }}', data={
                'file': file,
            }):
                pass
Ejemplo n.º 5
0
 def test_privatize_person_should_not_privatize_if_public(self):
     source_file = File('F0', __file__)
     source = Source('The Source')
     source.files.append(source_file)
     citation_file = File('F1', __file__)
     citation = IdentifiableCitation('C0', source)
     citation.files.append(citation_file)
     event_as_subject = Event(Birth())
     event_as_attendee = Event(Marriage())
     person_file = File('F2', __file__)
     person = Person('P0')
     person.private = False
     person.citations.append(citation)
     person.files.append(person_file)
     Presence(person, Subject(), event_as_subject)
     Presence(person, Attendee(), event_as_attendee)
     ancestry = Ancestry()
     ancestry.people[person.id] = person
     privatize(ancestry)
     self.assertEqual(False, person.private)
     self.assertIsNone(citation.private)
     self.assertIsNone(source.private)
     self.assertIsNone(person_file.private)
     self.assertIsNone(citation_file.private)
     self.assertIsNone(source_file.private)
     self.assertIsNone(event_as_subject.private)
     self.assertIsNone(event_as_attendee.private)
Ejemplo n.º 6
0
 def test_privatize_citation_should_not_privatize_if_public(self):
     source_file = File('F0', __file__)
     source = Source('The Source')
     source.files.append(source_file)
     citation_file = File('F1', __file__)
     citation = IdentifiableCitation('C0', source)
     citation.private = False
     citation.files.append(citation_file)
     privatize_citation(citation)
     self.assertEqual(False, citation.private)
     self.assertIsNone(source.private)
     self.assertIsNone(citation_file.private)
     self.assertIsNone(source_file.private)
Ejemplo n.º 7
0
 def test_privatize_citation_should_privatize_if_private(self):
     source_file = File('F0', __file__)
     source = Source('The Source')
     source.files.append(source_file)
     citation_file = File('F1', __file__)
     citation = IdentifiableCitation('C0', source)
     citation.private = True
     citation.files.append(citation_file)
     privatize_citation(citation)
     self.assertTrue(citation.private)
     self.assertTrue(source.private)
     self.assertTrue(citation_file.private)
     self.assertTrue(source_file.private)
Ejemplo n.º 8
0
class FilterFileTest(TemplateTestCase):
    @parameterized.expand([
        ('/file/F1.py', '{{ file | file }}', File('F1', __file__)),
        ('/file/F1.py:/file/F1.py',
         '{{ file | file }}:{{ file | file }}', File('F1', __file__)),
    ])
    @sync
    async def test(self, expected, template, file):
        async with self._render(template_string=template, data={
            'file': file,
        }) as (actual, site):
            self.assertEquals(expected, actual)
            for file_path in actual.split(':'):
                self.assertTrue(path.exists(path.join(site.configuration.www_directory_path, file_path[1:])))
Ejemplo n.º 9
0
 def test_file_should_encode_minimal(self):
     with NamedTemporaryFile() as f:
         file = File('the_file', f.name)
         expected = {
             '$schema':
             '/schema.json#/definitions/file',
             'id':
             'the_file',
             'resources': [],
             'notes': [],
             'links': [
                 {
                     'url': '/en/file/the_file/index.json',
                     'relationship': 'canonical',
                     'mediaType': 'application/json',
                 },
                 {
                     'url': '/nl/file/the_file/index.json',
                     'relationship': 'alternate',
                     'locale': 'nl-NL',
                 },
                 {
                     'url': '/en/file/the_file/index.html',
                     'relationship': 'alternate',
                     'mediaType': 'text/html',
                 },
             ],
         }
         self.assert_encodes(expected, file, 'file')
Ejemplo n.º 10
0
    def test_clean_should_not_clean_event_with_presences_with_people(
            self) -> None:
        ancestry = Ancestry()

        source = IdentifiableSource('S1', 'The Source')
        ancestry.sources[source.id] = source

        citation = IdentifiableCitation('C1', source)
        ancestry.citations[citation.id] = citation

        file = File('F1', __file__)
        ancestry.files[file.id] = file

        place = Place('P0', [PlaceName('The Place')])
        ancestry.places[place.id] = place

        person = Person('P0')

        event = IdentifiableEvent('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.events[event.id] = event

        Presence(person, Subject(), event)

        clean(ancestry)

        self.assertEqual(event, ancestry.events[event.id])
        self.assertIn(event, place.events)
        self.assertEqual(place, ancestry.places[place.id])
        self.assertIn(event, citation.facts)
        self.assertEqual(citation, ancestry.citations[citation.id])
        self.assertIn(event, file.resources)
        self.assertEqual(file, ancestry.files[file.id])
Ejemplo n.º 11
0
    def test_clean_should_clean_event(self) -> None:
        ancestry = Ancestry()

        source = IdentifiableSource('S1', 'The Source')
        ancestry.sources[source.id] = source

        citation = IdentifiableCitation('C1', source)
        ancestry.citations[citation.id] = citation

        file = File('F1', __file__)
        ancestry.files[file.id] = file

        place = Place('P0', [PlaceName('The Place')])
        ancestry.places[place.id] = place

        event = IdentifiableEvent('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.events[event.id] = event

        clean(ancestry)

        self.assertNotIn(event.id, ancestry.events)
        self.assertIsNone(event.place)
        self.assertNotIn(event, place.events)
        self.assertNotIn(place.id, ancestry.places)
        self.assertNotIn(event, citation.facts)
        self.assertNotIn(citation.id, ancestry.citations)
        self.assertNotIn(event, file.resources)
        self.assertNotIn(file.id, ancestry.files)
Ejemplo n.º 12
0
class DelegatingUrlGeneratorTest(TestCase):
    @parameterized.expand([
        ('/index.html', '/index.html'),
        ('/index.html', '<front>'),
        ('/person/index.html', '<person>'),
        ('/person/P1/index.html', Person('P1')),
        ('/event/index.html', '<event>'),
        ('/event/E1/index.html', Event('E1', Event.Type.DEATH)),
        ('/place/index.html', '<place>'),
        ('/place/P1/index.html', Place('P1', 'Place 1')),
        ('/file/index.html', '<file>'),
        ('/file/F1/index.html', File('F1', '/tmp')),
        ('/source/index.html', '<source>'),
        ('/source/S1/index.html', Source('S1', 'Source 1')),
        ('/citation/index.html', '<citation>'),
        ('/citation/C1/index.html', Citation('C1')),
    ])
    def test_generate(self, expected: str, resource: Any):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = DelegatingUrlGenerator(configuration)
        self.assertEquals(expected, sut.generate(resource))

    def test_generate_with_invalid_value(self):
        configuration = Configuration('/tmp', 'https://example.com')
        sut = DelegatingUrlGenerator(configuration)
        with self.assertRaises(ValueError):
            sut.generate(9)
Ejemplo n.º 13
0
 def test_description(self):
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     description = 'Hi, my name is Betty!'
     sut.description = description
     self.assertEquals(description, sut.description)
Ejemplo n.º 14
0
 async def test_without_width(self):
     file = File('F1', self.image_path, media_type=MediaType('image/png'))
     with self.assertRaises(ValueError):
         async with self._render(template_string='{{ file | image }}', data={
             'file': file,
         }):
             pass
Ejemplo n.º 15
0
 async def test_file(self):
     with NamedTemporaryFile() as f:
         file = File('PLACE1', f.name)
         self.site.ancestry.files[file.id] = file
         await generate(self.site)
         self.assert_betty_html('/file/%s/index.html' % file.id)
         self.assert_betty_json('/file/%s/index.json' % file.id, 'file')
Ejemplo n.º 16
0
 def test_privatize_source_should_privatize_if_private(self):
     file = File('F0', __file__)
     source = IdentifiableSource('S0', 'The Source')
     source.private = True
     source.files.append(file)
     privatize_source(source)
     self.assertTrue(source.private)
     self.assertTrue(file.private)
Ejemplo n.º 17
0
 def test_privatize_source_should_not_privatize_if_public(self):
     file = File('F0', __file__)
     source = IdentifiableSource('S0', 'The Source')
     source.private = False
     source.files.append(file)
     privatize_source(source)
     self.assertEqual(False, source.private)
     self.assertIsNone(file.private)
Ejemplo n.º 18
0
 def test_should_remove_files(self) -> None:
     source = IdentifiableSource('S0', 'The Source')
     file = File('F0', __file__)
     source.files.append(file)
     anonymous_source = AnonymousSource()
     anonymize_source(source, anonymous_source)
     self.assertEquals(0, len(source.files))
     self.assertIn(file, anonymous_source.files)
Ejemplo n.º 19
0
class FileTest(TestCase):
    @parameterized.expand([
        ('/file/F1.py', '{{ file | file }}', File('F1', __file__)),
        ('/file/F1.py:/file/F1.py', '{{ file | file }}:{{ file | file }}',
         File('F1', __file__)),
    ])
    def test(self, expected, template, file):
        with TemporaryDirectory() as output_directory_path:
            configuration = Configuration(output_directory_path,
                                          'https://example.com')
            environment = create_environment(Site(configuration))
            actual = environment.from_string(template).render(file=file)
            self.assertEquals(expected, actual)
            for file_path in actual.split(':'):
                self.assertTrue(
                    exists(
                        join(configuration.www_directory_path, file_path[1:])))
Ejemplo n.º 20
0
 def test_with_public_file_should_not_anonymize(self,
                                                m_anonymize_file) -> None:
     file = File('F0', __file__)
     file.private = False
     ancestry = Ancestry()
     ancestry.files[file.id] = file
     anonymize(ancestry)
     m_anonymize_file.assert_not_called()
Ejemplo n.º 21
0
 def test_with_private_file_should_anonymize(self,
                                             m_anonymize_file) -> None:
     file = File('F0', __file__)
     file.private = True
     ancestry = Ancestry()
     ancestry.files[file.id] = file
     anonymize(ancestry)
     m_anonymize_file.assert_called_once_with(file)
Ejemplo n.º 22
0
 def test_resources(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertCountEqual([], sut.resources)
     resources = [Mock(HasFiles), Mock(HasFiles)]
     sut.resources = resources
     self.assertCountEqual(resources, sut.resources)
Ejemplo n.º 23
0
 def test_media_type(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertIsNone(sut.media_type)
     media_type = MediaType('text/plain')
     sut.media_type = media_type
     self.assertEquals(media_type, sut.media_type)
Ejemplo n.º 24
0
 def test_notes(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertCountEqual([], sut.notes)
     notes = [Mock(Note), Mock(Note)]
     sut.notes = notes
     self.assertCountEqual(notes, sut.notes)
Ejemplo n.º 25
0
 def test_private(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertIsNone(sut.private)
     private = True
     sut.private = private
     self.assertEquals(private, sut.private)
Ejemplo n.º 26
0
 def test_citations(self) -> None:
     file_id = 'BETTY01'
     file_path = '/tmp/betty'
     sut = File(file_id, file_path)
     self.assertCountEqual([], sut.resources)
     citation = Mock(Citation)
     resources = [citation, Mock(HasFiles)]
     sut.resources = resources
     self.assertCountEqual([citation], sut.citations)
Ejemplo n.º 27
0
    def test_clean_should_clean_file(self) -> None:
        ancestry = Ancestry()

        file = File('F0', __file__)
        ancestry.files[file.id] = file

        clean(ancestry)

        self.assertNotIn(file.id, ancestry.files)
Ejemplo n.º 28
0
 def test_file_should_encode_minimal(self):
     with NamedTemporaryFile() as f:
         file = File('the_file', f.name)
         expected = {
             '$schema': '/schema.json#/definitions/file',
             'id': 'the_file',
             'entities': [],
             'notes': [],
         }
         self.assert_encodes(expected, file, 'file')
Ejemplo n.º 29
0
 def test_should_remove_files(self) -> None:
     source = Source('The Source')
     citation = IdentifiableCitation('C0', source)
     file = File('F0', __file__)
     citation.files.append(file)
     anonymous_source = AnonymousSource()
     anonymous_citation = AnonymousCitation(anonymous_source)
     anonymize_citation(citation, anonymous_citation)
     self.assertEquals(0, len(citation.files))
     self.assertIn(file, anonymous_citation.files)
Ejemplo n.º 30
0
 def test_privatize_source_should_privatize_if_private(self):
     file = File('F0', __file__)
     source = IdentifiableSource('S0', 'The Source')
     source.private = True
     source.files.append(file)
     ancestry = Ancestry()
     ancestry.sources[source.id] = source
     privatize(ancestry)
     self.assertTrue(source.private)
     self.assertTrue(file.private)