コード例 #1
0
ファイル: test_note.py プロジェクト: craws/OpenAtlas
 def test_note(self) -> None:
     with app.app_context():
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             actor = Entity.insert('person', 'Ripley')
         rv = self.app.get(url_for('note_insert', entity_id=actor.id))
         assert b'Description' in rv.data
         rv = self.app.post(url_for('note_insert', entity_id=actor.id),
                            data={'description': 'A nice description'},
                            follow_redirects=True)
         assert b'Note added' in rv.data
         rv = self.app.get(url_for('overview'))
         assert b'A nice description' in rv.data
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             user = User.get_by_username('Alice')
             if user:
                 note_id = User.get_notes_by_user_id(user.id)[0]['id']
         rv = self.app.get(url_for('note_update', id_=note_id))
         assert b'A nice description' in rv.data
         rv = self.app.post(url_for('note_update', id_=note_id),
                            data={'description': 'A very nice description'},
                            follow_redirects=True)
         assert b'Note updated' in rv.data \
                and b'A very nice description' in rv.data
         rv = self.app.get(url_for('note_view', id_=note_id))
         assert b'A very nice description' in rv.data
         rv = self.app.get(url_for('note_set_private', id_=note_id),
                           follow_redirects=True)
         assert b'Note updated' in rv.data
         rv = self.app.get(url_for('note_delete', id_=note_id),
                           follow_redirects=True)
         assert b'Note deleted' in rv.data
コード例 #2
0
 def test_source(self):
     with app.app_context():
         self.login()
         with app.test_request_context():
             app.preprocess_request()
             source_id = EntityMapper.insert('E33', 'Necronomicon', 'source content').id
         rv = self.app.get(url_for('translation_insert', source_id=source_id))
         assert b'+ Text' in rv.data
         data = {'name': 'Test translation'}
         rv = self.app.post(url_for('translation_insert', source_id=source_id), data=data)
         with app.test_request_context():
             app.preprocess_request()
             translation_id = rv.location.split('/')[-1]
         rv = self.app.get(url_for('source_view', id_=source_id))
         assert b'Test translation' in rv.data
         self.app.get(url_for('translation_update', id_=translation_id, source_id=source_id))
         rv = self.app.post(
             url_for('translation_update', id_=translation_id, source_id=source_id),
             data={'name': 'Translation updated'},
             follow_redirects=True)
         assert b'Translation updated' in rv.data
         rv = self.app.get(
             url_for('translation_delete', id_=translation_id, source_id=source_id),
             follow_redirects=True)
         assert b'The entry has been deleted.' in rv.data
         data = {'name': 'Translation continued', 'continue_': 'yes'}
         self.app.post(url_for('translation_insert', source_id=source_id), data=data)
コード例 #3
0
ファイル: test_member.py プロジェクト: acdh-oeaw/OpenAtlas
    def test_member(self) -> None:
        with app.app_context():
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                actor = Entity.insert('person', 'Ripley')
                group = Entity.insert('group', 'Space Marines')

            # Add membership
            rv = self.app.get(url_for('member_insert', origin_id=group.id))
            assert b'Actor function' in rv.data
            rv = self.app.post(url_for('member_insert',
                                       origin_id=actor.id,
                                       code='membership'),
                               data={'group': str([group.id])},
                               follow_redirects=True)
            assert b'Space Marines' in rv.data
            rv = self.app.post(url_for('member_insert',
                                       origin_id=actor.id,
                                       code='membership'),
                               data={
                                   'group': str([group.id]),
                                   'continue_': 'yes'
                               },
                               follow_redirects=True)
            assert b'Space Marines' in rv.data
            rv = self.app.post(url_for('member_insert',
                                       origin_id=group.id,
                                       code='membership'),
                               data={'group': str([group.id])})
            assert b"link to itself" in rv.data
            rv = self.app.post(url_for('member_insert', origin_id=actor.id),
                               data={'actor': str([actor.id])},
                               follow_redirects=True)
            assert b"link to itself" in rv.data

            # Add member to group
            data = {'actor': str([actor.id])}
            rv = self.app.post(url_for('member_insert', origin_id=group.id),
                               data=data,
                               follow_redirects=True)
            assert b'Ripley' in rv.data
            data['continue_'] = 'yes'
            rv = self.app.post(url_for('member_insert', origin_id=group.id),
                               data=data,
                               follow_redirects=True)
            assert b'Ripley' in rv.data

            # Update
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                link_id = Link.get_links(group.id, 'P107')[0].id
            rv = self.app.get(
                url_for('member_update', id_=link_id, origin_id=group.id))
            assert b'Ripley' in rv.data
            rv = self.app.post(
                url_for('member_update', id_=link_id, origin_id=group.id),
                data={'description': 'We are here to help you.'},
                follow_redirects=True)
            assert b'here to help' in rv.data
