Esempio n. 1
0
    def test_settings(self):
        with app.app_context():
            self.login()
            rv = self.app.get(url_for('admin_index'))
            assert b'User' in rv.data
            rv = self.app.get(url_for('settings_index'))
            assert b'Edit' in rv.data
            rv = self.app.get(url_for('settings_update'))
            assert b'Save' in rv.data
            data = {}
            for name in SettingsMapper.fields:
                data[name] = ''
            data['default_language'] = 'en'
            data['default_table_rows'] = '10'
            data['failed_login_forget_minutes'] = '10'
            data['failed_login_tries'] = '10'
            data['minimum_password_length'] = '10'
            data['random_password_length'] = '10'
            data['reset_confirm_hours'] = '10'
            data['log_level'] = '0'
            data['site_name'] = 'Nostromo'
            rv = self.app.post(url_for('settings_update'),
                               data=data,
                               follow_redirects=True)
            assert b'Nostromo' in rv.data

            rv = self.app.get(url_for('admin_file'))
            assert b'jpg' in rv.data
            rv = self.app.post(url_for('admin_file'),
                               data={'file_upload_max_size': 20},
                               follow_redirects=True)
            assert b'Changes have been saved.' in rv.data
 def test_logs(self):
     self.login()
     with app.app_context():
         rv = self.app.get(url_for('admin_log'))
         assert b'Login' in rv.data
         rv = self.app.get(url_for('admin_log_delete', follow_redirects=True))
         assert b'Login' not in rv.data
