-
Notifications
You must be signed in to change notification settings - Fork 3
Bugfix/ogc 3003 fix migrate links #2428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8685d5f
640950e
846f6d2
83a3980
997edc3
e0fed86
f075f1c
627ebae
8bed955
4ada6f8
cead900
df1e866
7e3b502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,21 @@ | ||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| from onegov.api.models import ApiKey | ||||||||||||||||||||||||||||||||||||||
| from xml.etree.ElementTree import tostring | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import transaction | ||||||||||||||||||||||||||||||||||||||
| from onegov.api.models import ApiKey | ||||||||||||||||||||||||||||||||||||||
| from onegov.core.utils import Bunch | ||||||||||||||||||||||||||||||||||||||
| from onegov.org.models import News | ||||||||||||||||||||||||||||||||||||||
| from onegov.org.models import Topic | ||||||||||||||||||||||||||||||||||||||
| from onegov.org.models.page import TopicCollection, NewsCollection | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, Any | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING | ||||||||||||||||||||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||||||||||||||||||||
| from .conftest import Client | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_gever_settings_only_https_allowed(client: Client) -> None: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| client.login_admin() | ||||||||||||||||||||||||||||||||||||||
| settings = client.get('/settings').click('Gever API') | ||||||||||||||||||||||||||||||||||||||
| settings.form['gever_username'] = 'foo' | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -30,7 +35,6 @@ def test_gever_settings_only_https_allowed(client: Client) -> None: | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_api_keys_create_and_delete(client: Client) -> None: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| client.login_admin() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| settings = client.get('/api-keys') | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -121,9 +125,7 @@ def test_analytics_settings(client: Client) -> None: | |||||||||||||||||||||||||||||||||||||
| ) in settings | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_firebase_settings(client: Client) -> None: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| client.login_admin() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Pretend this is real data (it's completely random) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -165,3 +167,69 @@ def test_resource_settings(client: Client) -> None: | |||||||||||||||||||||||||||||||||||||
| assert 'Allgemeine Informationen zu Reservationen' in page | ||||||||||||||||||||||||||||||||||||||
| assert '<h1>foo</h1>' in page | ||||||||||||||||||||||||||||||||||||||
| assert '<p>bar</p>' in page | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_migrate_links(client: Client) -> None: | ||||||||||||||||||||||||||||||||||||||
| session = client.app.session() | ||||||||||||||||||||||||||||||||||||||
| request: Any = Bunch(**{ | ||||||||||||||||||||||||||||||||||||||
| 'session': session, | ||||||||||||||||||||||||||||||||||||||
| 'identity.role': 'admin' | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
| old_domain = 'foo.ch' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # create topic | ||||||||||||||||||||||||||||||||||||||
| topic = Topic(title='Foo Topic', name='foo-topic') | ||||||||||||||||||||||||||||||||||||||
| topic.text = '<p>Wow, https://foo.ch/abc is a great page!</p>' | ||||||||||||||||||||||||||||||||||||||
| session.add(topic) | ||||||||||||||||||||||||||||||||||||||
| topic_text = str(topic.text) | ||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The type checker error was due to this potentially being |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # add news article (must be under the seeded /news/ root) | ||||||||||||||||||||||||||||||||||||||
| from onegov.page import PageCollection | ||||||||||||||||||||||||||||||||||||||
| news_root = PageCollection(session).by_path('/news/', ensure_type='news') | ||||||||||||||||||||||||||||||||||||||
| assert isinstance(news_root, News) | ||||||||||||||||||||||||||||||||||||||
| news = News(title='Big News', name='big-news', parent=news_root) | ||||||||||||||||||||||||||||||||||||||
| news.text = ('<p>Big news https://foo.ch/big-news and bigger news' | ||||||||||||||||||||||||||||||||||||||
| 'can be found here https://foo.ch/bigger-news</p>') | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+191
to
+192
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| session.add(news) | ||||||||||||||||||||||||||||||||||||||
| news_text = str(news.text) | ||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| transaction.commit() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def get_topic_text() -> str: | ||||||||||||||||||||||||||||||||||||||
| t = TopicCollection(session).by_title('Foo Topic') | ||||||||||||||||||||||||||||||||||||||
| assert t is not None and t.text is not None | ||||||||||||||||||||||||||||||||||||||
| return str(t.text) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def get_news_text() -> str: | ||||||||||||||||||||||||||||||||||||||
| n = NewsCollection(request).by_title('Big News') | ||||||||||||||||||||||||||||||||||||||
| assert n is not None and n.text is not None | ||||||||||||||||||||||||||||||||||||||
| return str(n.text) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+198
to
+206
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert old_domain in get_topic_text() | ||||||||||||||||||||||||||||||||||||||
| assert old_domain in get_news_text() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # execute migrate links test | ||||||||||||||||||||||||||||||||||||||
| client.login_admin() | ||||||||||||||||||||||||||||||||||||||
| migrate_page = client.get('/migrate-links') | ||||||||||||||||||||||||||||||||||||||
| migrate_page.form['old_domain'] = old_domain | ||||||||||||||||||||||||||||||||||||||
| migrate_page.form['test'] = True | ||||||||||||||||||||||||||||||||||||||
| result = migrate_page.form.submit() | ||||||||||||||||||||||||||||||||||||||
| assert 'Total 3 Links gefunden' in result | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert old_domain in get_topic_text() | ||||||||||||||||||||||||||||||||||||||
| assert old_domain in get_news_text() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # execute migrate links | ||||||||||||||||||||||||||||||||||||||
| migrate_page = client.get('/migrate-links') | ||||||||||||||||||||||||||||||||||||||
| migrate_page.form['old_domain'] = old_domain | ||||||||||||||||||||||||||||||||||||||
| migrate_page.form['test'] = False | ||||||||||||||||||||||||||||||||||||||
| result = migrate_page.form.submit().follow() | ||||||||||||||||||||||||||||||||||||||
| assert '3 Links migriert' in result | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| topic_text_new = get_topic_text() | ||||||||||||||||||||||||||||||||||||||
| news_text_new = get_news_text() | ||||||||||||||||||||||||||||||||||||||
| assert old_domain not in topic_text_new | ||||||||||||||||||||||||||||||||||||||
| assert old_domain not in news_text_new | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert topic_text.replace('foo.ch', 'localhost') == topic_text_new | ||||||||||||||||||||||||||||||||||||||
| assert news_text.replace('foo.ch', 'localhost') == news_text_new | ||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should use an |
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to use
Markuphere, otherwise<p>will get escaped to<p>