コード例 #4
0
    def test_member(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                actor = EntityMapper.insert('E21', 'Ripley')
                group = EntityMapper.insert('E74', 'Space Marines')

            # Add membership
            rv = self.app.get(url_for('member_insert', origin_id=group.id))
            assert b'Actor Function' in rv.data
            data = {'group': str([group.id])}
            rv = self.app.post(url_for('membership_insert',
                                       origin_id=actor.id),
                               data=data,
                               follow_redirects=True)
            assert b'Space Marines' in rv.data
            data = {'group': str([group.id]), 'continue_': 'yes'}
            rv = self.app.post(url_for('membership_insert',
                                       origin_id=actor.id),
                               data=data,
                               follow_redirects=True)
            assert b'Space Marines' in rv.data

            rv = self.app.post(url_for('membership_insert',
                                       origin_id=group.id),
                               data=data,
                               follow_redirects=True)
            assert b"Can't link to itself" in rv.data
            rv = self.app.post(url_for('member_insert', origin_id=actor.id),
                               data={'actor': str([actor.id])},
                               follow_redirects=True)
            assert b"Can't link to itself" in rv.data

            # Add member to group
            data = {'actor': str([actor.id])}
            rv = self.app.post(url_for('member_insert', origin_id=group.id),
                               data=data,
                               follow_redirects=True)
            assert b'Ripley' in rv.data
            data['continue_'] = 'yes'
            rv = self.app.post(url_for('member_insert', origin_id=group.id),
                               data=data,
                               follow_redirects=True)
            assert b'Ripley' in rv.data

            # Update
            with app.test_request_context():
                app.preprocess_request()
                link_id = LinkMapper.get_links(group.id, 'P107')[0].id
            rv = self.app.get(
                url_for('member_update', id_=link_id, origin_id=group.id))
            assert b'Ripley' in rv.data
            rv = self.app.post(
                url_for('member_update', id_=link_id, origin_id=group.id),
                data={'description': 'We are here to help you.'},
                follow_redirects=True)
            assert b'here to help' in rv.data
コード例 #5
0
    def test_involvement(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                actor_id = EntityMapper.insert('E21', 'Captain Miller').id
                event_id = EntityMapper.insert('E8', 'Event Horizon').id
                involvement_id = NodeMapper.get_hierarchy_by_name(
                    'Involvement').id

            # add involvement
            rv = self.app.get(url_for('involvement_insert',
                                      origin_id=actor_id))
            assert b'Involvement' in rv.data
            data = {
                'event': '[' + str(event_id) + ']',
                'activity': 'P11',
                involvement_id: involvement_id
            }
            rv = self.app.post(url_for('involvement_insert',
                                       origin_id=actor_id),
                               data=data,
                               follow_redirects=True)
            assert b'Event Horizon' in rv.data
            data = {
                'actor': '[' + str(actor_id) + ']',
                'continue_': 'yes',
                'activity': 'P22'
            }
            rv = self.app.post(url_for('involvement_insert',
                                       origin_id=event_id),
                               data=data,
                               follow_redirects=True)
            assert b'Event Horizon' in rv.data
            self.app.get(url_for('event_view', id_=event_id))

            # update involvement
            with app.test_request_context():
                app.preprocess_request()
                link_id = LinkMapper.get_links(event_id, 'P22')[0].id
            rv = self.app.get(
                url_for('involvement_update', id_=link_id, origin_id=event_id))
            assert b'Captain' in rv.data
            rv = self.app.post(url_for('involvement_update',
                                       id_=link_id,
                                       origin_id=actor_id),
                               data={
                                   'description':
                                   'Infinite Space - Infinite Terror',
                                   'activity': 'P23'
                               },
                               follow_redirects=True)
            assert b'Infinite Space - Infinite Terror' in rv.data
            self.app.get(url_for('event_view', id_=event_id))
コード例 #6
0
    def test_member(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                actor_id = EntityMapper.insert('E21', 'Ripley').id
                group_id = EntityMapper.insert('E74', 'Space Marines').id

            # Add membership
            rv = self.app.get(url_for('member_insert', origin_id=group_id))
            assert b'Actor Function' in rv.data
            data = {'group': '[' + str(group_id) + ']'}
            rv = self.app.post(
                url_for('membership_insert', origin_id=actor_id), data=data, follow_redirects=True)
            assert b'Space Marines' in rv.data
            data = {'group': '[' + str(group_id) + ']', 'continue_': 'yes'}
            rv = self.app.post(
                url_for('membership_insert', origin_id=actor_id), data=data, follow_redirects=True)
            assert b'Space Marines' in rv.data

            rv = self.app.post(
                url_for('membership_insert', origin_id=group_id), data=data, follow_redirects=True)
            assert b"Can't link to itself" in rv.data
            rv = self.app.post(url_for('member_insert', origin_id=actor_id),
                               data={'actor': '[' + str(actor_id) + ']'}, follow_redirects=True)
            assert b"Can't link to itself" in rv.data

            # Add member to group
            data = {'actor': '[' + str(actor_id) + ']'}
            rv = self.app.post(
                url_for('member_insert', origin_id=group_id), data=data, follow_redirects=True)
            assert b'Ripley' in rv.data
            data['continue_'] = 'yes'
            rv = self.app.post(
                url_for('member_insert', origin_id=group_id), data=data, follow_redirects=True)
            assert b'Ripley' in rv.data

            # Update
            with app.test_request_context():
                app.preprocess_request()
                link_id = LinkMapper.get_links(group_id, 'P107')[0].id
            rv = self.app.get(url_for('member_update', id_=link_id, origin_id=group_id))
            assert b'Ripley' in rv.data
            rv = self.app.post(
                url_for('member_update', id_=link_id, origin_id=group_id),
                data={'description': 'We are here to help you.'},
                follow_redirects=True)
            assert b'here to help' in rv.data
コード例 #7
0
ファイル: test_search.py プロジェクト: nhmvienna/OpenAtlas
 def test_search(self) -> None:
     with app.test_request_context():
         app.preprocess_request()  # type: ignore
         person = Entity.insert('person', 'Waldo')
         person.begin_to = '2018-01-01'
         person.update()
         person.link(
             'P131',
             Entity.insert('actor_appellation', 'Waldo alias'))
         object_ = Entity.insert('place', 'Waldorf')
         object_.link('P1', Entity.insert('appellation', 'Waldorf alias'))
         Entity.insert('person', 'Waldo without date')
     with app.app_context():  # type: ignore
         self.app.post(url_for('search_index'), data={'global-term': ''})
         rv = self.app.post(
             url_for('search_index'),
             data={
                 'global-term': 'wal',
                 'include_dateless': True,
                 'begin_year': -100, 'end_year': 3000})
         assert b'Waldo' in rv.data
         rv = self.app.post(
             url_for('search_index'),
             data={'term': 'wal', 'own': True})
         assert b'Waldo' not in rv.data
         data = {'term': 'do', 'classes': 'person'}
         rv = self.app.post(url_for('search_index'), data=data)
         assert b'Waldo' in rv.data
         rv = self.app.post(
             url_for('search_index'),
             follow_redirects=True,
             data={'term': 'x', 'begin_year': 2, 'end_year': -1})
         assert b'cannot start after' in rv.data
コード例 #8
0
    def test_node(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                actor_node = NodeMapper.get_hierarchy_by_name('Actor Actor Relation')
                sex_node = NodeMapper.get_hierarchy_by_name('Sex')
            rv = self.app.get(url_for('node_index'))
            assert b'Actor Actor Relation' in rv.data
            rv = self.app.get(url_for('node_insert', root_id=actor_node.id, super_id=actor_node.id))
            assert b'Actor Actor Relation' in rv.data
            rv = self.app.post(
                url_for('node_insert', root_id=actor_node.id), data={'name_search': 'new'})
            assert b'Inverse' in rv.data
            data = {
                'name': 'My secret node',
                'name_inverse': 'Do I look inverse?',
                'description': 'Very important!'}
            rv = self.app.post(url_for('node_insert', root_id=actor_node.id), data=data)
            node_id = rv.location.split('/')[-1].replace('node#tab-', '')
            rv = self.app.get(url_for('node_update', id_=node_id))
            assert b'My secret node' in rv.data and b'Super' in rv.data
            self.app.post(url_for('node_insert', root_id=sex_node.id), data=data)
            rv = self.app.post(
                url_for('node_update', id_=node_id), data=data, follow_redirects=True)
            assert b'Changes have been saved.' in rv.data

            # Test insert an continue
            data['continue_'] = 'yes'
            rv = self.app.post(
                url_for('node_insert', root_id=actor_node.id), data=data, follow_redirects=True)
            assert b'An entry has been created' in rv.data
            data['continue_'] = ''

            # Test forbidden system node
            rv = self.app.post(
                url_for('node_update', id_=actor_node.id), data=data, follow_redirects=True)
            assert b'Forbidden' in rv.data

            # Test update with self as root
            data[str(actor_node.id)] = node_id
            rv = self.app.post(
                url_for('node_update', id_=node_id), data=data, follow_redirects=True)
            assert b'Type can't have itself as super.' in rv.data

            # Test update with a child as root
            rv = self.app.post(url_for('node_insert', root_id=actor_node.id), data=data)
            child_node_id = rv.location.split('/')[-1].replace('node#tab-', '')
            data[str(actor_node.id)] = child_node_id
            rv = self.app.post(
                url_for('node_update', id_=node_id), data=data, follow_redirects=True)
            assert b'Type can't have a sub as super.' in rv.data

            # Test delete system node
            rv = self.app.get(url_for('node_delete', id_=actor_node.id), follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.get(url_for('node_delete', id_=child_node_id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #9
0
ファイル: test_model.py プロジェクト: craws/OpenAtlas
    def test_model(self) -> None:
        with app.app_context():
            rv = self.app.get(url_for('model_index'))
            assert b'Browse' in rv.data
            rv = self.app.get(url_for('openatlas_class_index'))
            assert b'Involvement' in rv.data
            rv = self.app.get(url_for('cidoc_class_index'))
            assert b'E1' in rv.data
            rv = self.app.get(url_for('cidoc_class_view', code='E4'))
            assert b'Domain for' in rv.data
            rv = self.app.get(url_for('property_index'))
            assert b'P1' in rv.data
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'P68' in rv.data
            rv = self.app.post(url_for('model_index'),
                               data={
                                   'cidoc_domain': 'E1',
                                   'cidoc_range': 'E1',
                                   'cidoc_property': 'P13'
                               })
            assert b'Wrong domain' in rv.data
            self.app.post(url_for('model_index'),
                          data={
                              'cidoc_domain': 'E1',
                              'cidoc_range': 'E1',
                              'cidoc_property': 'P67'
                          })

            with app.test_request_context():  # Insert data for network view
                app.preprocess_request()  # type: ignore
                actor = Entity.insert('person', 'King Arthur')
                event = Entity.insert('activity', 'Battle of Camlann')
                source = Entity.insert('source', 'The source')
                event.link('P11', actor)
                source.link('P67', event)
            self.app.get(url_for('model_network', dimensions=2))
            rv = self.app.get(url_for('model_network'))
            assert b'orphans' in rv.data
            rv = self.app.post(url_for('model_network'),
                               data={
                                   'orphans': True,
                                   'width': 100,
                                   'height': 40,
                                   'distance': -666,
                                   'charge': 500
                               })
            assert b'666' in rv.data
            rv = self.app.get(url_for('class_entities', code='E21'))
            assert b'King Arthur' in rv.data

            # Translations
            self.app.get('/index/setlocale/de')
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'verweist auf' in rv.data
            rv = self.app.get(url_for('cidoc_class_view', code='E18'))
            assert b'Materielles' in rv.data
            rv = self.app.get(url_for('property_view', code='P166'))
            assert b'was a presence of' in rv.data
コード例 #10
0
    def test_involvement(self):
        with app.app_context():
            self.login()
            rv = self.app.post(url_for('event_insert', code='E8'),
                               data={
                                    'name': 'Event Horizon',
                                    'date_begin_year': '1949',
                                    'date_begin_month': '10',
                                    'date_begin_day': '8',
                                    'date_end_year': '1951'})
            event_id = int(rv.location.split('/')[-1])
            with app.test_request_context():
                app.preprocess_request()
                actor_id = EntityMapper.insert('E21', 'Captain Miller').id
                involvement_id = NodeMapper.get_hierarchy_by_name('Involvement').id

            # Add involvement
            rv = self.app.get(url_for('involvement_insert', origin_id=actor_id))
            assert b'Involvement' in rv.data
            data = {'event': '[' + str(event_id) + ']', 'activity': 'P11',
                    involvement_id: involvement_id}
            rv = self.app.post(url_for('involvement_insert', origin_id=actor_id), data=data,
                               follow_redirects=True)
            assert b'Event Horizon' in rv.data
            data = {'actor': '[' + str(actor_id) + ']', 'continue_': 'yes', 'activity': 'P22'}
            rv = self.app.post(url_for('involvement_insert', origin_id=event_id), data=data,
                               follow_redirects=True)
            assert b'Event Horizon' in rv.data
            self.app.get(url_for('event_view', id_=event_id))

            # Update involvement
            with app.test_request_context():
                app.preprocess_request()
                link_id = LinkMapper.get_links(event_id, 'P22')[0].id
            rv = self.app.get(url_for('involvement_update', id_=link_id, origin_id=event_id))
            assert b'Captain' in rv.data
            rv = self.app.post(
                url_for('involvement_update', id_=link_id, origin_id=actor_id),
                data={'description': 'Infinite Space - Infinite Terror', 'activity': 'P23'},
                follow_redirects=True)
            assert b'Infinite Space - Infinite Terror' in rv.data
            self.app.get(url_for('event_view', id_=event_id))
コード例 #11
0
    def test_object(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                source = EntityMapper.insert('E33', 'Necronomicon')

            rv = self.app.get(url_for('object_insert'))
            assert b'+ Information Carrier' in rv.data
            rv = self.app.post(url_for('object_insert'), data={'name': 'Love-letter'},
                               follow_redirects=True)
            assert b'Love-letter' in rv.data
            rv = self.app.get(url_for('object_index'))
            assert b'Love-letter' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                object_ = EntityMapper.get_by_codes('object')[0]
            rv = self.app.get(url_for('object_update', id_=object_.id))
            assert b'Love-letter' in rv.data
            rv = self.app.post(url_for('object_update', id_=object_.id), follow_redirects=True,
                               data={'name': 'A little hate',
                                     'description': 'makes nothing better'})
            assert b'Changes have been saved' in rv.data

            # Add to object
            rv = self.app.get(url_for('object_add_source', id_=object_.id))
            assert b'Add Source' in rv.data
            rv = self.app.post(url_for('object_add_source', id_=object_.id),
                               data={'checkbox_values': str([source.id])}, follow_redirects=True)
            assert b'Necronomicon' in rv.data

            # Add to event
            rv = self.app.get(url_for('event_insert', code='E9', origin_id=object_.id))
            assert b'A little hate' in rv.data
            rv = self.app.post(url_for('event_insert', code='E9', origin_id=object_.id),
                               data={'name': 'Event Horizon', 'object': [object_.id]},
                               follow_redirects=True)
            assert b'Event Horizon' in rv.data

            rv = self.app.get(url_for('object_delete', id_=object_.id), follow_redirects=True)
            assert b'has been deleted' in rv.data
コード例 #12
0
 def test_search(self):
     self.login()
     with app.test_request_context():
         app.preprocess_request()
         EntityMapper.insert('E21', 'Waldo')
     with app.app_context():
         rv = self.app.post(url_for('index_search'), data={'global-term': 'wal'})
         assert b'Waldo' in rv.data
         rv = self.app.post(url_for('index_search'), data={'global-term': 'wal', 'own': True})
         assert b'Waldo' not in rv.data
         data = {'term': 'do', 'classes': 'actor'}
         rv = self.app.post(url_for('index_search'), data=data)
         assert b'Waldo' in rv.data
コード例 #13
0
    def test_export(self):
        with app.app_context():
            self.login()
            # Projects
            rv = self.app.get(url_for('import_project_insert'))
            assert b'Name *' in rv.data
            rv = self.app.post(url_for('import_project_insert'), data={'name': 'Project Import'})
            project_id = rv.location.split('/')[-1]
            rv = self.app.get(url_for('import_project_update', id_=project_id))
            assert b'Name *' in rv.data
            rv = self.app.post(url_for('import_project_update', id_=project_id),
                               follow_redirects=True, data={'name': 'Yup', 'description': 'whoa!'})
            assert b'whoa!' in rv.data
            rv = self.app.post(url_for('import_project_insert'), data={'name': 'Yup'},
                               follow_redirects=True)
            assert b'The name is already in use.' in rv.data
            rv = self.app.get(url_for('import_index'))
            assert b'Yup' in rv.data

            # Import data
            rv = self.app.get(url_for('import_data', class_code='E21', project_id=project_id))
            assert b'File *' in rv.data
            with open(os.path.dirname(__file__) + '/../static/import/example.csv', 'rb') as file:
                rv = self.app.post(
                    url_for('import_data', class_code='E18', project_id=project_id),
                    data={'file': file, 'duplicate': True}, follow_redirects=True)
            assert b'King Arthur' in rv.data
            with open(os.path.dirname(__file__) + '/../static/import/example.xlsx', 'rb') as file:
                rv = self.app.post(
                    url_for('import_data', class_code='E18', project_id=project_id),
                    data={'file': file, 'duplicate': True}, follow_redirects=True)
            assert b'IDs already in database' in rv.data
            with open(os.path.dirname(__file__) + '/../static/favicon.ico', 'rb') as file:
                rv = self.app.post(
                    url_for('import_data', class_code='E18', project_id=project_id),
                    data={'file': file}, follow_redirects=True)
            assert b'File type not allowed' in rv.data
            rv = self.app.get(url_for('import_project_view', id_=project_id))
            assert b'King Arthur' in rv.data

            # View an imported entity
            with app.test_request_context():
                app.preprocess_request()
                place_id = EntityMapper.get_by_codes('place')[0].id
            rv = self.app.get(url_for('actor_view', id_=place_id))
            assert b'Yup' in rv.data

            rv = self.app.get(url_for('import_project_delete', id_=project_id),
                              follow_redirects=True)
            assert b'Project deleted' in rv.data
コード例 #14
0
    def test_export(self):
        with app.app_context():
            self.login()
            # Projects
            rv = self.app.get(url_for('import_project_insert'))
            assert b'Name *' in rv.data
            rv = self.app.post(url_for('import_project_insert'), data={'name': 'Project Import'})
            project_id = rv.location.split('/')[-1]
            rv = self.app.get(url_for('import_project_update', id_=project_id))
            assert b'Name *' in rv.data
            rv = self.app.post(url_for('import_project_update', id_=project_id),
                               follow_redirects=True, data={'name': 'Yup', 'description': 'whoa!'})
            assert b'whoa!' in rv.data
            rv = self.app.post(url_for('import_project_insert'), data={'name': 'Yup'},
                               follow_redirects=True)
            assert b'The name is already in use.' in rv.data
            rv = self.app.get(url_for('import_index'))
            assert b'Yup' in rv.data

            # Import data
            rv = self.app.get(url_for('import_data', class_code='E21', project_id=project_id))
            assert b'File *' in rv.data
            with open(os.path.dirname(__file__) + '/../static/import/example.csv', 'rb') as file:
                rv = self.app.post(
                    url_for('import_data', class_code='E18', project_id=project_id),
                    data={'file': file, 'duplicate': True}, follow_redirects=True)
            assert b'King Arthur' in rv.data
            with open(os.path.dirname(__file__) + '/../static/import/example.xlsx', 'rb') as file:
                rv = self.app.post(
                    url_for('import_data', class_code='E18', project_id=project_id),
                    data={'file': file, 'duplicate': True}, follow_redirects=True)
            assert b'IDs already in database' in rv.data
            with open(os.path.dirname(__file__) + '/../static/favicon.ico', 'rb') as file:
                rv = self.app.post(
                    url_for('import_data', class_code='E18', project_id=project_id),
                    data={'file': file}, follow_redirects=True)
            assert b'File type not allowed' in rv.data
            rv = self.app.get(url_for('import_project_view', id_=project_id))
            assert b'King Arthur' in rv.data

            # View an imported entity
            with app.test_request_context():
                app.preprocess_request()
                place_id = EntityMapper.get_by_system_type('place')[0].id
            rv = self.app.get(url_for('actor_view', id_=place_id))
            assert b'Yup' in rv.data

            rv = self.app.get(url_for('import_project_delete', id_=project_id),
                              follow_redirects=True)
            assert b'Project deleted' in rv.data
コード例 #15
0
 def test_source(self):
     with app.app_context():
         self.login()
         with app.test_request_context():
             app.preprocess_request()
             source_id = EntityMapper.insert('E33', 'Necronomicon',
                                             'source content').id
         rv = self.app.get(
             url_for('translation_insert', source_id=source_id))
         assert b'+ Text' in rv.data
         data = {'name': 'Test translation'}
         rv = self.app.post(url_for('translation_insert',
                                    source_id=source_id),
                            data=data)
         with app.test_request_context():
             app.preprocess_request()
             translation_id = rv.location.split('/')[-1]
         rv = self.app.get(url_for('source_view', id_=source_id))
         assert b'Test translation' in rv.data
         self.app.get(
             url_for('translation_update',
                     id_=translation_id,
                     source_id=source_id))
         rv = self.app.post(url_for('translation_update',
                                    id_=translation_id,
                                    source_id=source_id),
                            data={'name': 'Translation updated'},
                            follow_redirects=True)
         assert b'Translation updated' in rv.data
         rv = self.app.get(url_for('translation_delete',
                                   id_=translation_id,
                                   source_id=source_id),
                           follow_redirects=True)
         assert b'The entry has been deleted.' in rv.data
         data = {'name': 'Translation continued', 'continue_': 'yes'}
         self.app.post(url_for('translation_insert', source_id=source_id),
                       data=data)
コード例 #16
0
ファイル: test_admin.py プロジェクト: craws/OpenAtlas
 def test_orphans_and_newsletter(self) -> None:
     with app.app_context():
         self.app.post(
             url_for('insert', class_='person'),
             data={
                 'name': 'Oliver Twist',
                 self.precision_geonames: '',
                 self.precision_wikidata: ''})
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             Entity.insert('file', 'One forsaken file entity')
         rv = self.app.get(url_for('admin_orphans'))
         assert all(x in rv.data for x in [b'Oliver Twist', b'forsaken'])
         rv = self.app.get(url_for('admin_newsletter'))
         assert b'Newsletter' in rv.data
コード例 #17
0
ファイル: test_admin.py プロジェクト: craws/OpenAtlas
 def test_similar(self) -> None:
     with app.app_context():
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             Entity.insert('person', 'I have the same name!')
             Entity.insert('person', 'I have the same name!')
         rv = self.app.post(
             url_for('admin_check_similar'),
             follow_redirects=True,
             data={'classes': 'person', 'ratio': 100})
         assert b'I have the same name!' in rv.data
         rv = self.app.post(
             url_for('admin_check_similar'),
             follow_redirects=True,
             data={'classes': 'file', 'ratio': 100})
         assert b'No entries' in rv.data
コード例 #18
0
ファイル: test_model.py プロジェクト: neural-oracle/OpenAtlas
    def test_model(self):
        with app.app_context():
            rv = self.app.get(url_for('model_index'))
            assert b'Browse' in rv.data
            rv = self.app.get(url_for('class_index'))
            assert b'E1' in rv.data
            rv = self.app.get(url_for('class_view', code='E4'))
            assert b'Domain for' in rv.data
            rv = self.app.get(url_for('property_index'))
            assert b'P1' in rv.data
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'P68' in rv.data
            data = {'domain': 'E1', 'range': 'E1', 'property': 'P13'}
            rv = self.app.post(url_for('model_index'), data=data)
            assert b'Wrong domain' in rv.data
            data = {'domain': 'E1', 'range': 'E1', 'property': 'P67'}
            rv = self.app.post(url_for('model_index'), data=data)
            assert b'Wrong domain' in rv.data

            self.login()
            with app.test_request_context(
            ):  # Insert data to display in network view
                app.preprocess_request()
                actor = EntityMapper.insert('E21', 'King Arthur')
                event = EntityMapper.insert('E7', 'Battle of Camlann')
                prop_object = EntityMapper.insert('E89',
                                                  'Propositional Object')
                LinkMapper.insert(actor, 'P11', event)
                LinkMapper.insert(actor, 'P67', prop_object)
            rv = self.app.get(url_for('model_network'))
            assert b'Orphans' in rv.data
            data = {
                'orphans': True,
                'width': 100,
                'height': 40,
                'distance': -666,
                'charge': 500
            }
            rv = self.app.post(url_for('model_network'), data=data)
            assert b'666' in rv.data

            # Translations
            self.app.get('/index/setlocale/de')
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'verweist auf' in rv.data
            rv = self.app.get(url_for('class_view', code='E4'))
            assert b'Phase' in rv.data
コード例 #19
0
 def test_dates(self) -> None:
     with app.app_context():  # type: ignore
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             # Create invalid dates for an actor and a relation link
             person = Entity.insert('person', 'Person')
             event = Entity.insert('activity', 'Event')
             person.begin_from = '2018-01-31'
             person.begin_to = '2018-01-01'
             person.update()
             involvement = Link.get_by_id(event.link('P11', person)[0])
             involvement.begin_from = '2017-01-31'
             involvement.begin_to = '2017-01-01'
             involvement.end_from = '2017-01-01'
             involvement.update()
         rv = self.app.get(url_for('admin_check_dates'))
         assert b'<span class="tab-counter">' in rv.data
コード例 #20
0
 def test_content_and_newsletter(self):
     with app.app_context():
         self.login()
         self.app.post(url_for('actor_insert', code='E21'), data={'name': 'Oliver Twist'})
         with app.test_request_context():
             app.preprocess_request()
             EntityMapper.insert('E61', '2017-04-01')  # Add orphaned date
             EntityMapper.insert('E31', 'One forsaken file entity', 'file')  # Add orphaned file
         rv = self.app.get(url_for('admin_orphans'))
         assert all(x in rv.data for x in [b'Oliver Twist', b'2017-04-01', b'forsaken'])
         rv = self.app.get(url_for('admin_orphans_delete', parameter='orphans'))
         assert b'2017-04-01' not in rv.data
         self.app.get(url_for('admin_orphans_delete', parameter='unlinked'))
         self.app.get(url_for('admin_orphans_delete', parameter='types'))
         self.app.get(url_for('admin_orphans_delete', parameter='whatever bogus string'))
         rv = self.app.get(url_for('admin_newsletter'))
         assert b'Newsletter' in rv.data
コード例 #21
0
    def test_model(self) -> None:
        with app.app_context():  # type: ignore
            rv = self.app.get(url_for('model_index'))
            assert b'Browse' in rv.data
            rv = self.app.get(url_for('class_index'))
            assert b'E1' in rv.data
            rv = self.app.get(url_for('class_view', code='E4'))
            assert b'Domain for' in rv.data
            rv = self.app.get(url_for('property_index'))
            assert b'P1' in rv.data
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'P68' in rv.data
            data: Dict[str, Any] = {'domain': 'E1', 'range': 'E1', 'property': 'P13'}
            rv = self.app.post(url_for('model_index'), data=data)
            assert b'Wrong domain' in rv.data
            data = {'domain': 'E1', 'range': 'E1', 'property': 'P67'}
            self.app.post(url_for('model_index'), data=data)

            with app.test_request_context():  # Insert data to display in network view
                app.preprocess_request()  # type: ignore
                actor = Entity.insert('person', 'King Arthur')
                event = Entity.insert(
                    'activity',
                    'Battle of Camlann - a long name that has to be truncated ..')
                source = Entity.insert('source', 'The source')
                actor.link('P11', event)
                source.link('P67', event)
            self.app.get(url_for('model_network', dimensions=2))
            rv = self.app.get(url_for('model_network'))
            assert b'orphans' in rv.data
            data = {'orphans': True, 'width': 100, 'height': 40, 'distance': -666, 'charge': 500}
            rv = self.app.post(url_for('model_network'), data=data)
            assert b'666' in rv.data

            rv = self.app.get(url_for('class_entities', code='E21'))
            assert b'King Arthur' in rv.data

            # Translations
            self.app.get('/index/setlocale/de')
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'verweist auf' in rv.data
            rv = self.app.get(url_for('class_view', code='E18'))
            assert b'Materielles' in rv.data
            rv = self.app.get(url_for('property_view', code='P166'))
            assert b'was a presence of' in rv.data
コード例 #22
0
ファイル: test_admin.py プロジェクト: craws/OpenAtlas
 def test_links(self) -> None:
     from openatlas.database.entity import Entity as DbEntity
     from openatlas.database.link import Link as DbLink
     with app.app_context():
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             id_ = DbEntity.insert({
                 'name': 'Invalid linked entity',
                 'openatlas_class_name': 'artifact',
                 'code': 'E13', 'description': ''})
             DbLink.insert({
                 'property_code': 'P86',
                 'domain_id': id_,
                 'range_id': id_,
                 'description': '',
                 'type_id': None})
             rv = self.app.get(url_for('admin_check_links'))
             assert b'Invalid linked entity' in rv.data
コード例 #23
0
ファイル: test_admin.py プロジェクト: thomaswoehlke/OpenAtlas
 def test_dates(self) -> None:
     self.login()
     with app.app_context():
         with app.test_request_context():
             app.preprocess_request()
             # Create invalid dates for an actor and a relation link
             person = EntityMapper.insert('E21', 'Person')
             event = EntityMapper.insert('E7', 'Event')
             person.begin_from = '2018-01-31'
             person.begin_to = '2018-01-01'
             person.update()
             involvement = LinkMapper.get_by_id(event.link('P11', person))
             involvement.begin_from = '2017-01-31'
             involvement.begin_to = '2017-01-01'
             involvement.end_from = '2017-01-01'
             involvement.update()
         rv = self.app.get(url_for('admin_check_dates'))
         assert b'Invalid dates <span class="tab-counter">1' in rv.data
         assert b'Invalid link dates <span class="tab-counter">1' in rv.data
         assert b'Invalid involvement dates <span class="tab-counter">1' in rv.data
コード例 #24
0
 def test_dates(self):
     self.login()
     with app.app_context():
         with app.test_request_context():
             app.preprocess_request()
             # Create invalid date links
             person_a = EntityMapper.insert('E21', 'Person A')
             person_b = EntityMapper.insert('E21', 'Person B')
             begin_date = EntityMapper.insert('E61', 'Begin date', 'exact date value',
                                              date='2018-01-31')
             end_date = EntityMapper.insert('E61', 'End date', 'exact date value',
                                            date='2018-01-01')
             person_a.link('OA1', begin_date)
             person_a.link('OA2', end_date)
             relation_id = person_a.link('OA7', person_b)
             LinkPropertyMapper.insert(relation_id, 'OA1', begin_date)
             LinkPropertyMapper.insert(relation_id, 'OA2', end_date)
         rv = self.app.get(url_for('admin_check_dates'))
         assert b'Invalid dates (1)' in rv.data
         assert b'Invalid link dates (1)' in rv.data
コード例 #25
0
ファイル: test_node.py プロジェクト: neural-oracle/OpenAtlas
    def test_node(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                actor_node = NodeMapper.get_hierarchy_by_name('Actor Actor Relation')
                sex_node = NodeMapper.get_hierarchy_by_name('Sex')
            rv = self.app.get(url_for('node_index'))
            assert b'Actor Actor Relation' in rv.data
            rv = self.app.post(
                url_for('node_insert', root_id=actor_node.id), data={'name_search': 'new'})
            assert b'Inverse' in rv.data
            data = {
                'name': 'My secret node',
                'name_inverse': 'Do I look inverse?',
                'description': 'Very important!'}
            rv = self.app.post(url_for('node_insert', root_id=actor_node.id), data=data)
            node_id = rv.location.split('/')[-1].replace('node#tab-', '')
            rv = self.app.get(url_for('node_update', id_=node_id))
            assert b'My secret node' in rv.data and b'Super' in rv.data
            self.app.post(url_for('node_insert', root_id=sex_node.id), data=data)
            rv = self.app.post(
                url_for('node_update', id_=node_id), data=data, follow_redirects=True)
            assert b'Changes have been saved.' in rv.data

            # Test forbidden system node
            rv = self.app.post(
                url_for('node_update', id_=actor_node.id), data=data, follow_redirects=True)
            assert b'Forbidden' in rv.data

            # Test update with self as root
            data[str(actor_node.id)] = node_id
            rv = self.app.post(
                url_for('node_update', id_=node_id), data=data, follow_redirects=True)
            assert b'super' in rv.data

            # Test delete system node
            rv = self.app.get(url_for('node_delete', id_=actor_node.id), follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.get(url_for('node_delete', id_=node_id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #26
0
ファイル: test_admin.py プロジェクト: thomaswoehlke/OpenAtlas
 def test_content_and_newsletter(self) -> None:
     with app.app_context():
         self.login()
         self.app.post(url_for('actor_insert', code='E21'),
                       data={'name': 'Oliver Twist'})
         with app.test_request_context():
             app.preprocess_request()
             EntityMapper.insert('E31', 'One forsaken file entity',
                                 'file')  # Add orphaned file
         rv = self.app.get(url_for('admin_orphans'))
         assert all(x in rv.data for x in [b'Oliver Twist', b'forsaken'])
         rv = self.app.get(
             url_for('admin_orphans_delete', parameter='orphans'))
         assert b'Oliver Twist' not in rv.data
         self.app.get(url_for('admin_orphans_delete', parameter='unlinked'))
         self.app.get(url_for('admin_orphans_delete', parameter='types'))
         self.app.get(
             url_for('admin_orphans_delete',
                     parameter='whatever bogus string'))
         rv = self.app.get(url_for('admin_newsletter'))
         assert b'Newsletter' in rv.data
コード例 #27
0
 def test_duplicates(self) -> None:
     with app.app_context():  # type: ignore
         with app.test_request_context():
             app.preprocess_request()  # type: ignore
             event = Entity.insert('acquisition', 'Event Horizon')
             source = Entity.insert('source', 'Tha source')
             source.link('P67', event)
             source.link('P67', event)
             source_node = Node.get_hierarchy('Source')
             source.link('P2', g.nodes[source_node.subs[0]])
             source.link('P2', g.nodes[source_node.subs[1]])
         rv = self.app.get(url_for('admin_check_link_duplicates'))
         assert b'Event Horizon' in rv.data
         rv = self.app.get(url_for('admin_check_link_duplicates',
                                   delete='delete'),
                           follow_redirects=True)
         assert b'Remove' in rv.data
         rv = self.app.get(url_for('admin_delete_single_type_duplicate',
                                   entity_id=source.id,
                                   node_id=source_node.subs[0]),
                           follow_redirects=True)
         assert b'Congratulations, everything looks fine!' in rv.data
コード例 #28
0
ファイル: test_admin.py プロジェクト: neural-oracle/OpenAtlas
 def test_content_and_newsletter(self):
     with app.app_context():
         self.login()
         self.app.post(url_for('actor_insert', code='E21'),
                       data={'name': 'Oliver Twist'})
         with app.test_request_context():
             app.preprocess_request()
             EntityMapper.insert('E61', '2017-04-01')  # add orphaned date
             EntityMapper.insert('E31', 'One forsaken file entity',
                                 'file')  # add orphaned file
         rv = self.app.get(url_for('admin_orphans'))
         assert all(x in rv.data
                    for x in [b'Oliver Twist', b'2017-04-01', b'forsaken'])
         rv = self.app.get(url_for('admin_orphans', delete='orphans'))
         assert b'2017-04-01' not in rv.data
         self.app.get(url_for('admin_orphans', delete='unlinked'))
         self.app.get(url_for('admin_orphans', delete='types'))
         self.app.get(
             url_for('admin_orphans',
                     delete='something completely different'))
         rv = self.app.get(url_for('admin_newsletter'))
         assert b'Newsletter' in rv.data
コード例 #29
0
 def test_note(self):
     with app.app_context():
         self.login()
         with app.test_request_context():
             app.preprocess_request()
             actor = EntityMapper.insert('E21', 'Ripley')
         rv = self.app.get(url_for('note_insert', entity_id=actor.id))
         assert b'Note *' in rv.data
         rv = self.app.post(url_for('note_insert', entity_id=actor.id),
                            data={'description': 'A nice description'},
                            follow_redirects=True)
         assert b'Note added' in rv.data
         rv = self.app.get(url_for('index'))
         assert b'A nice description' in rv.data
         rv = self.app.get(url_for('note_update', entity_id=actor.id))
         assert b'A nice description' in rv.data
         rv = self.app.post(url_for('note_update', entity_id=actor.id),
                            data={'description': 'A very nice description'},
                            follow_redirects=True)
         assert b'Note updated' in rv.data
         rv = self.app.get(url_for('note_delete', entity_id=actor.id), follow_redirects=True)
         assert b'Note deleted' in rv.data
コード例 #30
0
    def test_model(self):
        with app.app_context():
            rv = self.app.get(url_for('model_index'))
            assert b'Browse' in rv.data
            rv = self.app.get(url_for('class_index'))
            assert b'E1' in rv.data
            rv = self.app.get(url_for('class_view', code='E4'))
            assert b'Domain for' in rv.data
            rv = self.app.get(url_for('property_index'))
            assert b'P1' in rv.data
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'P68' in rv.data
            data = {'domain': 'E1', 'range': 'E1', 'property': 'P13'}
            rv = self.app.post(url_for('model_index'), data=data)
            assert b'Wrong domain' in rv.data
            data = {'domain': 'E1', 'range': 'E1', 'property': 'P67'}
            self.app.post(url_for('model_index'), data=data)

            self.login()
            with app.test_request_context():  # Insert data to display in network view
                app.preprocess_request()
                actor = EntityMapper.insert('E21', 'King Arthur')
                event = EntityMapper.insert('E7', 'Battle of Camlann')
                source = EntityMapper.insert('E33', 'Tha source')
                actor.link('P11', event)
                actor.link('P67', EntityMapper.insert('E89', 'Propositional Object'))
                source.link('P67', event)
            rv = self.app.get(url_for('model_network'))
            assert b'orphans' in rv.data
            data = {'orphans': True, 'width': 100, 'height': 40, 'distance': -666, 'charge': 500}
            rv = self.app.post(url_for('model_network'), data=data)
            assert b'666' in rv.data

            # Translations
            self.app.get('/index/setlocale/de')
            rv = self.app.get(url_for('property_view', code='P68'))
            assert b'verweist auf' in rv.data
            rv = self.app.get(url_for('class_view', code='E4'))
            assert b'Phase' in rv.data
コード例 #31
0
    def test_actor(self):
        with app.app_context():
            self.login()
            rv = self.app.get(url_for('actor_index'))
            assert b'No entries' in rv.data

            # Create entities for actor
            rv = self.app.post(url_for('place_insert'), data={'name': 'Nostromos'})
            residence_id = rv.location.split('/')[-1]
            with app.test_request_context():
                app.preprocess_request()
                sex_node = NodeMapper.get_hierarchy_by_name('Sex')
                sex_node_sub_1 = g.nodes[sex_node.subs[0]]
                sex_node_sub_2 = g.nodes[sex_node.subs[1]]
                event_id = EntityMapper.insert('E8', 'Event Horizon').id
                source_id = EntityMapper.insert('E33', 'Tha source').id

            # Actor insert
            rv = self.app.get(url_for('actor_insert', code='E21'))
            assert b'+ Person' in rv.data
            self.app.get(url_for('actor_insert', code='E21', origin_id=residence_id))
            data = {
                sex_node.id: sex_node_sub_1.id,
                'name': 'Sigourney Weaver',
                'alias-1': 'Ripley',
                'residence': residence_id,
                'appears_first': residence_id,
                'appears_last': residence_id,
                'description': 'Susan Alexandra Weaver is an American actress.',
                'date_begin_year': '-1949',
                'date_begin_month': '10',
                'date_begin_day': '8',
                'date_begin_year2': '-1948',
                'date_end_year': '2049',
                'date_end_year2': '2050',
                'date_birth': True,
                'date_death': True}
            rv = self.app.post(
                url_for('actor_insert', code='E21', origin_id=residence_id), data=data)
            actor_id = rv.location.split('/')[-1]

            # Test actor nodes
            rv = self.app.get(url_for('node_view', id_=sex_node_sub_1.id))
            assert b'Susan' in rv.data
            rv = self.app.get(url_for('node_move_entities', id_=sex_node_sub_1.id))
            assert b'Sigourney' in rv.data
            rv = self.app.post(url_for('node_move_entities', id_=sex_node_sub_1.id),
                               data={sex_node.id: sex_node_sub_2.id, 'selection': [actor_id]},
                               follow_redirects=True)
            assert b'Entities where updated' in rv.data
            rv = self.app.post(url_for('node_move_entities', id_=sex_node_sub_2.id),
                               data={sex_node.id: '', 'selection': [actor_id]},
                               follow_redirects=True)
            assert b'Entities where updated' in rv.data
            self.app.post(url_for('actor_insert', code='E21', origin_id=actor_id), data=data)
            self.app.post(url_for('actor_insert', code='E21', origin_id=event_id), data=data)
            self.app.post(url_for('actor_insert', code='E21', origin_id=source_id), data=data)
            rv = self.app.post(url_for('reference_insert', code='reference'), data={'name': 'Book'})
            reference_id = rv.location.split('/')[-1]
            rv = self.app.post(
                url_for('actor_insert', code='E21', origin_id=reference_id),
                data=data, follow_redirects=True)
            assert b'An entry has been created' in rv.data
            data['continue_'] = 'yes'
            rv = self.app.post(
                url_for('actor_insert', code='E21'), data=data, follow_redirects=True)
            assert b'An entry has been created' in rv.data
            rv = self.app.get(url_for('actor_index'))
            assert b'Sigourney Weaver' in rv.data

            # Actor update
            rv = self.app.get(url_for('actor_update', id_=actor_id))
            assert b'American actress' in rv.data
            data['name'] = 'Susan Alexandra Weaver'
            data['date_end_year'] = ''
            data['date_begin_year2'] = '1950'
            data['date_begin_day'] = ''
            rv = self.app.post(
                url_for('actor_update', id_=actor_id), data=data, follow_redirects=True)
            assert b'Susan Alexandra Weaver' in rv.data
            rv = self.app.post(
                url_for('ajax_bookmark'), data={'entity_id': actor_id}, follow_redirects=True)
            assert b'Remove bookmark' in rv.data
            rv = self.app.get('/')
            assert b'Weaver' in rv.data
            rv = self.app.post(
                url_for('ajax_bookmark'), data={'entity_id': actor_id}, follow_redirects=True)
            assert b'Bookmark' in rv.data
            rv = self.app.get(url_for('link_delete', origin_id=actor_id, id_=666),
                              follow_redirects=True)
            assert b'removed'in rv.data

            # Actor delete
            rv = self.app.get(url_for('actor_delete', id_=actor_id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #32
0
    def test_user(self) -> None:
        data = {
            'active': '',
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'you_never_guess_this',
            'group': 'admin',
            'name': 'Ripley Weaver',
            'description': '',
            'send_info': ''
        }
        data2 = {
            'active': '',
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'you_never_guess_this',
            'group': 'admin',
            'name': 'Newt',
            'continue_': 'yes',
            'send_info': ''
        }
        with app.app_context():  # type: ignore
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                logged_in_user = User.get_by_username('Alice')
                logged_in_user.remove_newsletter()
                if not logged_in_user:
                    abort(404)  # pragma: no cover
            rv = self.app.get(url_for('user_insert'))
            assert b'+ User' in rv.data
            rv = self.app.post(url_for('user_insert'), data=data)
            user_id = rv.location.split('/')[-1]
            data['password'] = '******'
            rv = self.app.post(url_for('user_insert'), data=data)
            assert b'match' in rv.data

            # Test insert with continue
            rv = self.app.post(url_for('user_insert'),
                               follow_redirects=True,
                               data=data2)
            assert b'Newt' not in rv.data

            rv = self.app.get(url_for('user_view', id_=user_id))
            assert b'Ripley' in rv.data
            rv = self.app.get(url_for('user_update', id_=logged_in_user.id))
            assert b'Alice' in rv.data
            data['description'] = 'The warrant officer'
            rv = self.app.post(url_for('user_update', id_=user_id),
                               data=data,
                               follow_redirects=True)
            assert b'The warrant officer' in rv.data
            rv = self.app.get(
                url_for('admin_index', action='delete_user', id_=user_id))
            assert b'User deleted' in rv.data

            # Test activity log
            data = {
                'name': 'test',
                'description': 'test'
            }  # insert a reference to show something
            self.app.post(url_for('insert', class_='bibliography'), data=data)
            rv = self.app.get(url_for('user_activity'))
            assert b'Activity' in rv.data
            rv = self.app.get(url_for('user_activity', user_id=user_id))
            assert b'Activity' in rv.data
            data = {'limit': 'all', 'action': 'all', 'user': '******'}
            rv = self.app.post(url_for('user_activity', data=data))
            assert b'Activity' in rv.data

            # Test missing permission
            self.app.get(url_for('logout'), follow_redirects=True)
            rv = self.app.get(url_for('user_insert'), follow_redirects=True)
            assert b'Forgot your password?' not in rv.data
            self.app.post('/login',
                          data={
                              'username': '******',
                              'password': '******'
                          })
            rv = self.app.get(url_for('user_insert'), follow_redirects=True)
            assert b'403 - Forbidden' in rv.data
コード例 #33
0
    def test_event(self) -> None:
        with app.app_context():  # type: ignore
            # Create entities for file
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                actor = Entity.insert('person', 'File keeper')
                reference = Entity.insert('edition', 'Ancient Books')
                node_id = Node.get_hierarchy('Sex').subs[0]

            # Insert
            rv = self.app.get(
                url_for('insert', class_='file', origin_id=actor.id))
            assert b'+ File' in rv.data
            logo = \
                pathlib.Path(app.root_path) \
                / 'static' / 'images' / 'layout' / 'logo.png'
            with open(logo, 'rb') as img:
                rv = self.app.post(url_for('insert',
                                           class_='file',
                                           origin_id=actor.id),
                                   data={
                                       'name': 'OpenAtlas logo',
                                       'file': img
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with open(logo, 'rb') as img1, open(logo, 'rb') as img2:
                rv = self.app.post(url_for('insert',
                                           class_='file',
                                           origin_id=actor.id),
                                   data={
                                       'name': 'OpenAtlas logo',
                                       'file': [img1, img2]
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with open(logo, 'rb') as img:
                rv = self.app.post(url_for('insert',
                                           class_='file',
                                           origin_id=reference.id),
                                   data={
                                       'name': 'OpenAtlas logo',
                                       'file': img
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                files = Entity.get_by_class('file')
                file_id = files[0].id
                file_id2 = files[1].id

            # Logo
            rv = self.app.get(url_for('admin_logo'),
                              data={'file': file_id},
                              follow_redirects=True)
            assert b'OpenAtlas logo' in rv.data
            with self.app.get(
                    url_for('display_logo', filename=str(file_id) + '.png')):
                pass  # Test logo with "with" to prevent unclosed files warning
            rv = self.app.get(url_for('admin_logo', id_=file_id),
                              follow_redirects=True)
            assert b'Remove custom logo' in rv.data
            rv = self.app.get(url_for('admin_index',
                                      action="remove_logo",
                                      id_=0),
                              follow_redirects=True)
            assert b'Logo' in rv.data

            with open(
                    pathlib.Path(app.root_path) / 'views' / 'index.py', 'rb') \
                    as invalid_file:
                rv = self.app.post(url_for('insert',
                                           class_='file',
                                           origin_id=actor.id),
                                   data={
                                       'name': 'Invalid file',
                                       'file': invalid_file
                                   },
                                   follow_redirects=True)
            assert b'File type not allowed' in rv.data

            rv = self.app.post(url_for('insert',
                                       class_='file',
                                       origin_id=actor.id),
                               follow_redirects=True,
                               data={'name': 'This is not a file'})
            assert b'This field is required' in rv.data

            # View
            rv = self.app.get(url_for('entity_view', id_=file_id))
            assert b'OpenAtlas logo' in rv.data
            rv = self.app.get(url_for('entity_view', id_=file_id2))
            assert b'OpenAtlas logo' in rv.data

            with self.app.get(
                    url_for('download_file', filename=str(file_id) + '.png')):
                pass  # Calling with "with" to prevent unclosed files warning
            with self.app.get(
                    url_for('display_file', filename=str(file_id) + '.png')):
                pass  # Calling with "with" to prevent unclosed files warning

            # Index
            rv = self.app.get(url_for('index', view='file'))
            assert b'OpenAtlas logo' in rv.data

            # Set and unset as main image
            self.app.get(url_for('set_profile_image',
                                 id_=file_id,
                                 origin_id=actor.id),
                         follow_redirects=True)
            self.app.get(
                url_for('file_remove_profile_image', entity_id=actor.id))

            # Add to reference
            rv = self.app.get(
                url_for('reference_add', id_=reference.id, view='file'))
            assert b'OpenAtlas logo' in rv.data
            rv = self.app.post(url_for('reference_add',
                                       id_=reference.id,
                                       view='file'),
                               data={
                                   'file': file_id,
                                   'page': '777'
                               },
                               follow_redirects=True)
            assert b'777' in rv.data

            # Update
            rv = self.app.get(url_for('update', id_=file_id))
            assert b'OpenAtlas logo' in rv.data
            rv = self.app.post(url_for('update', id_=file_id),
                               data={'name': 'Updated file'},
                               follow_redirects=True)
            assert b'Changes have been saved' in rv.data \
                   and b'Updated file' in rv.data
            rv = self.app.get(url_for('file_add', id_=file_id, view='actor'))
            assert b'Link actor' in rv.data
            rv = self.app.post(url_for('file_add', id_=file_id, view='actor'),
                               data={'checkbox_values': [actor.id]},
                               follow_redirects=True)
            assert b'File keeper' in rv.data
            rv = self.app.post(url_for('entity_add_file', id_=node_id),
                               data={'checkbox_values': str([file_id])},
                               follow_redirects=True)
            assert b'Updated file' in rv.data

            # Delete
            for file in files:
                rv = self.app.get(
                    url_for('index', view='file', delete_id=file.id))
                assert b'The entry has been deleted' in rv.data
コード例 #34
0
    def test_reference(self):

        with app.app_context():
            self.login()

            # Reference insert
            rv = self.app.get(url_for('reference_insert', code='bibliography'))
            assert b'+ Bibliography' in rv.data
            rv = self.app.get(url_for('reference_insert', code='edition'))
            assert b'+ Edition' in rv.data
            rv = self.app.get(url_for('reference_insert', code='carrier'))
            assert b'+ Carrier' in rv.data
            data = {'name': 'Test reference', 'description': 'Reference description'}
            rv = self.app.post(url_for('reference_insert', code='bibliography'), data=data)
            with app.test_request_context():
                app.preprocess_request()
                bibliography = EntityMapper.get_by_id(rv.location.split('/')[-1])
            data['continue_'] = 'yes'
            rv = self.app.post(url_for('reference_insert', code='carrier'), data=data,
                               follow_redirects=True)
            assert b'An entry has been created' in rv.data
            rv = self.app.get(url_for('reference_index'))

            # Reference update
            assert b'Test reference' in rv.data
            rv = self.app.get(url_for('reference_update', id_=bibliography.id))
            assert b'Test reference' in rv.data
            data['name'] = 'Test reference updated'
            rv = self.app.post(url_for('reference_update', id_=bibliography.id), data=data,
                               follow_redirects=True)
            assert b'Test reference updated' in rv.data

            # Reference link
            with app.test_request_context():
                app.preprocess_request()
                batman = EntityMapper.insert('E21', 'Batman')
            rv = self.app.get(url_for('reference_add', origin_id=batman.id))
            assert b'Batman' in rv.data
            rv = self.app.post(url_for('reference_add', origin_id=batman.id),
                               data={'reference': bibliography.id}, follow_redirects=True)
            assert b'Test reference updated' in rv.data

            rv = self.app.get(
                url_for('reference_add2', reference_id=bibliography.id, class_name='actor'))
            assert b'Batman' in rv.data
            rv = self.app.post(
                url_for('reference_add2', reference_id=bibliography.id, class_name='actor'),
                data={'actor': batman.id},
                follow_redirects=True)
            assert b'Test reference updated' in rv.data

            # Reference link update
            with app.test_request_context():
                app.preprocess_request()
                link_id = batman.get_links('P67', True)[0].id
                file = EntityMapper.insert('E31', 'The X-Files', 'file')
                file.link('P67', bibliography)
            rv = self.app.post(url_for(
                'reference_link_update', link_id=link_id,
                origin_id=bibliography.id), data={'page': '666'}, follow_redirects=True)
            assert b'Changes have been saved' in rv.data

            # Reference delete
            rv = self.app.get(url_for('reference_delete', id_=bibliography.id),
                              follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #35
0
ファイル: test_import.py プロジェクト: craws/OpenAtlas
    def test_import(self) -> None:
        with app.app_context():
            # Projects
            rv: Any = self.app.get(url_for('import_project_insert'))
            assert b'Name *' in rv.data
            rv = self.app.post(url_for('import_project_insert'),
                               data={'name': 'Project Import'})
            project_id = rv.location.split('/')[-1]
            rv = self.app.get(url_for('import_project_update', id_=project_id))
            assert b'Name *' in rv.data
            rv = self.app.post(url_for('import_project_update',
                                       id_=project_id),
                               data={
                                   'name': 'Yup',
                                   'description': 'whoa!'
                               },
                               follow_redirects=True)
            assert b'whoa!' in rv.data
            rv = self.app.post(url_for('import_project_insert'),
                               data={'name': 'Yup'},
                               follow_redirects=True)
            assert b'The name is already in use.' in rv.data
            rv = self.app.get(url_for('import_index'))
            assert b'Yup' in rv.data

            # Import data
            rv = self.app.get(
                url_for('import_data', class_='person', project_id=project_id))
            assert b'File *' in rv.data
            csv = Path(app.root_path) / 'static' / 'import' / 'example.csv'
            with open(csv, 'rb') as file:
                rv = self.app.post(url_for('import_data',
                                           class_='place',
                                           project_id=project_id),
                                   data={
                                       'file': file,
                                       'duplicate': True
                                   },
                                   follow_redirects=True)
            assert b'Vienna' in rv.data
            with open(csv, 'rb') as file:
                rv = self.app.post(url_for('import_data',
                                           class_='place',
                                           project_id=project_id),
                                   data={
                                       'file': file,
                                       'duplicate': True
                                   },
                                   follow_redirects=True)
            assert b'IDs already in database' in rv.data
            with open(Path(app.root_path) / 'static' / 'favicon.ico',
                      'rb') as file:
                rv = self.app.post(url_for('import_data',
                                           class_='place',
                                           project_id=project_id),
                                   data={'file': file},
                                   follow_redirects=True)
            assert b'File type not allowed' in rv.data
            rv = self.app.get(url_for('import_project_view', id_=project_id))
            assert b'London' in rv.data

            # View an imported entity
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                place_id = Entity.get_by_class('place')[0].id
            rv = self.app.get(url_for('view', id_=place_id))
            assert b'Yup' in rv.data

            rv = self.app.get(url_for('import_project_delete', id_=project_id),
                              follow_redirects=True)
            assert b'Project deleted' in rv.data
コード例 #36
0
    def test_source(self):
        with app.app_context():
            self.login()

            # Source insert
            rv = self.app.get(url_for('source_insert'))
            assert b'+ Source' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                origin_id = EntityMapper.insert('E21', 'David Duchovny').id
                actor_id = EntityMapper.insert('E21', 'Gillian Anderson Gillian Anderson ').id
                reference_id = EntityMapper.insert('E84', 'Ancient Books', 'information carrier').id
                file_id = EntityMapper.insert('E31', 'The X-Files', 'file').id

            rv = self.app.post(url_for('source_insert', origin_id=origin_id),
                               data={'name': 'Test source'}, follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                source_id = EntityMapper.get_by_codes('source')[0].id
            rv = self.app.post(url_for('source_insert', origin_id=reference_id),
                               data={'name': 'Test source'}, follow_redirects=True)
            assert b'Ancient Books' in rv.data
            rv = self.app.post(url_for('source_insert', origin_id=file_id),
                               data={'name': 'Test source'}, follow_redirects=True)
            assert b'An entry has been created' in rv.data and b'The X-Files' in rv.data
            data = {'name': 'Test source', 'continue_': 'yes'}
            rv = self.app.post(url_for('source_insert'), data=data, follow_redirects=True)
            assert b'An entry has been created' in rv.data
            rv = self.app.get(url_for('source_index'))
            assert b'Test source' in rv.data

            # Link source
            rv = self.app.post(url_for('reference_insert', code='edition', origin_id=source_id),
                               data={'name': 'Test reference'}, follow_redirects=True)
            assert b'Test source' in rv.data
            self.app.get(url_for('source_add', origin_id=actor_id))
            data = {'values': source_id}
            rv = self.app.post(url_for('source_add', origin_id=actor_id), data=data,
                               follow_redirects=True)
            assert b'Gillian Anderson' in rv.data

            self.app.get(url_for('source_add2', origin_id=actor_id, id_=source_id,
                                 class_name='actor'))
            rv = self.app.post(url_for('source_add2', id_=source_id, class_name='actor'),
                               data={'values': actor_id}, follow_redirects=True)
            assert b'Gillian Anderson' in rv.data
            rv = self.app.get(url_for('source_view', id_=source_id))
            assert b'Gillian Anderson' in rv.data
            rv = self.app.get(url_for('source_add2', id_=source_id, class_name='place'))
            assert b'Add Place' in rv.data

            # Update source
            rv = self.app.get(url_for('source_update', id_=source_id))
            assert b'Test source' in rv.data
            data = {'name': 'Source updated', 'description': 'some description'}
            rv = self.app.post(url_for('source_update', id_=source_id), data=data,
                               follow_redirects=True)
            assert b'Source updated' in rv.data
            rv = self.app.get(url_for('source_view', id_=source_id))
            assert b'some description' in rv.data

            # Delete source
            rv = self.app.get(url_for('source_delete', id_=source_id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #37
0
    def test_relation(self):
        with app.app_context():
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                actor_id = EntityMapper.insert('E21', 'Connor MacLeod').id
                related_id = EntityMapper.insert('E21', 'The Kurgan').id

            # Add relationship
            rv = self.app.get(url_for('relation_insert', origin_id=actor_id))
            assert b'Actor Actor Relation' in rv.data
            relation_id = NodeMapper.get_hierarchy_by_name('Actor Actor Relation').id
            relation_sub_id = g.nodes[relation_id].subs[0]
            data = {
                'actor': '[' + str(related_id) + ']',
                relation_id: relation_sub_id,
                'inverse': None,
                'date_begin_year': '-1949',
                'date_begin_month': '10',
                'date_begin_day': '8',
                'date_begin_year2': '-1948',
                'date_end_year': '2049',
                'date_end_year2': '2050'}
            rv = self.app.post(
                url_for('relation_insert', origin_id=actor_id), data=data, follow_redirects=True)
            assert b'The Kurgan' in rv.data
            rv = self.app.get(url_for('node_view', id_=relation_sub_id))
            assert b'Connor' in rv.data
            data['continue_'] = 'yes'
            data['inverse'] = True
            rv = self.app.post(
                url_for('relation_insert', origin_id=actor_id), data=data, follow_redirects=True)
            assert b'The Kurgan' in rv.data
            rv = self.app.get(url_for('actor_view', id_=actor_id))
            assert b'The Kurgan' in rv.data

            rv = self.app.post(
                url_for('relation_insert', origin_id=related_id), data=data, follow_redirects=True)
            assert b"Can't link to itself." in rv.data

            # Relation types
            rv = self.app.get(url_for('node_move_entities', id_=relation_sub_id))
            assert b'The Kurgan' in rv.data

            # Update relationship
            with app.test_request_context():
                app.preprocess_request()
                link_id = LinkMapper.get_links(actor_id, 'OA7')[0].id
                link_id2 = LinkMapper.get_links(actor_id, 'OA7', True)[0].id
            rv = self.app.get(url_for('relation_update', id_=link_id, origin_id=related_id))
            assert b'Connor' in rv.data
            rv = self.app.post(
                url_for('relation_update', id_=link_id, origin_id=actor_id),
                data={'description': 'There can be only one!', 'inverse': True},
                follow_redirects=True)
            assert b'only one' in rv.data
            rv = self.app.post(
                url_for('relation_update', id_=link_id2, origin_id=actor_id),
                data={'description': 'There can be only one!', 'inverse': None},
                follow_redirects=True)
            assert b'only one' in rv.data
コード例 #38
0
    def test_place(self):
        with app.app_context():
            self.login()
            rv = self.app.get(url_for('place_insert'))
            assert b'+ Place' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                unit_node = NodeMapper.get_hierarchy_by_name('Administrative Unit')
                unit_sub1 = g.nodes[unit_node.subs[0]]
                unit_sub2 = g.nodes[unit_node.subs[1]]
                reference_id = EntityMapper.insert('E31', 'Ancient Books', 'edition').id
                place_node = NodeMapper.get_hierarchy_by_name('Place')
                source_id = EntityMapper.insert('E33', 'Tha source').id
            data = {'name': 'Asgard', 'alias-0': 'Valhöll',
                    unit_node.id: '[' + str(unit_sub1.id) + ',' + str(unit_sub2.id) + ']'}
            rv = self.app.post(url_for('place_insert', origin_id=reference_id), data=data,
                               follow_redirects=True)
            assert b'Asgard' in rv.data
            gis_points = """[{"type":"Feature", "geometry":{"type":"Point", "coordinates":[9,17]},
                    "properties":{"name":"Valhalla","description":"","shapeType":"centerpoint"}}]"""
            data['gis_points'] = gis_points
            data['gis_polygons'] = """[{"geometry":{
                "coordinates":[[[9.75307425847859,17.8111792731339],
                [9.75315472474904,17.8110005175436],[9.75333711496205,17.8110873417098],
                [9.75307425847859,17.8111792731339]]],"type":"Polygon"},
                "properties":{"count":4,"description":"","id":8,"name":"",
                "objectDescription":"","objectId":185,"shapeType":"Shape",
                "siteType":"Settlement","title":""},"type":"Feature"}]"""
            data[place_node.id] = place_node.subs
            data['continue_'] = 'yes'
            rv = self.app.post(
                url_for('place_insert', origin_id=source_id), data=data, follow_redirects=True)
            assert b'Tha source' in rv.data

            with app.test_request_context():
                app.preprocess_request()
                places = EntityMapper.get_by_codes('place')
                place_id = places[0].id
                place2 = places[1]
                location = place2.get_linked_entity('P53')
                actor = EntityMapper.insert('E21', 'Milla Jovovich')
                actor.link('P74', location)
            assert b'Tha source' in rv.data
            rv = self.app.get(url_for('place_index'))
            assert b'Asgard' in rv.data
            rv = self.app.get(url_for('place_update', id_=place_id))
            assert b'Valhalla' in rv.data
            data['continue_'] = ''
            data['alias-1'] = 'Val-hall'
            rv = self.app.post(
                url_for('place_update', id_=place_id), data=data, follow_redirects=True)
            assert b'Val-hall' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                event = EntityMapper.insert('E8', 'Valhalla rising')
                event.link('P7', location)
                event.link('P24', location)
            rv = self.app.get(url_for('place_view', id_=place2.id))
            assert rv.data and b'Valhalla rising' in rv.data

            # Test invalid geom
            data['gis_polygons'] = """[{"type": "Feature", "geometry":
                {"type": "Polygon", "coordinates": [
                [[298.9893436362036, -5.888919049309554], [299.00444983737543, -5.9138487869408545],
                 [299.00650977389887, -5.893358673645309], [298.9848804404028, -5.9070188333813585],
                 [298.9893436362036, -5.888919049309554]]]},
                "properties": {"name": "", "description": "", "shapeType": "shape"}}]"""
            rv = self.app.post(
                url_for('place_insert', origin_id=source_id), data=data, follow_redirects=True)
            assert b'An invalid geometry was entered' in rv.data

            # Place types
            rv = self.app.get(url_for('node_move_entities', id_=unit_sub1.id))
            assert b'Asgard' in rv.data

            # Test move entities of multiple node if link to new node exists
            rv = self.app.post(url_for('node_move_entities', id_=unit_sub1.id),
                               data={unit_node.id: unit_sub2.id, 'selection': location.id},
                               follow_redirects=True)
            assert b'Entities where updated' in rv.data

            # Test move entities of multiple node if link to new node doesn't exists
            rv = self.app.post(url_for('node_move_entities', id_=unit_sub2.id),
                               data={unit_node.id: unit_sub1.id, 'selection': location.id},
                               follow_redirects=True)
            assert b'Entities where updated' in rv.data

            # Subunits
            with app.app_context():
                self.app.get(url_for('place_insert', origin_id=place_id))
                rv = self.app.post(url_for('place_insert', origin_id=place_id),
                                   data={'name': "It's not a bug, it's a feature!"})
                feat_id = rv.location.split('/')[-1]
                self.app.get(url_for('place_insert', origin_id=feat_id))
                self.app.get(url_for('place_update', id_=feat_id))
                self.app.post(url_for('place_update', id_=feat_id),
                              data={'name': "It's not a bug, it's a feature!"})
                rv = self.app.post(url_for('place_insert', origin_id=feat_id),
                                   data={'name':  "I'm a stratigraphic unit"})
                stratigraphic_id = rv.location.split('/')[-1]
                self.app.get(url_for('place_insert', origin_id=stratigraphic_id))
                self.app.get(url_for('place_update', id_=stratigraphic_id))
                self.app.post(url_for('place_update', id_=stratigraphic_id),
                              data={'name': "I'm a stratigraphic unit"})
                dimension_node_id = NodeMapper.get_hierarchy_by_name('Dimensions').subs[0]
                data = {'name': 'You never find me', str(dimension_node_id): '50'}
                rv = self.app.post(url_for('place_insert', origin_id=stratigraphic_id), data=data)
                find_id = rv.location.split('/')[-1]
                self.app.get(url_for('place_update', id_=find_id))
                self.app.post(url_for('place_update', id_=find_id), data=data)
            rv = self.app.get(url_for('place_view', id_=feat_id))
            assert b'not a bug' in rv.data
            rv = self.app.get(url_for('place_view', id_=stratigraphic_id))
            assert b'a stratigraphic unit' in rv.data
            rv = self.app.get(url_for('place_view', id_=find_id))
            assert b'You never' in rv.data
            rv = self.app.get(url_for('place_delete', id_=place_id), follow_redirects=True)
            assert b'not possible if subunits' in rv.data
            rv = self.app.get(url_for('place_delete', id_=find_id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
            rv = self.app.get(url_for('place_delete', id_=place2.id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #39
0
    def test_event(self):
        with app.app_context():
            self.login()

            # Create entities for event
            rv = self.app.post(url_for('place_insert'), data={'name': 'My house'})
            residence_id = rv.location.split('/')[-1]
            with app.test_request_context():
                app.preprocess_request()
                actor_id = EntityMapper.insert('E21', 'Game master').id
                file_id = EntityMapper.insert('E31', 'One forsaken file entity', 'file').id
                source_id = EntityMapper.insert('E33', 'Necronomicon', 'source content').id
                reference_id = EntityMapper.insert('E31', 'Ancient Books', 'edition').id

            # Insert
            rv = self.app.get(url_for('event_insert', code='E7'))
            assert b'+ Activity' in rv.data
            data = {
                'name': 'First event ever First event ever First event ever First event ever First',
                'place': residence_id}
            rv = self.app.post(url_for('event_insert', code='E7', origin_id=reference_id),
                               data=data, follow_redirects=True)
            assert b'First event ever' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                activity_id = EntityMapper.get_by_codes('event')[0].id

            self.app.post(url_for('event_insert', code='E7', origin_id=actor_id), data=data)
            self.app.post(url_for('event_insert', code='E7', origin_id=file_id), data=data)
            self.app.post(url_for('event_insert', code='E7', origin_id=source_id), data=data)

            rv = self.app.post(
                url_for('event_insert', code='E8'),
                data={
                    'name': 'Test event',
                    'given_place': '[' + str(residence_id) + ']',
                    'place': residence_id,
                    'event': activity_id,
                    'date_begin_year': '1949',
                    'date_begin_month': '10',
                    'date_begin_day': '8',
                    'date_end_year': '1951'})
            event_id = rv.location.split('/')[-1]
            rv = self.app.get(url_for('event_view', id_=event_id))
            assert b'Test event' in rv.data
            # Add another event and test if events are seen at place
            self.app.post(url_for('event_insert', code='E8'),
                          data={'name': 'Dusk', 'given_place': '[' + str(residence_id) + ']'})
            rv = self.app.get(url_for('place_view', id_=residence_id))
            assert b'Test event' in rv.data
            rv = self.app.get(url_for('actor_view', id_=actor_id))
            assert b'Game master' in rv.data
            rv = self.app.post(
                url_for('event_insert', code='E8'), follow_redirects=True,
                data={'name': 'Test event', 'continue_': 'yes'})
            assert b'An entry has been created' in rv.data
            rv = self.app.get(url_for('event_index'))
            assert b'Test event' in rv.data
            self.app.get(url_for('event_view', id_=activity_id))

            # Update
            rv = self.app.get(url_for('event_update', id_=activity_id))
            assert b'Test event' in rv.data
            rv = self.app.get(url_for('event_update', id_=event_id))
            assert b'First event ever' in rv.data
            data = {'name': 'Event updated'}
            rv = self.app.post(
                url_for('event_update', id_=event_id), data=data, follow_redirects=True)
            assert b'Event updated' in rv.data

            # Test super event validation
            data = {'name': 'Event Horizon', 'event': event_id}
            rv = self.app.post(
                url_for('event_update', id_=event_id), data=data, follow_redirects=True)
            assert b'error' in rv.data

            # Delete
            rv = self.app.get(url_for('event_delete', id_=event_id), follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #40
0
ファイル: test_place.py プロジェクト: nhmvienna/OpenAtlas
    def test_place(self) -> None:
        with app.app_context():  # type: ignore
            rv = self.app.get(url_for('insert', class_='place'))
            assert b'+ Place' in rv.data
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                unit_node = Node.get_hierarchy('Administrative unit')
                unit_sub1 = g.nodes[unit_node.subs[0]]
                unit_sub2 = g.nodes[unit_node.subs[1]]
                reference = Entity.insert('external_reference',
                                          'https://openatlas.eu')
                place_node = Node.get_hierarchy('Place')
                source = Entity.insert('source', 'Necronomicon')
            geonames = \
                f"reference_system_id_" \
                f"{ReferenceSystem.get_by_name('GeoNames').id}"
            precision = Node.get_hierarchy('External reference match').subs[0]
            data = {
                'name': 'Asgard',
                'alias-0': 'Valhöll',
                unit_node.id: str([unit_sub1.id, unit_sub2.id]),
                geonames: '123456',
                self.precision_geonames: precision,
                self.precision_wikidata: ''
            }
            rv = self.app.post(url_for('insert',
                                       class_='place',
                                       origin_id=reference.id),
                               data=data,
                               follow_redirects=True)
            assert b'Asgard' in rv.data \
                   and b'An entry has been created' in rv.data
            rv = self.app.get(url_for('entity_view', id_=precision))
            assert b'Asgard' in rv.data
            rv = self.app.get(
                url_for('entity_view',
                        id_=ReferenceSystem.get_by_name('GeoNames').id))
            assert b'Asgard' in rv.data

            data['gis_points'] = """[{
                "type": "Feature",
                "geometry": {"type":"Point","coordinates":[9,17]},
                "properties": {
                    "name": "Valhalla",
                    "description": "",
                    "shapeType": "centerpoint"}}]"""
            data['gis_lines'] = """[{
                "type": "Feature",
                "geometry":{
                    "type": "LineString",
                    "coordinates": [
                        [9.75307425847859,17.8111792731339],
                        [9.75315472474904,17.8110005175436],
                        [9.75333711496205,17.8110873417098]]},
                "properties": {
                    "name": "",
                    "description": "",
                    "shapeType": "line"}}]"""
            data['gis_polygons'] = """[{
                "type": "Feature",
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [[
                        [9.75307425847859,17.8111792731339],
                        [9.75315472474904,17.8110005175436],
                        [9.75333711496205,17.8110873417098],
                        [9.75307425847859,17.8111792731339]]]},
                "properties":{
                    "name": "",
                    "description": "",
                    "shapeType": "shape"}}]"""
            data[place_node.id] = place_node.subs
            data['continue_'] = 'yes'
            rv = self.app.post(url_for('insert',
                                       class_='place',
                                       origin_id=source.id),
                               data=data,
                               follow_redirects=True)
            assert b'Necronomicon' in rv.data
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                places = Entity.get_by_class('place')
                place = places[0]
                place2 = places[1]
                location = place2.get_linked_entity_safe('P53')
                actor = Entity.insert('person', 'Milla Jovovich')
                actor.link('P74', location)
            assert b'Necronomicon' in rv.data
            rv = self.app.get(url_for('index', view='place'))
            assert b'Asgard' in rv.data
            rv = self.app.get(url_for('update', id_=place.id))
            assert b'Valhalla' in rv.data
            data['continue_'] = ''
            data['alias-1'] = 'Val-hall'
            data['geonames_id'] = '321'
            rv = self.app.post(url_for('update', id_=place.id),
                               data=data,
                               follow_redirects=True)
            assert b'Val-hall' in rv.data

            # Test error when viewing the corresponding location
            rv = self.app.get(url_for('entity_view', id_=place.id + 1))
            assert b'be viewed directly' in rv.data

            # Test with same GeoNames id
            rv = self.app.post(url_for('update', id_=place.id),
                               data=data,
                               follow_redirects=True)
            assert b'Val-hall' in rv.data

            # Test with same GeoNames id but different precision
            data['geonames_precision'] = ''
            rv = self.app.post(url_for('update', id_=place.id),
                               data=data,
                               follow_redirects=True)
            assert b'Val-hall' in rv.data

            # Test update without the previous GeoNames id
            data['geonames_id'] = ''
            rv = self.app.post(url_for('update', id_=place.id),
                               data=data,
                               follow_redirects=True)
            assert b'Val-hall' in rv.data

            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                event = Entity.insert('acquisition', 'Valhalla rising')
                event.link('P7', location)
                event.link('P24', location)
            rv = self.app.get(url_for('entity_view', id_=place2.id))
            assert rv.data and b'Valhalla rising' in rv.data

            # Test invalid geom
            data['gis_polygons'] = """[{
                "type": "Feature", 
                "geometry": {
                    "type": "Polygon", 
                    "coordinates": [[
                        [298.9893436362036, -5.888919049309554], 
                        [299.00444983737543, -5.9138487869408545],
                        [299.00650977389887, -5.893358673645309], 
                        [298.9848804404028, -5.9070188333813585],
                        [298.9893436362036, -5.888919049309554]]]},
                "properties": {
                "name": "", 
                "description": "", 
                "shapeType": "shape"}}]"""
            rv = self.app.post(url_for('insert',
                                       class_='place',
                                       origin_id=source.id),
                               data=data,
                               follow_redirects=True)
            assert b'An invalid geometry was entered' in rv.data

            # Test Overlays
            path = \
                pathlib.Path(app.root_path) \
                / 'static' / 'images' / 'layout' / 'logo.png'
            with open(path, 'rb') as img:
                rv = self.app.post(url_for('insert',
                                           class_='file',
                                           origin_id=place.id),
                                   data={
                                       'name': 'X-Files',
                                       'file': img
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                file = Entity.get_by_class('file')[0]
                link_id = Link.insert(file, 'P67', place)[0]
            rv = self.app.get(
                url_for('overlay_insert',
                        image_id=file.id,
                        place_id=place.id,
                        link_id=link_id))
            assert b'X-Files' in rv.data
            data = {
                'top_left_easting': 42,
                'top_left_northing': 12,
                'top_right_easting': 43,
                'top_right_northing': 13,
                'bottom_left_easting': 10,
                'bottom_left_northing': 20
            }
            rv = self.app.post(url_for('overlay_insert',
                                       image_id=file.id,
                                       place_id=place.id,
                                       link_id=link_id),
                               data=data,
                               follow_redirects=True)
            assert b'Edit' in rv.data
            if os.name == "posix":  # Ignore for other OS e.g. Windows
                with app.test_request_context():
                    app.preprocess_request()  # type: ignore
                    overlay = Overlay.get_by_object(place)
                    overlay_id = overlay[list(overlay.keys())[0]].id
                rv = self.app.get(
                    url_for('overlay_update',
                            id_=overlay_id,
                            place_id=place.id,
                            link_id=link_id))
                assert b'42' in rv.data
                rv = self.app.post(url_for('overlay_update',
                                           id_=overlay_id,
                                           place_id=place.id,
                                           link_id=link_id),
                                   data=data,
                                   follow_redirects=True)
                assert b'Changes have been saved' in rv.data
                self.app.get(url_for('overlay_remove',
                                     id_=overlay_id,
                                     place_id=place.id),
                             follow_redirects=True)

            # Add to place
            rv = self.app.get(url_for('entity_add_file', id_=place.id))
            assert b'Link file' in rv.data

            rv = self.app.post(url_for('entity_add_file', id_=place.id),
                               data={'checkbox_values': str([file.id])},
                               follow_redirects=True)
            assert b'X-Files' in rv.data

            rv = self.app.get(
                url_for('reference_add', id_=reference.id, view='place'))
            assert b'Val-hall' in rv.data
            rv = self.app.get(url_for('entity_add_reference', id_=place.id))
            assert b'Link reference' in rv.data
            rv = self.app.post(url_for('entity_add_reference', id_=place.id),
                               data={
                                   'reference': reference.id,
                                   'page': '777'
                               },
                               follow_redirects=True)
            assert b'777' in rv.data

            # Place types
            rv = self.app.get(url_for('node_move_entities', id_=unit_sub1.id))
            assert b'Asgard' in rv.data

            # Test move entities of multiple node if link to new node exists
            rv = self.app.post(url_for('node_move_entities', id_=unit_sub1.id),
                               follow_redirects=True,
                               data={
                                   unit_node.id: unit_sub2.id,
                                   'selection': location.id,
                                   'checkbox_values': str([location.id])
                               })
            assert b'Entities were updated' in rv.data

            # Test move entities of multiple node
            rv = self.app.post(url_for('node_move_entities', id_=unit_sub2.id),
                               follow_redirects=True,
                               data={
                                   unit_node.id: unit_sub1.id,
                                   'selection': location.id,
                                   'checkbox_values': str([location.id])
                               })
            assert b'Entities were updated' in rv.data

            # Subunits
            data = {
                'name': "Try continue",
                'continue_': 'sub',
                self.precision_geonames: precision,
                self.precision_wikidata: ''
            }
            self.app.get(url_for('insert', class_='place'))
            rv = self.app.post(url_for('insert', class_='place'),
                               data=data,
                               follow_redirects=True)
            assert b'Insert and add strati' in rv.data
            data['name'] = "It's not a bug, it's a feature!"
            rv = self.app.get(
                url_for('insert',
                        class_='stratigraphic_unit',
                        origin_id=place.id))
            assert b'Insert and add find' in rv.data
            rv = self.app.post(url_for('insert',
                                       class_='place',
                                       origin_id=place.id),
                               data=data)
            feat_id = rv.location.split('/')[-1]
            self.app.get(url_for('insert', class_='place', origin_id=feat_id))
            self.app.get(url_for('update', id_=feat_id))
            self.app.post(url_for('update', id_=feat_id), data=data)
            data['name'] = "I'm a stratigraphic unit"
            rv = self.app.post(url_for('insert',
                                       class_='place',
                                       origin_id=feat_id),
                               data=data)
            stratigraphic_id = rv.location.split('/')[-1]
            self.app.get(
                url_for('insert', class_='place', origin_id=stratigraphic_id))
            self.app.get(url_for('update', id_=stratigraphic_id))
            self.app.post(url_for('update', id_=stratigraphic_id),
                          data={'name': "I'm a stratigraphic unit"})
            dimension_node_id = Node.get_hierarchy('Dimensions').subs[0]
            data = {
                'name': 'You never find me',
                dimension_node_id: 50,
                self.precision_geonames: precision,
                self.precision_wikidata: ''
            }
            rv = self.app.post(url_for('insert',
                                       class_='find',
                                       origin_id=stratigraphic_id),
                               data=data)
            find_id = rv.location.split('/')[-1]
            rv = self.app.post(url_for('update', id_=find_id),
                               data=data,
                               follow_redirects=True)
            assert b'50' in rv.data
            self.app.get(url_for('update', id_=find_id))
            data = {
                'name': 'My human remains',
                self.precision_geonames: precision,
                self.precision_wikidata: ''
            }
            rv = self.app.post(url_for('insert',
                                       class_='human_remains',
                                       origin_id=stratigraphic_id),
                               data=data)
            human_remains_id = rv.location.split('/')[-1]
            rv = self.app.get(url_for('update', id_=human_remains_id))
            assert b'My human remains' in rv.data
            rv = self.app.get('/')
            assert b'My human remains' in rv.data

            rv = self.app.get(url_for('entity_view', id_=feat_id))
            assert b'not a bug' in rv.data
            rv = self.app.get(url_for('entity_view', id_=stratigraphic_id))
            assert b'a stratigraphic unit' in rv.data
            rv = self.app.get(url_for('entity_view', id_=find_id))
            assert b'You never' in rv.data
            rv = self.app.get(url_for('index',
                                      view='place',
                                      delete_id=place.id),
                              follow_redirects=True)
            assert b'not possible if subunits' in rv.data
            rv = self.app.get(url_for('index', view='place',
                                      delete_id=find_id),
                              follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
            rv = self.app.get(
                url_for('index', view='place', delete_id=place2.id))
            assert b'The entry has been deleted.' in rv.data
コード例 #41
0
ファイル: test_image.py プロジェクト: craws/OpenAtlas
    def test_image(self) -> None:
        app.config['IMAGE_SIZE']['tmp'] = '1'
        with app.app_context():
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                place = insert_entity('Nostromos',
                                      'place',
                                      description='That is the Nostromos')
                logo = \
                    pathlib.Path(app.root_path) \
                    / 'static' / 'images' / 'layout' / 'logo.png'

            # Resizing through UI insert
            with open(logo, 'rb') as img:
                rv = self.app.post(url_for('insert',
                                           class_='file',
                                           origin_id=place.id),
                                   data={
                                       'name': 'OpenAtlas logo',
                                       'file': img
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data

            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                files = Entity.get_by_class('file')
                file_id = files[0].id

            # Set and unset as main image
            self.app.get(url_for('set_profile_image',
                                 id_=file_id,
                                 origin_id=place.id),
                         follow_redirects=True)

            # Delete through UI
            rv = self.app.get(url_for('index', view='file', delete_id=file_id))
            assert b'The entry has been deleted' in rv.data

            # Create entities for file
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                file_pathless = insert_entity('Pathless_File', 'file')

                file = insert_entity('Test_File', 'file')
                file.link('P2', g.types[Type.get_hierarchy('License').subs[0]])
                file_name = f'{file.id}.jpeg'
                src_png = \
                    pathlib.Path(app.root_path) \
                    / 'static' / 'images' / 'layout' / 'logo.png'
                dst_png = \
                    pathlib.Path(app.config['UPLOAD_DIR'] / file_name)
                copyfile(src_png, dst_png)

                file2 = insert_entity('Test_File2', 'file')
                file2.link('P2',
                           g.types[Type.get_hierarchy('License').subs[0]])
                file2_name = f'{file2.id}.jpeg'
                src2_png = \
                    pathlib.Path(app.root_path) \
                    / 'static' / 'images' / 'layout' / 'logo.png'
                dst2_png = pathlib.Path(app.config['UPLOAD_DIR'] / file2_name)
                copyfile(src2_png, dst2_png)

                file_py = insert_entity('Test_Py', 'file')
                file_name_py = f'{file_py.id}.py'
                src_py = pathlib.Path(app.root_path) / 'views' / 'index.py'
                dst_py = pathlib.Path(app.config['UPLOAD_DIR'] / file_name_py)
                copyfile(src_py, dst_py)

                # Exception
                safe_resize_image(file2.id, '.png', size="???")
                display_profile_image(file_pathless)

            # Resizing images (don't change order!)
            rv = self.app.get(url_for('view', id_=file.id))
            assert b'Test_File' in rv.data
            rv = self.app.get(url_for('view', id_=file_py.id))
            assert b'No preview available' in rv.data
            rv = self.app.get(url_for('view', id_=file_pathless.id))
            assert b'Missing file' in rv.data
            rv = self.app.get(url_for('index', view='file'))
            assert b'Test_File' in rv.data

            # Display file
            rv = self.app.get(url_for('display_file', filename=file_name))
            assert b'\xff' in rv.data
            rv = self.app.get(
                url_for('display_file',
                        filename=file_name,
                        size=app.config['IMAGE_SIZE']['thumbnail']))
            assert b'\xff' in rv.data
            rv = self.app.get(
                url_for('display_file',
                        filename=file_name,
                        size=app.config['IMAGE_SIZE']['table']))
            assert b'\xff' in rv.data
            rv = self.app.get(
                url_for('display_file',
                        filename=file_name_py,
                        size=app.config['IMAGE_SIZE']['table']))
            assert b'404' in rv.data

            # Make directory if not exist
            rv = self.app.get(url_for('view', id_=file.id))
            assert b'Test_File' in rv.data

            # Exception
            app.config['IMAGE_SIZE']['tmp'] = '<'
            rv = self.app.get(url_for('view', id_=file.id))
            assert b'Test_File' in rv.data
            app.config['IMAGE_SIZE']['tmp'] = '1'

            rv = self.app.get(url_for('admin_resize_images'),
                              follow_redirects=True)
            assert b'Images were created' in rv.data
            rv = self.app.get(url_for('admin_delete_orphaned_resized_images'),
                              follow_redirects=True)
            assert b'Resized orphaned images were deleted' in rv.data

            rv = self.app.get(url_for('index', view='file', delete_id=file.id))
            assert b'The entry has been deleted' in rv.data
            rv = self.app.get(url_for('index', view='file',
                                      delete_id=file2.id))
            assert b'The entry has been deleted' in rv.data

            shutil.rmtree(
                pathlib.Path(app.config['RESIZED_IMAGES'] /
                             app.config['IMAGE_SIZE']['tmp']))

            dst_py.unlink()
            del app.config['IMAGE_SIZE']['tmp']
コード例 #42
0
    def test_artifact(self) -> None:
        with app.app_context():
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                source = Entity.insert('source', 'Necronomicon')
                actor = Entity.insert('person', 'Conan')

            rv = self.app.get(url_for('insert', class_='artifact'))
            assert b'+ Artifact' in rv.data
            rv = self.app.post(
                url_for('insert', class_='artifact'),
                data={'name': 'Love-letter', 'actor': actor.id},
                follow_redirects=True)
            assert b'Love-letter' in rv.data
            rv = self.app.get(url_for('index', view='artifact'))
            assert b'Love-letter' in rv.data
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                artifact = Entity.get_by_view('artifact')[0]
            rv = self.app.get(url_for('update', id_=artifact.id))
            assert b'Love-letter' in rv.data
            rv = self.app.post(
                url_for('update', id_=artifact.id),
                follow_redirects=True,
                data={
                    'name': 'A little hate',
                    'description': 'makes nothing better'})
            assert b'Changes have been saved' in rv.data

            # Add to source
            rv = self.app.get(url_for('entity_add_source', id_=artifact.id))
            assert b'Link source' in rv.data
            rv = self.app.post(
                url_for('entity_add_source', id_=artifact.id),
                data={'checkbox_values': str([source.id])},
                follow_redirects=True)
            assert b'Necronomicon' in rv.data

            # Add to event
            rv = self.app.get(
                url_for('insert', class_='move', origin_id=artifact.id))
            assert b'A little hate' in rv.data
            rv = self.app.post(
                url_for('insert', class_='move', origin_id=artifact.id),
                data={'name': 'Event Horizon', 'artifact': [artifact.id]},
                follow_redirects=True)
            assert b'Event Horizon' in rv.data

            # Add to actor as owner
            rv = self.app.get(
                url_for('link_insert', id_=actor.id, view='artifact'))
            assert b'A little hate' in rv.data
            rv = self.app.post(
                url_for('link_insert', id_=actor.id, view='artifact'),
                data={'checkbox_values': [artifact.id]},
                follow_redirects=True)
            assert b'A little hate' in rv.data
            rv = self.app.get(url_for('view', id_=artifact.id))
            assert b'Owned by' in rv.data and b'Conan' in rv.data
            rv = self.app.get(
                url_for('insert', class_='artifact', origin_id=actor.id))
            assert b'Conan' in rv.data

            rv = self.app.get(
                url_for('index', view='artifact', delete_id=artifact.id))
            assert b'has been deleted' in rv.data

            # Insert and continue
            rv = self.app.post(
                url_for('insert', class_='artifact'),
                data={'name': 'This will be continued', 'continue_': 'yes'},
                follow_redirects=True)
            assert b'An entry has been created' in rv.data
コード例 #43
0
ファイル: test_type.py プロジェクト: craws/OpenAtlas
    def test_type(self) -> None:
        with app.app_context():
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                actor_type = Type.get_hierarchy('Actor actor relation')
                dimension_type = Type.get_hierarchy('Dimensions')
                historical_type = Type.get_hierarchy('Historical place')
                sex_type = Type.get_hierarchy('Sex')
                place = insert_entity('Home', 'place')
                place.link('P2', g.types[dimension_type.subs[0]], '46')
                location = place.get_linked_entity_safe('P53')
                location.link('P89', g.types[historical_type.subs[0]])
            rv: Any = self.app.get(url_for('view', id_=historical_type.subs[0]))
            assert b'Historical place' in rv.data
            rv = self.app.get(url_for('type_index'))
            assert b'Actor actor relation' in rv.data
            rv = self.app.get(
                url_for('insert', class_='type', origin_id=actor_type.id))
            assert b'Actor actor relation' in rv.data
            data = {
                'name': 'My secret type',
                'name_inverse': 'Do I look inverse?',
                'description': 'Very important!'}
            rv = self.app.post(
                url_for('insert', class_='type', origin_id=actor_type.id),
                data=data)
            type_id = rv.location.split('/')[-1]
            rv = self.app.get(url_for('update', id_=type_id))
            assert b'My secret type' in rv.data and b'Super' in rv.data
            self.app.post(
                url_for('insert', class_='type', origin_id=sex_type.id),
                data=data)
            rv = self.app.post(
                url_for('update', id_=type_id),
                data=data,
                follow_redirects=True)
            assert b'Changes have been saved.' in rv.data

            # Insert and continue
            data['continue_'] = 'yes'
            rv = self.app.post(
                url_for('insert', class_='type', origin_id=actor_type.id),
                data=data,
                follow_redirects=True)
            assert b'An entry has been created' in rv.data
            data['continue_'] = ''

            # Forbidden system type
            rv = self.app.post(
                url_for('update', id_=actor_type.id),
                data=data,
                follow_redirects=True)
            assert b'Forbidden' in rv.data

            # Update with self as root
            data[str(actor_type.id)] = type_id
            rv = self.app.post(
                url_for('update', id_=type_id),
                data=data,
                follow_redirects=True)
            assert b'Type can&#39;t have itself as super' in rv.data

            # Update with sub as root
            rv = self.app.post(
                url_for('insert', class_='type', origin_id=actor_type.id),
                data=data)
            sub_type_id = rv.location.split('/')[-1].replace('type#tab-', '')
            data[str(actor_type.id)] = sub_type_id
            rv = self.app.post(
                url_for('update', id_=type_id),
                data=data,
                follow_redirects=True)
            assert b'Type can&#39;t have a sub as super' in rv.data

            # Custom type
            rv = self.app.get(
                url_for('view', id_=sex_type.id),
                follow_redirects=True)
            assert b'Male' in rv.data

            # Administrative unit
            admin_unit_id = Type.get_hierarchy('Administrative unit').id
            rv = self.app.get(
                url_for('view', id_=admin_unit_id), follow_redirects=True)
            assert b'Austria' in rv.data
            rv = self.app.post(
                url_for(
                    'insert',
                    class_='administrative_unit',
                    origin_id=g.types[admin_unit_id].subs[0]),
                data={'name': 'admin unit'},
                follow_redirects=True)
            assert b'An entry has been created' in rv.data

            # Value type
            rv = self.app.get(
                url_for('view', id_=dimension_type.id),
                follow_redirects=True)
            assert b'Height' in rv.data
            rv = self.app.get(url_for('view', id_=dimension_type.subs[0]))
            assert b'Unit' in rv.data
            rv = self.app.get(url_for('update', id_=dimension_type.subs[0]))
            assert b'Dimensions' in rv.data

            # Test parent value type view after creating a sub subtype
            rv = self.app.post(
                url_for(
                    'insert',
                    class_='type',
                    origin_id=dimension_type.subs[0]),
                data={
                    'name': "Sub sub type",
                    dimension_type.id: dimension_type.subs[0]},
                follow_redirects=True)
            assert b'An entry has been created' in rv.data
            rv = self.app.get(url_for('view', id_=dimension_type.subs[0]))
            assert b'Sub sub type' in rv.data

            # Untyped entities
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                actor = Entity.insert('person', 'Connor MacLeod')
            rv = self.app.get(url_for('show_untyped_entities', id_=sex_type.id))
            assert b'Connor MacLeod' in rv.data
            with app.test_request_context():
                app.preprocess_request()  # type: ignore
                actor.link('P2', g.types[sex_type.subs[0]])
            rv = self.app.get(url_for('show_untyped_entities', id_=sex_type.id))
            assert b'No entries' in rv.data

            # Delete
            rv = self.app.get(
                url_for('type_delete', id_=actor_type.id),
                follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.get(
                url_for('type_delete', id_=sub_type_id),
                follow_redirects=True)
            assert b'The entry has been deleted.' in rv.data
コード例 #44
0
ファイル: test_file.py プロジェクト: neural-oracle/OpenAtlas
    def test_event(self):
        with app.app_context():
            self.login()

            # Create entities for file
            with app.test_request_context():
                app.preprocess_request()
                actor_id = EntityMapper.insert('E21', 'File keeper').id
                reference_id = EntityMapper.insert('E31', 'Ancient Books',
                                                   'edition').id

            # Insert
            rv = self.app.get(url_for('file_insert', origin_id=actor_id))
            assert b'+ File' in rv.data

            with open(
                    os.path.dirname(__file__) +
                    '/../static/images/layout/logo.png', 'rb') as img:
                rv = self.app.post(url_for('file_insert',
                                           code='E7',
                                           origin_id=actor_id),
                                   data={
                                       'name': 'OpenAtlas logo',
                                       'file': img
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with open(
                    os.path.dirname(__file__) +
                    '/../static/images/layout/logo.png', 'rb') as img:
                rv = self.app.post(url_for('file_insert',
                                           code='E7',
                                           origin_id=reference_id),
                                   data={
                                       'name': 'OpenAtlas logo',
                                       'file': img
                                   },
                                   follow_redirects=True)
            assert b'An entry has been created' in rv.data
            with app.test_request_context():
                app.preprocess_request()
                files = EntityMapper.get_by_system_type('file')
                file_id = files[0].id
                file_id2 = files[1].id

            with open(os.path.dirname(__file__) + '/test_file.py',
                      'rb') as invalid_file:
                rv = self.app.post(url_for('file_insert',
                                           code='E7',
                                           origin_id=actor_id),
                                   data={
                                       'name': 'Invalid file',
                                       'file': invalid_file
                                   },
                                   follow_redirects=True)
            assert b'File type not allowed' in rv.data

            rv = self.app.post(url_for('file_insert',
                                       code='E7',
                                       origin_id=actor_id),
                               data={'name': 'This is not a file'},
                               follow_redirects=True)
            assert b'This field is required' in rv.data

            # View
            rv = self.app.get(url_for('file_view', id_=file_id))
            assert b'OpenAtlas logo' in rv.data
            rv = self.app.get(url_for('file_view', id_=file_id2))
            assert b'OpenAtlas logo' in rv.data

            # Calling download, display urls with "with to prevent unclosed files warning
            with self.app.get(
                    url_for('download_file',
                            filename=str(file_id) + '.png')) as image:
                pass
            with self.app.get(
                    url_for('display_file',
                            filename=str(file_id) + '.png')) as image:
                pass

            # Index
            rv = self.app.get(url_for('file_index'))
            assert b'OpenAtlas logo' in rv.data

            # Add
            rv = self.app.get(url_for('file_add', origin_id=actor_id))
            assert b'Add File' in rv.data
            rv = self.app.post(url_for('file_add', origin_id=actor_id),
                               data={'values': file_id},
                               follow_redirects=True)
            assert b'OpenAtlas logo' in rv.data

            # Update
            rv = self.app.get(url_for('file_update', id_=file_id))
            assert b'OpenAtlas logo' in rv.data
            rv = self.app.post(url_for('file_update', id_=file_id),
                               data={'name': 'Updated file'},
                               follow_redirects=True)
            assert b'Changes have been saved' in rv.data and b'Updated file' in rv.data

            # Unlink
            rv = self.app.get(
                url_for('file_view', id_=file_id, unlink_id=actor_id))
            assert b'Link removed' in rv.data

            rv = self.app.get(
                url_for('file_add2', id_=file_id, class_name='actor'))
            assert b'Add Actor' in rv.data
            rv = self.app.post(url_for('file_add2',
                                       id_=file_id,
                                       class_name='actor'),
                               data={'values': actor_id},
                               follow_redirects=True)
            assert b'File keeper' in rv.data

            # Delete
            rv = self.app.get(url_for('file_delete', id_=file_id),
                              follow_redirects=True)
            assert b'The entry has been deleted' in rv.data
コード例 #45
0
    def test_user(self):
        data = {
            'active': '',
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'you_never_guess_this',
            'group': 'admin',
            'name': 'Ripley Weaver',
            'description': '',
            'send_info': ''}

        data2 = {
            'active': '',
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'password2': 'you_never_guess_this',
            'group': 'admin',
            'name': 'Newt',
            'continue_': 'yes',
            'send_info': ''}

        with app.app_context():
            rv = self.app.get(url_for('user_insert'), follow_redirects=True)
            assert b'Password' in rv.data
            self.app.post('/login', data={'username': '******', 'password': '******'})
            rv = self.app.get(url_for('user_insert'), follow_redirects=True)
            assert b'403 - Forbidden' in rv.data
            self.app.get(url_for('logout'), follow_redirects=True)
            self.login()
            with app.test_request_context():
                app.preprocess_request()
                logged_in_user_id = UserMapper.get_by_username('Alice').id
            rv = self.app.get(url_for('user_insert'))
            assert b'+ User' in rv.data
            rv = self.app.post(url_for('user_insert'), data=data)
            user_id = rv.location.split('/')[-1]
            data['password'] = '******'
            rv = self.app.post(url_for('user_insert'), data=data)
            assert b'match' in rv.data

            # Test with insert with continue
            rv = self.app.post(url_for('user_insert'), follow_redirects=True, data=data2)
            assert b'Newt' not in rv.data

            rv = self.app.get(url_for('user_view', id_=user_id))
            assert b'Ripley' in rv.data
            rv = self.app.get(url_for('user_update', id_=logged_in_user_id))
            assert b'Alice' in rv.data
            data['description'] = 'The warrant officer'
            rv = self.app.post(
                url_for('user_update', id_=user_id), data=data, follow_redirects=True)
            assert b'The warrant officer' in rv.data
            rv = self.app.get(url_for('user_delete', id_=user_id), follow_redirects=True)
            assert b'A user was deleted' in rv.data

            # Test activity log
            data = {'name': 'test', 'description': 'test'}  # insert a reference to show something
            self.app.post(url_for('reference_insert', code='bibliography'), data=data)
            rv = self.app.get(url_for('user_activity'))
            assert b'Activity' in rv.data
            rv = self.app.get(url_for('user_activity', user_id=user_id))
            assert b'Activity' in rv.data
            data = {'limit': 'all', 'action': 'all', 'user': '******'}
            rv = self.app.post(url_for('user_activity', data=data))
            assert b'Activity' in rv.data