Esempio n. 3
0
    def test_hierarchy(self):
        with app.app_context():
            self.login()
            rv = self.app.get(url_for('hierarchy_insert', param='custom'))
            assert b'+ Custom' in rv.data
            data = {'name': 'Geronimo', 'multiple': True, 'description': 'Very important!'}
            rv = self.app.post(url_for('hierarchy_insert', param='custom'), data=data)
            hierarchy_id = rv.location.split('/')[-1].replace('types#tab-', '')
            rv = self.app.get(url_for('hierarchy_update', id_=hierarchy_id))
            assert b'Geronimo' in rv.data
            rv = self.app.post(
                url_for('hierarchy_update', id_=hierarchy_id), data=data, follow_redirects=True)
            assert b'Changes have been saved.' in rv.data
            data['name'] = 'Actor Actor Relation'
            rv = self.app.post(
                url_for('hierarchy_update', id_=hierarchy_id), data=data, follow_redirects=True)
            assert b'The name is already in use' in rv.data
            rv = self.app.post(url_for('hierarchy_delete', id_=hierarchy_id), follow_redirects=True)
            assert b'deleted' in rv.data

            # Test checks
            actor_node = NodeMapper.get_hierarchy_by_name('Actor Actor Relation')
            rv = self.app.get(url_for('hierarchy_update', id_=actor_node.id), follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.get(url_for('hierarchy_delete', id_=actor_node.id), follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.post(url_for('hierarchy_insert', param='custom'), data=data)
            assert b'The name is already in use' in rv.data
    def test_export(self):
        with app.app_context():
            self.login()

            # SQL export
            rv = self.app.get(url_for('export_sql'))
            assert b'Export SQL' in rv.data
            rv = self.app.post(url_for('export_sql'), follow_redirects=True)
            assert b'Data was exported as SQL' in rv.data
            date_string = DateMapper.current_date_for_filename()
            self.app.get(url_for('download_sql', filename=date_string + '_dump.sql'))
            rv = self.app.get(url_for('delete_sql', filename=date_string + '_dump.sql'),
                              follow_redirects=True)
            assert b'File deleted' in rv.data

            # CSV export
            rv = self.app.get(url_for('export_csv'))
            assert b'Export CSV' in rv.data
            rv = self.app.post(url_for('export_csv'), follow_redirects=True,
                               data={'zip': True, 'model_class': True,
                                     'gis_point': True, 'gis_format': 'wkt'})
            assert b'Data was exported as CSV' in rv.data
            rv = self.app.post(url_for('export_csv'), follow_redirects=True,
                               data={'model_class': True, 'timestamps': True,
                                     'gis_polygon': True, 'gis_format': 'postgis'})
            assert b'Data was exported as CSV' in rv.data
            rv = self.app.post(url_for('export_csv'), follow_redirects=True,
                               data={'model_class': True, 'timestamps': True, 'gis_point': True,
                                     'gis_polygon': True, 'gis_format': 'coordinates'})
            assert b'Data was exported as CSV' in rv.data
            date_string = DateMapper.current_date_for_filename()
            self.app.get(url_for('download_csv', filename=date_string + '_csv.zip'))
            rv = self.app.get(url_for('delete_csv', filename=date_string + '_csv.zip'),
                              follow_redirects=True)
            assert b'File deleted' in rv.data
Esempio n. 5
0
 def login(self) -> None:
     with app.app_context():  # type: ignore
         self.app.post('/login',
                       data={
                           'username': '******',
                           'password': '******'
                       })
Esempio n. 6
0
 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
Esempio n. 7
0
 def test_logs(self) -> None:
     with app.app_context():  # type: ignore
         rv = self.app.get(url_for('admin_log'))
         assert b'Login' in rv.data
         rv = self.app.get(
             url_for('admin_log_delete', follow_redirects=True))
         assert b'Login' not in rv.data
 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)
Esempio n. 9
0
    def test_date(self):
        with app.app_context():
            self.login()

            # Dates insert
            data = {'name': 'Date place',
                    'begin_year_from': -1949, 'begin_month_from': 2, 'begin_day_from': 8,
                    'begin_year_to': -1948, 'end_year_from': 2040, 'end_year_to': 2050}
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Date place' in rv.data

            # Invalid dates
            data['begin_day_from'] = 31
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Not a valid date' in rv.data

            # Invalid time span (first after second date)
            data['begin_day_from'] = 5
            data['begin_year_from'] = 20
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'First date cannot be after second' in rv.data

            # Invalid begin dates which are after end dates
            data['begin_year_from'] = -1949
            data['end_year_from'] = -2000
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
            data['end_year_to'] = ''
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
Esempio n. 10
0
 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
    def test_date(self):
        with app.app_context():
            self.login()

            # dates insert
            data = {
                'name': 'Date place',
                'date_begin_year': -1949,
                'date_begin_month': 2,
                'date_begin_day': 8,
                'date_begin_year2': -1948,
                'date_end_year': 2040,
                'date_end_year2': 2050,
                'date_birth': True,
                'date_death': True}
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Date place' in rv.data

            data['date_begin_day'] = 31  # test invalid dates
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Not a valid date' in rv.data

            data['date_begin_day'] = 5
            data['date_begin_year'] = 20  # test invalid time span (first after second date)
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'First date cannot be after second' in rv.data

            data['date_begin_year'] = -1949
            data['date_end_year'] = -2000  # test invalid begin dates which are after end dates
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
            data['date_end_year2'] = ''
            rv = self.app.post(url_for('place_insert'), data=data, follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
Esempio n. 12
0
    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
Esempio n. 13
0
 def test_logs(self):
     self.login()
     with app.app_context():
         rv = self.app.get(url_for('admin_log'))
         assert b'Login' in rv.data
         rv = self.app.get(
             url_for('admin_log_delete', follow_redirects=True))
         assert b'Login' not in rv.data
Esempio n. 14
0
    def test_date(self) -> None:
        with app.app_context():  # type: ignore
            # Dates insert (don't change year values - they test leap years too)
            data = {
                'name': 'Date place',
                'begin_year_from': -1949,
                'begin_month_from': 2,
                'begin_day_from': 8,
                'begin_year_to': -1948,
                'end_year_from': 1996,
                'end_year_to': 1996,
                self.precision_geonames: '',
                self.precision_wikidata: ''}
            rv = self.app.post(
                url_for('insert', class_='place'),
                data=data,
                follow_redirects=True)
            assert b'Date place' in rv.data

            # Invalid dates
            data['begin_day_from'] = 31
            rv = self.app.post(
                url_for('insert', class_='place'),
                data=data,
                follow_redirects=True)
            assert b'Not a valid date' in rv.data

            # Invalid time span (first after second date)
            data['begin_day_from'] = 5
            data['begin_year_from'] = 20
            rv = self.app.post(
                url_for('insert', class_='place'),
                data=data,
                follow_redirects=True)
            assert b'First date cannot be after second' in rv.data

            # Invalid begin dates which are after end dates
            data['begin_year_from'] = -1949
            data['end_year_from'] = -2000
            rv = self.app.post(
                url_for('insert', class_='place'),
                data=data,
                follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
            data['end_year_to'] = ''
            rv = self.app.post(
                url_for('insert', class_='place'),
                data=data,
                follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data

            # Missing form fields
            data['begin_year_from'] = ''
            rv = self.app.post(
                url_for('insert', class_='place'),
                data=data,
                follow_redirects=True)
            assert b'Required for time span' in rv.data
Esempio n. 15
0
    def test_profile(self):
        with app.app_context():
            self.login()

            # test profile update
            rv = self.app.get(url_for('profile_index'))
            assert b'*****@*****.**' in rv.data
            data = {
                'language': 'en',
                'table_rows': '100',
                'layout': 'advanced',
                'theme': 'default'
            }
            rv = self.app.post(url_for('profile_index'),
                               data=data,
                               follow_redirects=True)
            assert b'saved' in rv.data
            rv = self.app.get(url_for('profile_update'))
            assert b'Newsletter' in rv.data
            data = {
                'name': 'Alice Abernathy',
                'email': '*****@*****.**',
                'show_email': '',
                'newsletter': ''
            }
            rv = self.app.post(url_for('profile_update'),
                               data=data,
                               follow_redirects=True)
            assert b'Alice Abernathy' in rv.data

            # test change password
            rv = self.app.get(url_for('profile_password'))
            assert b'Old password' in rv.data
            new_pass = '******'
            data = {
                'password_old': 'test',
                'password': new_pass,
                'password2': new_pass
            }
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'Your password has been updated' in rv.data
            data['password2'] = 'short'
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'match' in rv.data
            data['password_old'] = new_pass
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'New password is like old one' in rv.data
            data['password'] = '******'
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'too short' in rv.data
    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
Esempio n. 17
0
    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
Esempio n. 18
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
Esempio n. 19
0
    def test_profile(self) -> None:
        with app.app_context():  # type: ignore
            # Profile update
            rv = self.app.get(url_for('profile_index'))
            assert b'*****@*****.**' in rv.data
            rv = self.app.get(url_for('profile_settings', category='profile'))
            assert b'*****@*****.**' in rv.data
            data = {
                'name': 'Alice Abernathy',
                'email': '*****@*****.**',
                'show_email': ''
            }
            rv = self.app.post(url_for('profile_settings', category='profile'),
                               data=data,
                               follow_redirects=True)
            assert b'saved' in rv.data
            assert b'Alice Abernathy' in rv.data
            rv = self.app.post(url_for('profile_settings', category='display'),
                               data={
                                   'language': 'en',
                                   'table_rows': 10,
                                   'layout': 'default',
                                   'map_zoom_default': 10,
                                   'map_zoom_max': 10
                               },
                               follow_redirects=True)
            assert b'saved' in rv.data
            assert b'English' in rv.data

            # Change password
            rv = self.app.get(url_for('profile_password'))
            assert b'Old password' in rv.data
            new_pass = '******'
            data = {
                'password_old': 'test',
                'password': new_pass,
                'password2': new_pass
            }
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'Your password has been updated' in rv.data
            data['password2'] = 'short'
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'match' in rv.data
            data['password_old'] = new_pass
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'New password is like old one' in rv.data
            data['password'] = '******'
            rv = self.app.post(url_for('profile_password'),
                               data=data,
                               follow_redirects=True)
            assert b'too short' in rv.data
Esempio n. 20
0
    def test_settings(self) -> None:
        with app.app_context():  # type: ignore
            rv = self.app.get(url_for('admin_index'))
            assert b'User' in rv.data

            # Mail
            rv = self.app.get(url_for('admin_settings', category='mail'))
            assert b'Recipients feedback' in rv.data
            rv = self.app.post(url_for('admin_settings', category='mail'),
                               follow_redirects=True,
                               data={
                                   'mail':
                                   True,
                                   'mail_transport_username':
                                   '******',
                                   'mail_transport_host':
                                   'localhost',
                                   'mail_transport_port':
                                   '23',
                                   'mail_from_email':
                                   '*****@*****.**',
                                   'mail_from_name':
                                   'Max Headroom',
                                   'mail_recipients_feedback':
                                   '*****@*****.**'
                               })
            assert b'Max Headroom' in rv.data

            rv = self.app.get(url_for('admin_settings', category='general'))
            assert b'Log level' in rv.data

            # Content
            rv = self.app.post(url_for('admin_content',
                                       item='citation_example'),
                               data={
                                   'en': 'citation as example',
                                   'de': ''
                               },
                               follow_redirects=True)
            assert b'Changes have been saved' in rv.data
            rv = self.app.get(url_for('insert', class_='edition'))
            assert b'citation as example' in rv.data
            rv = self.app.get(url_for('admin_content', item='legal_notice'))
            assert b'Save' in rv.data
            rv = self.app.post(url_for('admin_content', item='legal_notice'),
                               data={
                                   'en': 'My legal notice',
                                   'de': 'German notice'
                               },
                               follow_redirects=True)
            assert b'My legal notice' in rv.data
            self.app.get('/index/setlocale/de')
            rv = self.app.get(url_for('index_content', item='legal_notice'))
            assert b'German notice' in rv.data
    def test_index(self):
        with app.app_context():
            rv = self.app.get('/')
            assert b'Overview' in rv.data
            rv = self.app.get('/some_missing_site')
            assert b'404' in rv.data
            rv = self.app.get(url_for('index_changelog'))
            assert b'2.0.0' in rv.data
            self.app.get(url_for('index_content', item='contact'))
            rv = self.app.get(url_for('index_credits'))
            assert b'Stefan Eichert' in rv.data
            self.app.get(url_for('set_locale', language='en'))
            rv = self.app.get(url_for('login'))
            assert b'Password' in rv.data
            rv = self.app.post(url_for('login'), data={'username': '******', 'password': '******'})
            assert b'No user with this name found' in rv.data
            rv = self.app.post(url_for('login'), data={'username': '******', 'password': '******'})
            assert b'Wrong Password' in rv.data
            rv = self.app.post(url_for('login'), data={'username': '******', 'password': '******'})
            assert b'This user is not activated' in rv.data
            for i in range(4):
                rv = self.app.post(url_for('login'), data={'username': '******', 'password': '******'})
            assert b'Too many login attempts' in rv.data

            # test reset password, unsubscribe
            rv = self.app.get(url_for('reset_password'))
            assert b'Forgot your password?' in rv.data
            rv = self.app.get(url_for('reset_confirm', code='1234'))
            assert b'404' in rv.data
            rv = self.app.get(url_for('index_unsubscribe', code='1234'))
            assert b'invalid' in rv.data

            self.login()
            rv = self.app.get(url_for('reset_password'))
            assert b'Forgot your password?' not in rv.data
            rv = self.app.get('/')
            assert b'0' in rv.data
            rv = self.app.get(url_for('index_feedback'))
            assert b'Thank you' in rv.data

            # test redirection to overview if trying to login again
            rv = self.app.get(url_for('login'), follow_redirects=True)
            assert b'first' in rv.data
            rv = self.app.get(url_for('set_locale', language='de'), follow_redirects=True)
            assert b'Quelle' in rv.data
            rv = self.app.get(url_for('logout'), follow_redirects=True)
            assert b'Password' in rv.data
            rv = self.app.get('/404')
            assert b'not found' in rv.data

            # raise an id not found error
            self.login()
            rv = self.app.get('/actor/view/666', follow_redirects=True)
            assert b'teapot' in rv.data
Esempio n. 22
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))
Esempio n. 23
0
    def test_hierarchy(self):
        with app.app_context():
            self.login()

            # Custom types
            data = {
                'name': 'Geronimo',
                'forms': [1, 2, 4, 5, 6],
                'multiple': True,
                'description': 'Very important!'}
            rv = self.app.post(url_for('hierarchy_insert', param='custom'), data=data)
            hierarchy_id = rv.location.split('/')[-1].replace('types#tab-', '')
            rv = self.app.get(url_for('hierarchy_update', id_=hierarchy_id))
            assert b'Geronimo' in rv.data
            data['forms'] = [3]
            rv = self.app.post(
                url_for('hierarchy_update', id_=hierarchy_id), data=data, follow_redirects=True)
            assert b'Changes have been saved.' in rv.data

            rv = self.app.get(url_for('hierarchy_insert', param='custom'))
            assert b'+ Custom' in rv.data

            data = {'name': 'My secret node', 'description': 'Very important!'}
            rv = self.app.post(url_for('node_insert', root_id=hierarchy_id), data=data)
            node_id = rv.location.split('/')[-1].replace('types#tab-', '')
            rv = self.app.get(url_for('hierarchy_remove_form', id_=hierarchy_id, remove_id=2),
                              follow_redirects=True)
            assert b'Changes have been saved.' in rv.data
            self.app.get(url_for('node_delete', id_=node_id))

            data['name'] = 'Actor Actor Relation'
            rv = self.app.post(
                url_for('hierarchy_update', id_=hierarchy_id), data=data, follow_redirects=True)
            assert b'The name is already in use' in rv.data
            rv = self.app.post(url_for('hierarchy_delete', id_=hierarchy_id), follow_redirects=True)
            assert b'deleted' in rv.data

            # Value types
            rv = self.app.get(url_for('hierarchy_insert', param='value'))
            assert b'+ Value' in rv.data
            data2 = {'name': 'A valued value type', 'forms': [1], 'description': ''}
            rv = self.app.post(url_for('hierarchy_insert', param='value'), data=data2)
            custom_hierarchy_id = rv.location.split('/')[-1].replace('types#tab-', '')
            rv = self.app.get(url_for('hierarchy_update', id_=custom_hierarchy_id))
            assert b'valued' in rv.data

            # Test checks
            actor_node = NodeMapper.get_hierarchy_by_name('Actor Actor Relation')
            rv = self.app.get(url_for('hierarchy_update', id_=actor_node.id), follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.get(url_for('hierarchy_delete', id_=actor_node.id), follow_redirects=True)
            assert b'Forbidden' in rv.data
            rv = self.app.post(url_for('hierarchy_insert', param='custom'), data=data)
            assert b'The name is already in use' in rv.data
Esempio n. 24
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
Esempio n. 25
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
    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
 def test_admin(self):
     with app.app_context():
         self.login()
         rv = self.app.get(url_for('admin_mail'))
         assert b'Email from' in rv.data
         rv = self.app.get(url_for('admin_index'))
         assert b'User' in rv.data
         rv = self.app.get(url_for('admin_general'))
         assert b'Edit' in rv.data
         rv = self.app.get(url_for('admin_general_update'))
         assert b'Save' in rv.data
         rv = self.app.get(url_for('admin_map'))
         assert b'MaxClusterRadius' in rv.data
         rv = self.app.post(url_for('admin_map'), follow_redirects=True, data={
             'map_cluster_enabled': True, 'map_cluster_max_radius': 2,
             'map_cluster_disable_at_zoom': 5})
         assert b'Changes have been saved.' in rv.data
         data = {name: '' for name in SettingsMapper.fields}
         data['default_language'] = 'en'
         data['default_table_rows'] = '10'
         data['failed_login_forget_minutes'] = '10'
         data['failed_login_tries'] = '10'
         data['minimum_password_length'] = '10'
         data['random_password_length'] = '10'
         data['reset_confirm_hours'] = '10'
         data['log_level'] = '0'
         data['site_name'] = 'Nostromo'
         data['minimum_jstree_search'] = 3
         data['minimum_tablesorter_search'] = 4
         rv = self.app.post(url_for('admin_general_update'), data=data, follow_redirects=True)
         assert b'Nostromo' in rv.data
         rv = self.app.get(url_for('admin_mail_update'))
         assert b'Mail transport port' in rv.data
         data = {
             'mail': True,
             'mail_transport_username': '******',
             'mail_transport_host': 'localhost',
             'mail_transport_port': '23',
             'mail_from_email': '*****@*****.**',
             'mail_from_name': 'Max Headroom',
             'mail_recipients_feedback': '*****@*****.**'}
         rv = self.app.post(url_for('admin_mail_update'), data=data, follow_redirects=True)
         assert b'Max Headroom' in rv.data
         rv = self.app.get(url_for('admin_file'))
         assert b'jpg' in rv.data
         rv = self.app.post(
             url_for('admin_file'), data={'file_upload_max_size': 20, 'profile_image_width': 20},
             follow_redirects=True)
         assert b'Changes have been saved.' in rv.data
Esempio n. 28
0
 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
    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
Esempio n. 30
0
 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
 def test_content(self):
     with app.app_context():
         self.login()
         rv = self.app.get(url_for('content_view', item='legal_notice'))
         assert b'Edit' in rv.data
         rv = self.app.get(url_for('content_update', item='legal_notice'))
         assert b'Save' in rv.data
         data = {'en': 'Legal notice', 'de': 'Impressum'}
         rv = self.app.post(
             url_for('content_update', item='legal_notice'), data=data, follow_redirects=True)
         assert b'Impressum' in rv.data
         rv = self.app.get(url_for('content_index', item='legal_notice'))
         assert b'Text' in rv.data
         self.app.get('/index/setlocale/de')
         rv = self.app.get('/', follow_redirects=True)
         assert b'Impressum' in rv.data
Esempio n. 32
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'}
            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
Esempio n. 33
0
    def test_date(self):
        with app.app_context():
            self.login()

            # dates insert
            data = {
                'name': 'Date place',
                'date_begin_year': -1949,
                'date_begin_month': 2,
                'date_begin_day': 8,
                'date_begin_year2': -1948,
                'date_end_year': 2040,
                'date_end_year2': 2050,
                'date_birth': True,
                'date_death': True
            }
            rv = self.app.post(url_for('place_insert'),
                               data=data,
                               follow_redirects=True)
            assert b'Date place' in rv.data

            data['date_begin_day'] = 31  # test invalid dates
            rv = self.app.post(url_for('place_insert'),
                               data=data,
                               follow_redirects=True)
            assert b'Not a valid date' in rv.data

            data['date_begin_day'] = 5
            data[
                'date_begin_year'] = 20  # test invalid time span (first after second date)
            rv = self.app.post(url_for('place_insert'),
                               data=data,
                               follow_redirects=True)
            assert b'First date cannot be after second' in rv.data

            data['date_begin_year'] = -1949
            data[
                'date_end_year'] = -2000  # test invalid begin dates which are after end dates
            rv = self.app.post(url_for('place_insert'),
                               data=data,
                               follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
            data['date_end_year2'] = ''
            rv = self.app.post(url_for('place_insert'),
                               data=data,
                               follow_redirects=True)
            assert b'Begin dates cannot start after end dates' in rv.data
Esempio n. 34
0
 def test_content(self):
     with app.app_context():
         self.login()
         rv = self.app.get(url_for('content_view', item='legal_notice'))
         assert b'Edit' in rv.data
         rv = self.app.get(url_for('content_update', item='legal_notice'))
         assert b'Save' in rv.data
         data = {'en': 'Legal notice', 'de': 'Impressum'}
         rv = self.app.post(url_for('content_update', item='legal_notice'),
                            data=data,
                            follow_redirects=True)
         assert b'Impressum' in rv.data
         rv = self.app.get(url_for('content_index', item='legal_notice'))
         assert b'Text' in rv.data
         self.app.get('/index/setlocale/de')
         rv = self.app.get('/', follow_redirects=True)
         assert b'Impressum' in rv.data
Esempio n. 35
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
Esempio n. 36
0
    def setUp(self) -> None:
        app.testing = True
        app.config['SERVER_NAME'] = 'local.host'
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['WTF_CSRF_METHODS'] = []  # Disable CSRF in tests

        self.setup_database()
        self.app = app.test_client()
        self.login()  # Login on default because needed almost everywhere
        with app.app_context():
            self.app.get('/')  # Needed to initialise g
            self.precision_geonames = \
                'reference_system_precision_' + \
                str(ReferenceSystem.get_by_name('GeoNames').id)
            self.precision_wikidata = \
                'reference_system_precision_' + \
                str(ReferenceSystem.get_by_name('Wikidata').id)
 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
Esempio n. 38
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
Esempio n. 39
0
 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
    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))
Esempio n. 41
0
 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
 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
Esempio n. 43
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
    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
    def test_profile(self):
        with app.app_context():
            self.login()

            # test profile update
            rv = self.app.get(url_for('profile_index'))
            assert b'*****@*****.**' in rv.data
            data = {'language': 'en', 'table_rows': '100', 'layout': 'advanced', 'theme': 'default'}
            rv = self.app.post(url_for('profile_index'), data=data, follow_redirects=True)
            assert b'saved' in rv.data
            rv = self.app.get(url_for('profile_update'))
            assert b'Newsletter' in rv.data
            data = {
                'name': 'Alice Abernathy',
                'email': '*****@*****.**',
                'show_email': '',
                'newsletter': ''}
            rv = self.app.post(url_for('profile_update'), data=data, follow_redirects=True)
            assert b'Alice Abernathy' in rv.data

            # test change password
            rv = self.app.get(url_for('profile_password'))
            assert b'Old password' in rv.data
            new_pass = '******'
            data = {'password_old': 'test', 'password': new_pass, 'password2': new_pass}
            rv = self.app.post(url_for('profile_password'), data=data, follow_redirects=True)
            assert b'Your password has been updated' in rv.data
            data['password2'] = 'short'
            rv = self.app.post(url_for('profile_password'), data=data, follow_redirects=True)
            assert b'match' in rv.data
            data['password_old'] = new_pass
            rv = self.app.post(url_for('profile_password'), data=data, follow_redirects=True)
            assert b'New password is like old one' in rv.data
            data['password'] = '******'
            rv = self.app.post(url_for('profile_password'), data=data, follow_redirects=True)
            assert b'too short' in rv.data
    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
    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
    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
    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
    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
    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
    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
 def test_links(self):
     self.login()
     with app.app_context():
         rv = self.app.get(url_for('admin_check_links', check='check'))
         assert b'Invalid linked entity' in rv.data