def test_to_archive(self): m = TopoMap(document_id=1, editor='ign', scale='20000', code='3431OT', locales=[ DocumentLocale(id=2, lang='en', title='Lac d\'Annecy'), DocumentLocale(id=3, lang='fr', title='Lac d\'Annecy'), ]) map_archive = m.to_archive() self.assertIsNone(map_archive.id) self.assertEqual(map_archive.document_id, m.document_id) self.assertEqual(map_archive.editor, m.editor) self.assertEqual(map_archive.scale, m.scale) self.assertEqual(map_archive.code, m.code) archive_locals = m.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = m.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title)
def test_to_archive(self): user_profile = UserProfile(document_id=1, categories=['amateur'], locales=[ DocumentLocale(id=2, lang='en', title='Me', summary='...'), DocumentLocale(id=3, lang='fr', title='Moi', summary='...'), ]) user_profile_archive = user_profile.to_archive() self.assertIsNone(user_profile_archive.id) self.assertEqual(user_profile_archive.document_id, user_profile.document_id) self.assertEqual(user_profile_archive.categories, user_profile.categories) archive_locals = user_profile.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = user_profile.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title)
def test_to_archive(self): image = Image(document_id=1, activities=['skitouring'], height=1200, locales=[ DocumentLocale(id=2, lang='en', title='A', description='abc'), DocumentLocale(id=3, lang='fr', title='B', description='bcd'), ]) image_archive = image.to_archive() self.assertIsNone(image_archive.id) self.assertEqual(image_archive.document_id, image.document_id) self.assertEqual(image_archive.activities, image.activities) self.assertEqual(image_archive.height, image.height) archive_locals = image.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = image.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title) self.assertEqual(locale_archive.description, locale.description)
def _add_test_data(self): self.map1 = TopoMap(editor='IGN', scale='25000', code='3431OT') self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy') self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy') self.map1.locales.append(self.locale_en) self.map1.locales.append(self.locale_fr) self.map1.geometry = DocumentGeometry( geom_detail='SRID=3857;POINT(635956 5723604)') self.session.add(self.map1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.map1, user_id) self.map2 = TopoMap(editor='IGN', scale='25000', code='3432OT') self.session.add(self.map2) self.map3 = TopoMap(editor='IGN', scale='25000', code='3433OT') self.session.add(self.map3) self.map4 = TopoMap(editor='IGN', scale='25000', code='3434OT') self.map4.locales.append( DocumentLocale(lang='en', title='Lac d\'Annecy')) self.map4.locales.append( DocumentLocale(lang='fr', title='Lac d\'Annecy')) self.session.add(self.map4) self.session.flush()
def test_to_archive(self): area = Area( document_id=1, area_type='range', locales=[ DocumentLocale( id=2, lang='en', title='Chartreuse', summary='...'), DocumentLocale( id=3, lang='fr', title='Chartreuse', summary='...'), ] ) area_archive = area.to_archive() self.assertIsNone(area_archive.id) self.assertEqual(area_archive.document_id, area.document_id) self.assertEqual(area_archive.area_type, area.area_type) archive_locals = area.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = area.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title)
def migrate(self): super(MigrateUserProfiles, self).migrate() # some users to do not have a profile, create an empty profile so that # the users can be imported. with transaction.manager: last_locale_id = self.connection_source.execute( text('select max(document_i18n_archive_id) ' 'from app_documents_i18n_archives;')).fetchone()[0] last_archive_id = self.connection_source.execute( text('select max(document_archive_id) ' 'from app_documents_archives;')).fetchone()[0] profileless_users = self.connection_source.execute( text(MigrateUserProfiles.query_profileless_users)) for row in profileless_users: user_id = row[0] last_locale_id += 1 last_archive_id += 1 locale = DocumentLocale(id=last_locale_id, document_id=user_id, lang='fr', title='') profile = UserProfile(document_id=user_id, locales=[locale]) locale_archive = locale.to_archive() locale_archive.id = last_locale_id profile_archive = profile.to_archive() profile_archive.id = last_archive_id self.session_target.add(profile) self.session_target.add(locale) self.session_target.flush() self.session_target.add(locale_archive) self.session_target.add(profile_archive)
def _add_test_data(self): self.article1 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy') self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy') self.article1.locales.append(self.locale_en) self.article1.locales.append(self.locale_fr) self.session.add(self.article1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.article1, user_id) self.article1_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.article1.document_id). \ filter(DocumentVersion.lang == 'en').first() self.article2 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article2) self.article3 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article3) self.article4 = Article(categories=['site_info'], activities=['hiking'], article_type='personal') self.article4.locales.append( DocumentLocale(lang='en', title='Lac d\'Annecy')) self.article4.locales.append( DocumentLocale(lang='fr', title='Lac d\'Annecy')) self.session.add(self.article4) self.session.flush() DocumentRest.create_new_version(self.article4, user_id) self.article4_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.article4.document_id). \ filter(DocumentVersion.lang == 'en').first() self.waypoint1 = Waypoint(waypoint_type='summit', elevation=2203) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='climbing_outdoor', elevation=2, rock_types=[], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.session.add(self.waypoint2) self.session.flush() self.session.add( Association.create(parent_document=self.article1, child_document=self.article4)) self.session.add( Association.create(parent_document=self.article3, child_document=self.article1)) self.session.flush()
def _add_global_test_data(session): global_passwords['contributor'] = 'super pass' global_passwords['contributor2'] = 'better pass' global_passwords['moderator'] = 'even better pass' contributor_profile = UserProfile( categories=['amateur'], locales=[ DocumentLocale(title='', description='Me', lang='en'), DocumentLocale(title='', description='Moi', lang='fr')], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) contributor = User( name='Contributor', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor_profile) contributor2_profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(title='...', lang='en')]) contributor2 = User( name='Contributor 2', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor2_profile) moderator_profile = UserProfile( categories=['mountain_guide'], locales=[DocumentLocale(title='', lang='en')]) moderator = User( name='Moderator', username='******', email='*****@*****.**', forum_username='******', moderator=True, password='******', email_validated=True, profile=moderator_profile) users = [moderator, contributor, contributor2] session.add_all(users) session.flush() key = settings['jwtauth.master_secret'] algorithm = 'HS256' now = datetime.datetime.utcnow() exp = now + datetime.timedelta(weeks=10) for user in [moderator, contributor, contributor2]: claims = create_claims(user, exp) token = jwt.encode(claims, key=key, algorithm=algorithm). \ decode('utf-8') add_or_retrieve_token(token, exp, user.id) global_userids[user.username] = user.id global_tokens[user.username] = token
def _add_test_data(self): self.image = Image( activities=['paragliding'], height=1500, image_type='collaborative') self.locale_en = DocumentLocale( lang='en', title='Mont Blanc from the air', description='...') self.locale_fr = DocumentLocale( lang='fr', title='Mont Blanc du ciel', description='...') self.image.locales.append(self.locale_en) self.image.locales.append(self.locale_fr) self.image.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.image) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.image, user_id) self.image2 = Image( activities=['paragliding'], height=1500) self.session.add(self.image2) self.image3 = Image( activities=['paragliding'], height=1500) self.session.add(self.image3) self.image4 = Image( activities=['paragliding'], height=1500, image_type='personal') self.image4.locales.append(DocumentLocale( lang='en', title='Mont Blanc from the air', description='...')) self.image4.locales.append(DocumentLocale( lang='fr', title='Mont Blanc du ciel', description='...')) self.session.add(self.image4) self.session.flush() DocumentRest.create_new_version(self.image4, user_id) self.waypoint = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.waypoint.locales.append(WaypointLocale( lang='en', title='Mont Granier (en)', description='...', access='yep')) self.session.add(self.waypoint) self.session.flush()
def test_get_maps(self): map1 = TopoMap( locales=[ DocumentLocale(lang='en', title='Passo del Maloja'), DocumentLocale(lang='fr', title='Passo del Maloja') ], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((1060345.67641127 5869598.161661,1161884.8271513 5866294.47946546,1159243.3608776 5796747.98963817,1058506.68785187 5800000.03655724,1060345.67641127 5869598.161661))' ) # noqa ) map2 = TopoMap( locales=[DocumentLocale(lang='fr', title='Monte Disgrazia')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((1059422.5474971 5834730.45170096,1110000.12573506 5833238.36363707,1108884.30979916 5798519.62445622,1058506.68785187 5800000.03655724,1059422.5474971 5834730.45170096))' ) # noqa ) map3 = TopoMap( locales=[DocumentLocale(lang='fr', title='Sciora')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((1059422.5474971 5834730.45170096,1084713.47958582 5834021.11961652,1084204.54539729 5816641.60293193,1058963.71520182 5817348.14989301,1059422.5474971 5834730.45170096))' ) # noqa ) map4 = TopoMap( locales=[DocumentLocale(lang='fr', title='...')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((753678.422528324 6084684.82967302,857818.351438369 6084952.58494753,857577.289072432 6013614.93425228,754282.556732048 6013351.52692378,753678.422528324 6084684.82967302))' ) # noqa ) waypoint = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(1069913.22199537 5830556.39234855)' ) # noqa ) self.session.add_all([waypoint, map1, map2, map3, map4]) self.session.flush() maps = get_maps(waypoint, 'en') self.assertEqual( set([m.document_id for m in maps]), set([map1.document_id, map2.document_id, map3.document_id])) for m in maps: # check that the "best" locale is set self.assertEqual(len(m.locales), 1)
def post(self): user = schema_create_user.objectify(self.request.validated) user.password = self.request.validated['password'] user.update_validation_nonce(Purpose.registration, VALIDATION_EXPIRE_DAYS) # directly create the user profile, the document id of the profile # is the user id lang = user.lang user.profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(lang=lang, title='')]) DBSession.add(user) try: DBSession.flush() except: log.warning('Error persisting user', exc_info=True) raise HTTPInternalServerError('Error persisting user') # also create a version for the profile DocumentRest.create_new_version(user.profile, user.id) # The user needs validation email_service = get_email_service(self.request) nonce = user.validation_nonce settings = self.request.registry.settings link = settings['mail.validate_register_url_template'] % nonce email_service.send_registration_confirmation(user, link) return to_json_dict(user, schema_user)
def _add_test_data(self): self.map1 = TopoMap(editor='IGN', scale='25000', code='3431OT') self.locale_en = DocumentLocale(lang='en', title='Lac d\'Annecy') self.locale_fr = DocumentLocale(lang='fr', title='Lac d\'Annecy') self.map1.locales.append(self.locale_en) self.map1.locales.append(self.locale_fr) self.map1.geometry = DocumentGeometry( geom_detail='SRID=3857;POLYGON((611774 5706934,611774 5744215,' '642834 5744215,642834 5706934,611774 5706934))') self.session.add(self.map1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.map1, user_id) self.map2 = TopoMap(editor='IGN', scale='25000', code='3432OT') self.session.add(self.map2) self.map3 = TopoMap(editor='IGN', scale='25000', code='3433OT') self.session.add(self.map3) self.map4 = TopoMap(editor='IGN', scale='25000', code='3434OT') self.map4.locales.append( DocumentLocale(lang='en', title='Lac d\'Annecy')) self.map4.locales.append( DocumentLocale(lang='fr', title='Lac d\'Annecy')) self.session.add(self.map4) self.session.flush() self.waypoint1 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(677461.381691516 5740879.44638645)')) self.waypoint2 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(693666.031687976 5741108.7574713)')) route_geom = 'SRID=3857;LINESTRING(668518 5728802, 668528 5728812)' self.route = Route(activities=['skitouring'], geometry=DocumentGeometry(geom_detail=route_geom)) self.session.add_all([self.waypoint1, self.waypoint2, self.route]) self.session.add( TopoMapAssociation(document=self.waypoint2, topo_map=self.map1)) self.session.flush()
def _add_test_data(self): user_id = self.global_userids['contributor'] self.profile1 = self.session.query(UserProfile).get(user_id) self.locale_en = self.profile1.get_locale('en') self.locale_fr = self.profile1.get_locale('fr') DocumentRest.create_new_version(self.profile1, user_id) self.profile2 = UserProfile(categories=['amateur']) self.session.add(self.profile2) self.profile3 = UserProfile(categories=['amateur']) self.session.add(self.profile3) self.profile4 = UserProfile(categories=['amateur']) self.profile4.locales.append( DocumentLocale(lang='en', description='You', title='')) self.profile4.locales.append( DocumentLocale(lang='fr', description='Toi', title='')) self.session.add(self.profile4) self.session.flush() # create users for the profiles self.user2 = User(name='user2', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=self.profile2) self.user3 = User(name='user3', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=False, profile=self.profile3) self.user4 = User(name='user4', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=self.profile4) self.session.add_all([self.user2, self.user3, self.user4]) self.session.flush()
def _add_test_data(self): self.area1 = Area(area_type='range') self.locale_en = DocumentLocale(lang='en', title='Chartreuse') self.locale_fr = DocumentLocale(lang='fr', title='Chartreuse') self.area1.locales.append(self.locale_en) self.area1.locales.append(self.locale_fr) self.area1.geometry = DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((668518.249382151 5728802.39591739,668518.249382151 5745465.66808356,689156.247019149 5745465.66808356,689156.247019149 5728802.39591739,668518.249382151 5728802.39591739))' # noqa ) self.session.add(self.area1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.area1, user_id) self.area2 = Area(area_type='range') self.session.add(self.area2) self.area3 = Area(area_type='range') self.session.add(self.area3) self.area4 = Area(area_type='admin_limits') self.area4.locales.append(DocumentLocale(lang='en', title='Isère')) self.area4.locales.append(DocumentLocale(lang='fr', title='Isère')) self.session.add(self.area4) self.waypoint1 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(677461.381691516 5740879.44638645)')) self.waypoint2 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(693666.031687976 5741108.7574713)')) route_geom = 'SRID=3857;LINESTRING(668518 5728802, 668528 5728812)' self.route = Route(activities=['skitouring'], geometry=DocumentGeometry(geom_detail=route_geom)) self.session.add_all([self.waypoint1, self.waypoint2, self.route]) self.session.add( AreaAssociation(document=self.waypoint2, area=self.area1)) self.session.flush()
def _add_test_data(self): self.waypoint = Waypoint(waypoint_type='summit', elevation=2203) self.locale_en = WaypointLocale(lang='en', title='Mont Granier', description='...', access='yep') self.waypoint.locales.append(self.locale_en) self.waypoint.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.waypoint) self.waypoint_with_topic = Waypoint(waypoint_type='summit', elevation=2203) document_topic = DocumentTopic(topic_id=1) self.locale_en_with_topic = WaypointLocale( lang='en', title='Mont Granier', description='...', access='yep', document_topic=document_topic) self.waypoint_with_topic.locales.append(self.locale_en_with_topic) self.waypoint_with_topic.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.waypoint_with_topic) self.image = Image(filename='image.jpg', activities=['paragliding'], height=1500, image_type='collaborative') self.image_locale_en = DocumentLocale(lang='en', title='', description='') self.image.locales.append(self.image_locale_en) self.image.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.image) self.outing = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale( lang='en', title='Mont Granier / skitouring') ]) self.session.add(self.outing) self.session.flush() for user_id in (self.global_userids['contributor'], self.global_userids['contributor2']): self.session.add( Association(parent_document_id=user_id, parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing.document_id, child_document_type=OUTING_TYPE)) self.session.flush()
def setUp(self): # noqa super(TestUserFilterPreferencesRest, self).setUp() self._prefix = '/users/preferences' self.area1 = Area(area_type='range', locales=[ DocumentLocale(lang='fr', title='France'), DocumentLocale(lang='de', title='Frankreich') ]) self.area2 = Area(area_type='range', locales=[DocumentLocale(lang='fr', title='Suisse')]) self.session.add_all([self.area1, self.area2]) self.session.flush() self.contributor = self.session.query(User).get( self.global_userids['contributor']) self.contributor.feed_filter_areas.append(self.area1) self.contributor.feed_filter_activities = ['hiking'] self.session.flush()
def test_to_archive(self): article = Article(document_id=1, categories=['expeditions'], activities=['hiking'], article_type='personal', locales=[ DocumentLocale(id=2, lang='en', title='A', summary='C', description='abc'), DocumentLocale(id=3, lang='fr', title='B', summary='C', description='bcd'), ]) article_archive = article.to_archive() self.assertIsNone(article_archive.id) self.assertIsNotNone(article_archive.activities) self.assertIsNotNone(article_archive.article_type) self.assertEqual(article_archive.document_id, article.document_id) self.assertEqual(article_archive.activities, article.activities) self.assertEqual(article_archive.article_type, article.article_type) self.assertEqual(article_archive.categories, article.categories) archive_locals = article.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = article.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title) self.assertEqual(locale_archive.description, locale.description) self.assertEqual(locale_archive.type, locale.type) self.assertEqual(locale_archive.summary, locale.summary)
def setUp(self): BaseTestRest.setUp(self) waypoint = Waypoint( waypoint_type='summit', elevation=2000, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') ) outing = Outing( activities=['skitouring'], date_start=date(2016, 1, 1), date_end=date(2016, 1, 1), geometry=DocumentGeometry(geom='SRID=3857;POINT(0 0)') ) article = Article( categories=['site_info'], activities=['hiking'], article_type='collab' ) for lang in default_langs: locale = OutingLocale(lang=lang, title=f'Title in {lang}') outing.locales.append(locale) locale = DocumentLocale(lang=lang, title=f'Title in {lang}') article.locales.append(locale) locale = WaypointLocale(lang=lang, title=f'Title in {lang}') waypoint.locales.append(locale) self.session.add(article) self.session.add(outing) self.session.add(waypoint) self.session.flush() fill_index(self.session) # make sure the search index is built force_search_index() contributor_id = self.global_userids['contributor'] for lang in default_langs: self.session.add(DocumentChange( time=datetime(2016, 1, 1, 12, 0, 0), user_id=contributor_id, change_type='created', document_id=waypoint.document_id, document_type=WAYPOINT_TYPE, user_ids=[contributor_id], langs=[lang] )) self.session.flush()
def migrate(self): super(MigrateUserProfiles, self).migrate() # some users to do not have a profile, create an empty profile so that # the users can be imported. with transaction.manager: last_locale_id = self.connection_source.execute( text('select max(document_i18n_archive_id) ' 'from app_documents_i18n_archives;')).fetchone()[0] last_archive_id = self.connection_source.execute( text('select max(document_archive_id) ' 'from app_documents_archives;')).fetchone()[0] profileless_users = self.connection_source.execute( text(MigrateUserProfiles.query_profileless_users)) for row in profileless_users: user_id = row[0] last_locale_id += 1 last_archive_id += 1 locale = DocumentLocale( id=last_locale_id, document_id=user_id, lang='fr', title='' ) profile = UserProfile( document_id=user_id, locales=[locale] ) locale_archive = locale.to_archive() locale_archive.id = last_locale_id profile_archive = profile.to_archive() profile_archive.id = last_archive_id self.session_target.add(profile) self.session_target.add(locale) self.session_target.flush() self.session_target.add(locale_archive) self.session_target.add(profile_archive)
def test_to_archive(self): book = Book(document_id=1, activities=['hiking'], book_types=['biography'], locales=[ DocumentLocale(id=2, lang='en', title='A', summary='C', description='abc'), DocumentLocale(id=3, lang='fr', title='B', summary='C', description='bcd'), ]) book_archive = book.to_archive() self.assertIsNone(book_archive.id) self.assertIsNotNone(book_archive.activities) self.assertIsNotNone(book_archive.book_types) self.assertEqual(book_archive.document_id, book.document_id) self.assertEqual(book_archive.activities, book.activities) self.assertEqual(book_archive.book_types, book.book_types) archive_locals = book.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = book.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title) self.assertEqual(locale_archive.description, locale.description) self.assertEqual(locale_archive.type, locale.type) self.assertEqual(locale_archive.summary, locale.summary)
def _add_test_data(self): user_id = self.global_userids['contributor'] self.waypoint1 = Waypoint(waypoint_type='summit', elevation=2203) self.session.add(self.waypoint1) self.waypoint2 = Waypoint(waypoint_type='summit', elevation=200) self.session.add(self.waypoint2) self.session.flush() self.waypoint3 = Waypoint(waypoint_type='summit', elevation=200, redirects_to=self.waypoint1.document_id) self.session.add(self.waypoint3) self.route1 = Route(activities=['skitouring']) self.session.add(self.route1) self.session.add(self.waypoint2) self.route2 = Route(activities=['skitouring']) self.session.add(self.route2) self.image1 = Image(filename='image.jpg', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air') ]) self.session.add(self.image1) self.session.flush() DocumentRest.create_new_version(self.image1, user_id) self.article1 = Article( categories=['site_info'], activities=['hiking'], article_type='collab', locales=[DocumentLocale(lang='en', title='Lac d\'Annecy')]) self.session.add(self.article1) self.session.flush() DocumentRest.create_new_version(self.article1, user_id) self.article2 = Article( categories=['site_info'], activities=['hiking'], article_type='personal', locales=[DocumentLocale(lang='en', title='Lac d\'Annecy')]) self.session.add(self.article2) self.session.flush() DocumentRest.create_new_version(self.article2, user_id) self.report1 = Xreport( activities=['hiking'], locales=[XreportLocale(lang='en', title='Lac d\'Annecy')]) self.session.add(self.report1) self.session.flush() DocumentRest.create_new_version(self.report1, user_id) self.outing = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1)) self.session.add(self.outing) self.session.flush() self.session.add( Association(parent_document_id=user_id, parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing.document_id, child_document_type=OUTING_TYPE)) update_feed_document_create(self.outing, user_id) self.session.flush() # create a 2nd feed entry for the outing feed_change = self.get_feed_change(self.outing.document_id) user_id = self.global_userids['moderator'] feed_change2 = feed_change.copy() feed_change2.change_type = 'added_photos' feed_change2.user_id = user_id feed_change2.user_ids = list( set(feed_change.user_ids).union([user_id])) self.session.add(feed_change2) self.session.flush()
def _add_global_test_data(session): global_passwords['contributor'] = 'super pass' global_passwords['contributor2'] = 'better pass' global_passwords['moderator'] = 'even better pass' global_passwords['robot'] = 'bombproof pass' contributor_profile = UserProfile( categories=['amateur'], locales=[ DocumentLocale(title='', description='Me', lang='en'), DocumentLocale(title='', description='Moi', lang='fr')], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) contributor = User( name='Contributor', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor_profile) contributor2_profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(title='...', lang='en')]) contributor2 = User( name='Contributor 2', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor2_profile) contributor3_profile = UserProfile( categories=['amateur'], locales=[DocumentLocale(title='...', lang='en')]) contributor3 = User( name='Contributor 3', username='******', email='*****@*****.**', forum_username='******', password='******', email_validated=True, profile=contributor3_profile) moderator_profile = UserProfile( categories=['mountain_guide'], locales=[DocumentLocale(title='', lang='en')]) moderator = User( name='Moderator', username='******', email='*****@*****.**', forum_username='******', moderator=True, password='******', email_validated=True, profile=moderator_profile) robot_profile = UserProfile( locales=[DocumentLocale(title='', lang='en')]) robot = User( name='Robot', username='******', email='*****@*****.**', forum_username='******', robot=True, password='******', email_validated=True, profile=robot_profile) users = [robot, moderator, contributor, contributor2, contributor3] session.add_all(users) session.flush() domain = 'www.somewhere.com' sso_key = SsoKey( domain=domain, key=domain ) session.add(sso_key) sso_external_id = SsoExternalId( domain=domain, external_id='1', user=contributor, token='token', expire=utc.localize(datetime.datetime.utcnow()), ) session.add(sso_external_id) session.flush() key = settings['jwtauth.master_secret'] algorithm = 'HS256' now = datetime.datetime.utcnow() exp = now + datetime.timedelta(weeks=10) for user in [robot, moderator, contributor, contributor2, contributor3]: claims = create_claims(user, exp) token = jwt.encode(claims, key=key, algorithm=algorithm). \ decode('utf-8') add_or_retrieve_token(token, exp, user.id) global_userids[user.username] = user.id global_tokens[user.username] = token
def _add_test_data(self): user_id = self.global_userids['contributor'] self.image = Image(filename='image.jpg', activities=['paragliding'], height=1500, image_type='collaborative') self.locale_en = DocumentLocale( lang='en', title='Mont Blanc from the air', description='...', document_topic=DocumentTopic(topic_id=1)) self.locale_fr = DocumentLocale(lang='fr', title='Mont Blanc du ciel', description='...') self.image.locales.append(self.locale_en) self.image.locales.append(self.locale_fr) self.image.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.image) self.session.flush() self.article1 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article1) self.session.flush() self._add_association( Association.create(parent_document=self.article1, child_document=self.image), user_id) self.book1 = Book(activities=['hiking'], book_types=['biography']) self.session.add(self.book1) self.session.flush() self._add_association( Association.create(parent_document=self.book1, child_document=self.image), user_id) DocumentRest.create_new_version(self.image, user_id) self.image_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.image.document_id). \ filter(DocumentVersion.lang == 'en').first() self.image2 = Image(filename='image2.jpg', activities=['paragliding'], height=1500) self.session.add(self.image2) self.image3 = Image(filename='image3.jpg', activities=['paragliding'], height=1500) self.session.add(self.image3) self.image4 = Image(filename='image4.jpg', activities=['paragliding'], height=1500, image_type='personal') self.image4.locales.append( DocumentLocale(lang='en', title='Mont Blanc from the air', description='...')) self.image4.locales.append( DocumentLocale(lang='fr', title='Mont Blanc du ciel', description='...')) self.session.add(self.image4) self.session.flush() DocumentRest.create_new_version(self.image3, self.global_userids['contributor2']) DocumentRest.create_new_version(self.image4, user_id) self._add_association( Association.create(parent_document=self.image, child_document=self.image2), user_id) self.waypoint = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint.locales.append( WaypointLocale(lang='en', title='Mont Granier (en)', description='...', access='yep')) self.session.add(self.waypoint) self.session.flush() update_feed_document_create(self.waypoint, user_id) self.session.flush() self.area = Area(area_type='range', locales=[DocumentLocale(lang='fr', title='France')]) self.session.add(self.area) self.session.flush() self._add_association(Association.create(self.area, self.image), user_id) self.session.flush() self.outing1 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing1) self.session.flush() self._add_association( Association.create(parent_document=self.outing1, child_document=self.image), user_id) self._add_association( Association(parent_document_id=self.global_userids['contributor'], parent_document_type=USERPROFILE_TYPE, child_document_id=self.outing1.document_id, child_document_type=OUTING_TYPE), user_id) update_feed_document_create(self.outing1, user_id) self.session.flush()
def main(argv=sys.argv): settings_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'loadtests.ini') settings = get_appsettings(settings_file) engine = engine_from_config(settings, 'sqlalchemy.') logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.WARN) Session = sessionmaker() # noqa register(Session) session = Session(bind=engine) with transaction.manager: for i in range(1, NB_USERS_TO_CREATE + 1): username = BASE_USERNAME + str(i) password = username email = username + '@foo.bar' lang = 'fr' profile = UserProfile( categories=['amateur'], geometry=DocumentGeometry( version=1, geom=None, geom_detail=None), locales=[DocumentLocale(lang=lang, title='')] ) user = User( username=username, forum_username=username, name=username, email=email, lang=lang, password=password, profile=profile ) # make sure user account is directly validated user.clear_validation_nonce() user.email_validated = True session.add(user) session.flush() # also create a version for the profile # code from DocumentRest.create_new_version archive = user.profile.to_archive() archive_locales = user.profile.get_archive_locales() archive_geometry = user.profile.get_archive_geometry() meta_data = HistoryMetaData(comment='creation', user_id=user.id) versions = [] for locale in archive_locales: version = DocumentVersion( document_id=user.profile.document_id, lang=locale.lang, document_archive=archive, document_locales_archive=locale, document_geometry_archive=archive_geometry, history_metadata=meta_data ) versions.append(version) session.add(archive) session.add_all(archive_locales) session.add(meta_data) session.add_all(versions) session.flush() print('Created %d users with base username `%s`' % ( NB_USERS_TO_CREATE, BASE_USERNAME))
def test_fill_index(self): """Tests that documents are inserted into the ElasticSearch index. """ self.session.add( Waypoint(document_id=71171, waypoint_type='summit', elevation=2000, quality='medium', access_time='15min', geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Mont Granier', description='...', summary='Le Mont [b]Granier[/b]'), WaypointLocale(lang='en', title='Mont Granier', description='...', summary='The Mont Granier') ])) self.session.add( Waypoint(document_id=71172, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.add( Route(document_id=71173, activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations=['1'], locales=[ RouteLocale(lang='en', title='Face N', description='...', gear='paraglider', title_prefix='Mont Blanc') ])) self.session.add( Waypoint(document_id=71174, redirects_to=71171, waypoint_type='summit', elevation=4985, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ])) self.session.add( Outing(document_id=71175, activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), frequentation='overcrowded', locales=[ OutingLocale(lang='en', title='Mont Blanc : Face N !', description='...', weather='sunny') ])) self.session.add( Article(document_id=71176, categories=['site_info'], activities=['hiking'], article_type='collab', geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)'), locales=[ DocumentLocale(lang='en', title='Lac d\'Annecy', description='...', summary=''), DocumentLocale(lang='fr', title='Lac d\'Annecy', description='...', summary='') ])) self.session.flush() self.session.add( Book(document_id=71177, activities=['hiking'], book_types=['biography'], author='Denis Dainat', publication_date='', locales=[ DocumentLocale(lang='fr', title='Escalades au Thaurac', description='...', summary=''), DocumentLocale(lang='en', title='Escalades au Thaurac', description='...', summary='') ])) self.session.flush() self.session.add( Xreport(document_id=71178, event_type='person_fall', event_activity='skitouring', nb_participants=10, elevation=1500, date=datetime.date(2016, 1, 1), locales=[ XreportLocale(lang='en', title='Death in the mountains', description='...', place='some place description') ])) self.session.flush() # fill the ElasticSearch index fill_index(self.session) waypoint1 = SearchWaypoint.get(id=71171) self.assertIsNotNone(waypoint1) self.assertEqual(waypoint1.title_en, 'Mont Granier') self.assertEqual(waypoint1.title_fr, 'Mont Granier') # self.assertEqual(waypoint1.summary_fr, 'Le Mont Granier ') self.assertEqual(waypoint1.doc_type, 'w') self.assertEqual(waypoint1.quality, 2) self.assertEqual(waypoint1.access_time, 3) self.assertAlmostEqual(waypoint1.geom[0], 5.71288994) self.assertAlmostEqual(waypoint1.geom[1], 45.64476395) waypoint2 = SearchWaypoint.get(id=71172) self.assertIsNotNone(waypoint2) self.assertEqual(waypoint2.title_en, 'Mont Blanc') self.assertIsNone(waypoint2.title_fr) self.assertEqual(waypoint2.doc_type, 'w') route = SearchRoute.get(id=71173) self.assertIsNotNone(route) self.assertEqual(route.title_en, 'Mont Blanc : Face N') self.assertIsNone(route.title_fr) self.assertEqual(route.doc_type, 'r') self.assertEqual(route.durations, [0]) outing = SearchOuting.get(id=71175) self.assertIsNotNone(outing) self.assertEqual(outing.title_en, 'Mont Blanc : Face N !') self.assertIsNone(outing.title_fr) self.assertEqual(outing.doc_type, 'o') self.assertEqual(outing.frequentation, 3) article = SearchArticle.get(id=71176) self.assertIsNotNone(article) self.assertEqual(article.title_en, 'Lac d\'Annecy') self.assertEqual(article.title_fr, 'Lac d\'Annecy') self.assertEqual(article.doc_type, 'c') book = SearchBook.get(id=71177) self.assertIsNotNone(book) self.assertEqual(book.title_en, 'Escalades au Thaurac') self.assertEqual(book.title_fr, 'Escalades au Thaurac') self.assertEqual(book.doc_type, 'b') self.assertEqual(book.book_types, ['biography']) xreport = SearchXreport.get(id=71178) self.assertIsNotNone(xreport) self.assertEqual(xreport.title_en, 'Death in the mountains') self.assertEqual(xreport.doc_type, 'x') # merged document is ignored self.assertIsNone(SearchWaypoint.get(id=71174, ignore=404)) # check that the sync. status was updated last_update, _ = es_sync.get_status(self.session) self.assertIsNotNone(last_update)
def setUp(self): # noqa super(TestDocumentDeleteRest, self).setUp() self._prefix = '/documents/delete/' user_id = self.global_userids['contributor'] self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Dent de Crolles', description='...', summary='La Dent de Crolles') ]) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', document_topic=DocumentTopic(topic_id=1), summary='The heighest point in Europe') ]) self.session.add(self.waypoint2) self.waypoint3 = Waypoint( waypoint_type='summit', elevation=3, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint3.locales.append( WaypointLocale(lang='en', title='Mont Granier', description='...', access='yep', document_topic=DocumentTopic(topic_id=2))) self.waypoint3.locales.append( WaypointLocale(lang='fr', title='Mont Granier', description='...', access='ouai', document_topic=DocumentTopic(topic_id=3))) self.session.add(self.waypoint3) self.session.flush() self.waypoint4 = Waypoint( waypoint_type='summit', elevation=3, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint4.locales.append( WaypointLocale(lang='en', title='Mont Ventoux', description='...')) self.session.add(self.waypoint4) self.session.flush() DocumentRest.create_new_version(self.waypoint1, user_id) update_feed_document_create(self.waypoint1, user_id) DocumentRest.create_new_version(self.waypoint2, user_id) update_feed_document_create(self.waypoint2, user_id) DocumentRest.create_new_version(self.waypoint3, user_id) update_feed_document_create(self.waypoint3, user_id) DocumentRest.create_new_version(self.waypoint4, user_id) update_feed_document_create(self.waypoint4, user_id) self.session.flush() route1_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route1 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', main_waypoint_id=self.waypoint1.document_id, geometry=route1_geometry) self.route1.locales.append( RouteLocale(lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider')) self.session.add(self.route1) route2_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route2 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', geometry=route2_geometry) self.route2.locales.append( RouteLocale(lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider', document_topic=DocumentTopic(topic_id=4))) self.session.add(self.route2) self.session.flush() self._add_association(self.waypoint1, self.route1) self._add_association(self.waypoint2, self.route2) self.session.flush() route3_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.route3 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', geometry=route3_geometry) self.route3.locales.append( RouteLocale(lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider', document_topic=DocumentTopic(topic_id=5))) self.session.add(self.route3) self.session.flush() DocumentRest.create_new_version(self.route1, user_id) update_feed_document_create(self.route1, user_id) DocumentRest.create_new_version(self.route2, user_id) update_feed_document_create(self.route2, user_id) DocumentRest.create_new_version(self.route3, user_id) update_feed_document_create(self.route3, user_id) self._add_association(self.waypoint1, self.route3) self._add_association(self.waypoint2, self.route3) self._add_association(self.waypoint3, self.route3) self._add_tag(self.route3) self.session.flush() outing1_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.outing1 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), geometry=outing1_geometry, locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny', document_topic=DocumentTopic(topic_id=6)) ]) self.session.add(self.outing1) self.session.flush() DocumentRest.create_new_version(self.outing1, user_id) update_feed_document_create(self.outing1, user_id) self._add_association(self.route1, self.outing1) self.session.flush() outing1b_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.outing1b = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), geometry=outing1b_geometry, redirects_to=self.outing1.document_id, locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing1b) self.session.flush() DocumentRest.create_new_version(self.outing1b, user_id) self.session.flush() outing2_geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)') self.outing2 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), geometry=outing2_geometry, locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny', document_topic=DocumentTopic(topic_id=7)) ]) self.session.add(self.outing2) self.session.flush() DocumentRest.create_new_version(self.outing2, user_id) update_feed_document_create(self.outing2, user_id) self._add_association(self.route2, self.outing2) self._add_association(self.route3, self.outing2) self.session.flush() self.article1 = Article( activities=['skitouring'], categories=['gear'], article_type='personal', locales=[ DocumentLocale(lang='en', title='Some article', description='Some content', document_topic=DocumentTopic(topic_id=8)) ]) self.session.add(self.article1) self.session.flush() DocumentRest.create_new_version(self.article1, user_id) update_feed_document_create(self.article1, user_id) self.session.flush() self.article1.locales[0].title = 'Some other article title' article1_lang = self.article1.locales[0].lang self.session.flush() DocumentRest.update_version(self.article1, user_id, 'new title', [UpdateType.LANG], [article1_lang]) self.session.flush() self._add_association(self.route2, self.article1) self._add_association(self.outing2, self.article1) self.session.flush() self.article2 = Article(activities=['skitouring'], categories=['gear'], article_type='personal', locales=[ DocumentLocale(lang='en', title='Some other article', description='Some content') ]) self.session.add(self.article2) self.session.flush() # Make the article older than 24h old written_at = datetime.datetime(2016, 1, 1, 0, 0, 0) DocumentRest.create_new_version(self.article2, user_id, written_at) update_feed_document_create(self.article2, user_id) self.session.flush() self.book1 = Book(activities=['skitouring'], book_types=['biography'], locales=[ DocumentLocale( lang='en', title='Some book', description='Some content', document_topic=DocumentTopic(topic_id=9)) ]) self.session.add(self.book1) self.session.flush() DocumentRest.create_new_version(self.book1, user_id) update_feed_document_create(self.book1, user_id) self._add_association(self.book1, self.route2) self._add_association(self.book1, self.route3) self.session.flush() self.xreport1 = Xreport( event_activity='alpine_climbing', event_type='stone_ice_fall', locales=[ XreportLocale(lang='en', title='Lac d\'Annecy', place='some place descrip. in english', document_topic=DocumentTopic(topic_id=10)), XreportLocale(lang='fr', title='Lac d\'Annecy', place='some place descrip. in french', document_topic=DocumentTopic(topic_id=11)) ]) self.session.add(self.xreport1) self.session.flush() DocumentRest.create_new_version(self.xreport1, user_id) update_feed_document_create(self.xreport1, user_id) self._add_association(self.outing2, self.xreport1) self._add_association(self.route3, self.xreport1) self.session.flush() self.image1 = Image(filename='image1.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale( lang='en', title='Mont Blanc from the air', description='...', document_topic=DocumentTopic(topic_id=12)) ]) self.session.add(self.image1) self.session.flush() DocumentRest.create_new_version(self.image1, user_id) self._add_association(self.outing1, self.image1) self._add_association(self.route3, self.image1) self._add_association(self.waypoint3, self.image1) self.session.flush() update_feed_images_upload( [self.image1], [{ 'filename': 'image1.jpg', 'activities': ['paragliding'], 'image_type': 'collaborative', 'height': 1500, 'locales': [{ 'lang': 'en', 'title': 'Mont Blanc from the air' }], 'associations': { 'outings': [{ 'document_id': self.outing1.document_id }], 'routes': [{ 'document_id': self.route3.document_id }], 'waypoints': [{ 'document_id': self.waypoint3.document_id }] } }], user_id) self.image1.filename = 'image1.1.jpg' self.session.flush() DocumentRest.update_version(self.image1, user_id, 'changed filename', [UpdateType.FIGURES], []) self.session.flush() self.topo_map1 = TopoMap( code='3232ET', editor='IGN', scale='25000', locales=[DocumentLocale(lang='fr', title='Belley')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))' ) # noqa ) self.session.add(self.topo_map1) self.session.flush() self.session.add( TopoMapAssociation(document=self.waypoint2, topo_map=self.topo_map1)) self.session.add( TopoMapAssociation(document=self.waypoint3, topo_map=self.topo_map1)) self.session.add( TopoMapAssociation(document=self.route2, topo_map=self.topo_map1)) self.session.add( TopoMapAssociation(document=self.route3, topo_map=self.topo_map1)) self.session.flush() self.area1 = Area( area_type='range', geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))' # noqa )) self.session.add(self.area1) self.session.flush() self.session.add( AreaAssociation(document=self.waypoint2, area=self.area1)) self.session.add( AreaAssociation(document=self.waypoint3, area=self.area1)) self.session.add(AreaAssociation(document=self.route2, area=self.area1)) self.session.add(AreaAssociation(document=self.route3, area=self.area1)) self.session.flush()
def _add_test_data(self): self.xreport1 = Xreport(activities=['hiking'], event_type=['stone_fall']) self.locale_en = XreportLocale(lang='en', title='Lac d\'Annecy', place='some place descrip. in english') self.locale_fr = XreportLocale(lang='fr', title='Lac d\'Annecy', place='some place descrip. in french') self.xreport1.locales.append(self.locale_en) self.xreport1.locales.append(self.locale_fr) self.session.add(self.xreport1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.xreport1, user_id) self.xreport1_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.xreport1.document_id). \ filter(DocumentVersion.lang == 'en').first() user_id3 = self.global_userids['contributor3'] self.session.add( Association(parent_document_id=user_id3, parent_document_type=USERPROFILE_TYPE, child_document_id=self.xreport1.document_id, child_document_type=XREPORT_TYPE)) self.xreport2 = Xreport(activities=['hiking'], event_type=['avalanche'], nb_participants=5) self.session.add(self.xreport2) self.xreport3 = Xreport(activities=['hiking'], event_type=['avalanche'], nb_participants=5) self.session.add(self.xreport3) self.xreport4 = Xreport(activities=['hiking'], event_type=['avalanche'], nb_participants=5, nb_impacted=5, age=50) self.xreport4.locales.append( DocumentLocale(lang='en', title='Lac d\'Annecy')) self.xreport4.locales.append( DocumentLocale(lang='fr', title='Lac d\'Annecy')) self.session.add(self.xreport4) self.article2 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article2) self.session.flush() self.image2 = Image(filename='image2.jpg', activities=['paragliding'], height=1500) self.session.add(self.image2) self.session.flush() self.waypoint1 = Waypoint(waypoint_type='summit', elevation=2203) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='climbing_outdoor', elevation=2, rock_types=[], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.session.add(self.waypoint2) self.session.flush() self.outing3 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 2, 1), date_end=datetime.date(2016, 2, 2)) self.session.add(self.outing3) self.route3 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1') self.session.add(self.route3) self.session.flush() self.session.add( Association.create(parent_document=self.outing3, child_document=self.xreport1)) self.session.add( Association.create(parent_document=self.route3, child_document=self.xreport1)) self.session.flush()
def _add_test_data(self): self.waypoint = Waypoint(waypoint_type='summit', elevation=2203) self.locale_en = WaypointLocale(lang='en', title='Mont Granier', description='...', access='yep') self.locale_fr = WaypointLocale(lang='fr', title='Mont Granier', description='...', access='ouai') self.waypoint.locales.append(self.locale_en) self.waypoint.locales.append(self.locale_fr) self.waypoint.geometry = DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)') self.session.add(self.waypoint) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.waypoint, user_id) self.waypoint_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.waypoint.document_id). \ filter(DocumentVersion.lang == 'en').first() self.waypoint2 = Waypoint( waypoint_type='climbing_outdoor', elevation=2, rock_types=[], geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.session.add(self.waypoint2) self.waypoint3 = Waypoint( waypoint_type='summit', elevation=3, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.session.add(self.waypoint3) self.waypoint4 = Waypoint( waypoint_type='summit', elevation=4, protected=True, geometry=DocumentGeometry(geom='SRID=3857;POINT(659775 5694854)')) self.waypoint4.locales.append( WaypointLocale(lang='en', title='Mont Granier', description='...', access='yep')) self.waypoint4.locales.append( WaypointLocale(lang='fr', title='Mont Granier', description='...', access='ouai')) self.session.add(self.waypoint4) self.waypoint5 = Waypoint( waypoint_type='summit', elevation=3, redirects_to=self.waypoint.document_id, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)')) self.waypoint5.locales.append( WaypointLocale(lang='en', title='Mont Granier', description='...', access='yep')) self.session.add(self.waypoint5) self.session.flush() DocumentRest.create_new_version(self.waypoint4, self.global_userids['contributor']) DocumentRest.create_new_version(self.waypoint5, self.global_userids['contributor']) # add some associations self.route1 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', main_waypoint_id=self.waypoint.document_id) self.route1.locales.append( RouteLocale(lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider')) self.session.add(self.route1) self.session.flush() self.route2 = Route(redirects_to=self.route1.document_id, activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', main_waypoint_id=self.waypoint.document_id) self.route3 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1') self.route3.locales.append( RouteLocale(lang='en', title='Mont Blanc from the air', description='...', title_prefix='Mont Blanc :', gear='paraglider')) self.session.add(self.route2) self.session.add(self.route3) self.session.flush() self.session.add( Association(parent_document_id=self.waypoint.document_id, child_document_id=self.waypoint4.document_id)) self.session.add( Association(parent_document_id=self.waypoint.document_id, child_document_id=self.waypoint5.document_id)) self.session.add( Association(parent_document_id=self.waypoint.document_id, child_document_id=self.route1.document_id)) self.session.add( Association(parent_document_id=self.waypoint.document_id, child_document_id=self.route2.document_id)) self.session.add( Association(parent_document_id=self.waypoint4.document_id, child_document_id=self.route3.document_id)) self.outing1 = Outing(activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 3), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing1) self.session.flush() self.session.add( Association(parent_document_id=self.route1.document_id, child_document_id=self.outing1.document_id)) self.outing2 = Outing(redirects_to=self.outing1.document_id, activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.outing3 = Outing(activities=['skitouring'], date_start=datetime.date(2015, 12, 31), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale(lang='en', title='...', description='...', weather='sunny') ]) self.session.add(self.outing2) self.session.add(self.outing3) self.session.flush() self.session.add( Association(parent_document_id=self.route1.document_id, child_document_id=self.outing2.document_id)) self.session.add( Association(parent_document_id=self.route3.document_id, child_document_id=self.outing3.document_id)) # add a map topo_map = TopoMap( code='3232ET', editor='IGN', scale='25000', locales=[DocumentLocale(lang='fr', title='Belley')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))' ) # noqa ) self.session.add(topo_map) self.session.flush() self.session.add( TopoMap( redirects_to=topo_map.document_id, code='3232ET', editor='IGN', scale='25000', locales=[DocumentLocale(lang='fr', title='Belley')], geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))' ) # noqa )) # add areas self.area1 = Area( area_type='range', geometry=DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((611774.917032556 5706934.10657514,611774.917032556 5744215.5846397,642834.402570357 5744215.5846397,642834.402570357 5706934.10657514,611774.917032556 5706934.10657514))' # noqa )) self.area2 = Area(area_type='range', locales=[DocumentLocale(lang='fr', title='France')]) self.session.add_all([self.area1, self.area2]) self.session.add( AreaAssociation(document=self.waypoint, area=self.area2)) self.session.flush()
def _add_test_data(self): self.route = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1') self.locale_en = RouteLocale( lang='en', title='Mont Blanc from the air', description='...', gear='paraglider', title_prefix='Main waypoint title', document_topic=DocumentTopic(topic_id=1)) self.locale_fr = RouteLocale( lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider') self.route.locales.append(self.locale_en) self.route.locales.append(self.locale_fr) self.route.geometry = DocumentGeometry( geom_detail='SRID=3857;LINESTRING(635956 5723604, 635966 5723644)', geom='SRID=3857;POINT(635961 5723624)' ) self.session.add(self.route) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.route, user_id) self.route_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.route.document_id). \ filter(DocumentVersion.lang == 'en').first() self.article1 = Article(categories=['site_info'], activities=['hiking'], article_type='collab') self.session.add(self.article1) self.session.flush() self._add_association(Association.create( parent_document=self.route, child_document=self.article1), user_id) self.book1 = Book(activities=['hiking'], book_types=['biography']) self.session.add(self.book1) self.session.flush() self._add_association(Association.create( parent_document=self.book1, child_document=self.route), user_id) self.route2 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=800, height_diff_down=800, durations='1', locales=[ RouteLocale( lang='en', title='Mont Blanc from the air', description='...', gear='paraglider'), RouteLocale( lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider')] ) self.session.add(self.route2) self.session.flush() DocumentRest.create_new_version(self.route2, user_id) self.route3 = Route( activities=['skitouring'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1', locales=[ RouteLocale( lang='en', title='Mont Blanc from the air', description='...', gear='paraglider'), RouteLocale( lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider')] ) self.route3.geometry = DocumentGeometry(geom='SRID=3857;POINT(0 0)') self.session.add(self.route3) self.session.flush() DocumentRest.create_new_version(self.route3, user_id) self.route4 = Route( activities=['rock_climbing'], elevation_max=1500, elevation_min=700, height_diff_up=500, height_diff_down=500, durations='1', climbing_outdoor_type='single') self.route4.locales.append(RouteLocale( lang='en', title='Mont Blanc from the air', description='...', gear='paraglider')) self.route4.locales.append(RouteLocale( lang='fr', title='Mont Blanc du ciel', description='...', gear='paraglider')) self.session.add(self.route4) # add some associations self.waypoint = Waypoint( waypoint_type='climbing_outdoor', elevation=4, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.waypoint.locales.append(WaypointLocale( lang='en', title='Mont Granier 1 (en)', description='...', access='yep', access_period='yapa')) self.waypoint.locales.append(WaypointLocale( lang='fr', title='Mont Granier 1 (fr)', description='...', access='ouai', access_period='yapa')) self.session.add(self.waypoint) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4, geometry=DocumentGeometry( geom='SRID=3857;POINT(635956 5723604)')) self.waypoint2.locales.append(WaypointLocale( lang='en', title='Mont Granier 2 (en)', description='...', access='yep')) self.session.add(self.waypoint2) self.session.flush() self._add_association(Association.create( parent_document=self.route, child_document=self.route4), user_id) self._add_association(Association.create( parent_document=self.route4, child_document=self.route), user_id) self._add_association(Association.create( parent_document=self.waypoint, child_document=self.route), user_id) # add a map topo_map = TopoMap( code='3232ET', editor='IGN', scale='25000', locales=[ DocumentLocale(lang='fr', title='Belley') ], geometry=DocumentGeometry(geom_detail='SRID=3857;POLYGON((635900 5723600, 635900 5723700, 636000 5723700, 636000 5723600, 635900 5723600))') # noqa ) self.session.add(topo_map) self.session.flush() self.session.add(TopoMapAssociation( document=self.route, topo_map=topo_map)) self.outing1 = Outing( activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), public_transport=True, locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny') ] ) self.session.add(self.outing1) self.session.flush() self._add_association(Association.create( parent_document=self.route, child_document=self.outing1), user_id) self.outing2 = Outing( redirects_to=self.outing1.document_id, activities=['skitouring'], date_start=datetime.date(2016, 1, 1), date_end=datetime.date(2016, 1, 1), locales=[ OutingLocale( lang='en', title='...', description='...', weather='sunny') ] ) self.session.add(self.outing2) self.session.flush() self._add_association(Association.create( parent_document=self.route, child_document=self.outing2), user_id) self.session.flush() # add areas self.area1 = Area( area_type='range', geometry=DocumentGeometry( geom_detail='SRID=3857;POLYGON((635900 5723600, 635900 5723700, 636000 5723700, 636000 5723600, 635900 5723600))' # noqa ) ) self.area2 = Area( area_type='range', locales=[ DocumentLocale(lang='fr', title='France') ] ) self.session.add_all([self.area1, self.area2]) self.session.flush()
def _add_test_data(self): self.area1 = Area(area_type='range') self.locale_en = DocumentLocale(lang='en', title='Chartreuse') self.locale_fr = DocumentLocale(lang='fr', title='Chartreuse') self.area1.locales.append(self.locale_en) self.area1.locales.append(self.locale_fr) self.area1.geometry = DocumentGeometry( geom_detail= 'SRID=3857;POLYGON((668518.249382151 5728802.39591739,668518.249382151 5745465.66808356,689156.247019149 5745465.66808356,689156.247019149 5728802.39591739,668518.249382151 5728802.39591739))' # noqa ) self.session.add(self.area1) self.session.flush() user_id = self.global_userids['contributor'] DocumentRest.create_new_version(self.area1, user_id) self.area1_version = self.session.query(DocumentVersion). \ filter(DocumentVersion.document_id == self.area1.document_id). \ filter(DocumentVersion.lang == 'en').first() self.area2 = Area(area_type='range') self.session.add(self.area2) self.area3 = Area(area_type='range') self.session.add(self.area3) self.area4 = Area(area_type='admin_limits') self.area4.locales.append(DocumentLocale(lang='en', title='Isère')) self.area4.locales.append(DocumentLocale(lang='fr', title='Isère')) self.session.add(self.area4) self.waypoint1 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(677461.381691516 5740879.44638645)')) self.waypoint2 = Waypoint( waypoint_type='summit', geometry=DocumentGeometry( geom='SRID=3857;POINT(693666.031687976 5741108.7574713)')) route_geom = 'SRID=3857;LINESTRING(668518 5728802, 668528 5728812)' self.route = Route(activities=['skitouring'], geometry=DocumentGeometry(geom_detail=route_geom)) self.session.add_all([self.waypoint1, self.waypoint2, self.route]) self.session.add( AreaAssociation(document=self.waypoint2, area=self.area1)) self.image = Image(filename='image.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air', description='...') ]) self.session.add(self.image) self.session.flush() self._add_association(Association.create(self.area1, self.image), user_id) self.session.flush()
def setUp(self): # noqa super(TestDocumentMergeRest, self).setUp() self._prefix = '/documents/merge' contributor_id = self.global_userids['contributor'] self.waypoint1 = Waypoint( waypoint_type='summit', elevation=2000, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='fr', title='Dent de Crolles', description='...', summary='La Dent de Crolles') ]) self.session.add(self.waypoint1) self.waypoint2 = Waypoint( waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add(self.waypoint2) self.session.flush() self.waypoint3 = Waypoint( waypoint_type='summit', elevation=4985, redirects_to=self.waypoint1.document_id, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add(self.waypoint3) self.waypoint4 = Waypoint( waypoint_type='summit', elevation=4985, geometry=DocumentGeometry(geom='SRID=3857;POINT(635956 5723604)'), locales=[ WaypointLocale(lang='en', title='Mont Blanc', description='...', summary='The heighest point in Europe') ]) self.session.add(self.waypoint4) self.session.flush() self.route1 = Route(activities=['skitouring'], elevation_max=1500, elevation_min=700, main_waypoint_id=self.waypoint1.document_id, locales=[ RouteLocale(lang='fr', title='Mont Blanc du ciel', description='...', summary='Ski') ]) self.session.add(self.route1) self.session.flush() DocumentRest.create_new_version(self.waypoint1, contributor_id) update_feed_document_create(self.waypoint1, contributor_id) association = Association.create(parent_document=self.waypoint1, child_document=self.route1) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) association = Association.create(parent_document=self.waypoint1, child_document=self.waypoint4) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) association = Association.create(parent_document=self.waypoint2, child_document=self.waypoint4) self.session.add(association) self.session.add( association.get_log(self.global_userids['contributor'])) self.session.flush() self.image1 = Image(filename='image1.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air', description='...') ]) self.session.add(self.image1) self.image2 = Image(filename='image2.jpg', activities=['paragliding'], height=1500, image_type='collaborative', locales=[ DocumentLocale(lang='en', title='Mont Blanc from the air', description='...') ]) self.session.add(self.image2) self.session.flush() DocumentRest.create_new_version(self.image1, contributor_id) self.session.flush() self.image1.filename = 'image1.1.jpg' self.session.flush() DocumentRest.update_version(self.image1, contributor_id, 'changed filename', [UpdateType.FIGURES], []) self.session.flush()