Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
3c4f80c to
e0fed86
Compare
This reverts commit 3810420.
There was a problem hiding this comment.
Pull request overview
Fixes the /migrate-links link migration behavior to (1) count all URL occurrences rather than just “field changed”, and (2) preserve Markup values during substitution to avoid unwanted escaping changes.
Changes:
- Update link migration to use
re.subnfor accurate per-occurrence counting and propagateMarkupfor migrated HTML fields. - Add a Town6 integration test covering the
/migrate-linksdry-run and actual migration behavior. - Add
by_title()helpers onTopicCollection/NewsCollectionto simplify retrieving fixtures in tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/onegov/town6/test_views_settings.py | Adds an end-to-end test for /migrate-links covering detection and migration of multiple links. |
| src/onegov/org/models/page.py | Adds by_title() convenience lookups to TopicCollection and NewsCollection. |
| src/onegov/org/management.py | Counts replacements with subn and preserves Markup when mutating stored HTML content. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| topic_text_replaced = topic_text.replace('foo.ch', 'localhost') | ||
| assert topic_text_replaced == topic_text_new | ||
| news_text_replaced = news_text.replace('foo.ch', 'localhost') |
There was a problem hiding this comment.
The expected replacement domain is hard-coded as 'localhost'. This makes the test brittle if the test server host/domain is ever changed (e.g. to 127.0.0.1 or a custom host). Prefer deriving the expected new domain from the app/request (the same value used by the migration, i.e. request.domain).
| topic_text_replaced = topic_text.replace('foo.ch', 'localhost') | |
| assert topic_text_replaced == topic_text_new | |
| news_text_replaced = news_text.replace('foo.ch', 'localhost') | |
| # derive the new domain from the migrated topic text to avoid | |
| # hard-coding values like 'localhost' which depend on the test host | |
| new_domain = topic_text_new.split('https://', 1)[1].split('/abc', 1)[0] | |
| topic_text_replaced = topic_text.replace(old_domain, new_domain) | |
| assert topic_text_replaced == topic_text_new | |
| news_text_replaced = news_text.replace(old_domain, new_domain) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
||
| # create topic | ||
| topic = Topic(title='Foo Topic', name='foo-topic') | ||
| topic.text = '<p>Wow, https://foo.ch/abc is a great page!</p>' |
There was a problem hiding this comment.
| topic.text = '<p>Wow, https://foo.ch/abc is a great page!</p>' | |
| topic.text = Markup('<p>Wow, https://foo.ch/abc is a great page!</p>') |
Make sure to use Markup here, otherwise <p> will get escaped to <p>
| 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) |
There was a problem hiding this comment.
| topic_text = str(topic.text) | |
| topic_text = topic.text | |
| assert topic_text is not None |
The type checker error was due to this potentially being None, not because it wasn't a str.
| news.text = ('<p>Big news https://foo.ch/big-news and bigger news' | ||
| 'can be found here https://foo.ch/bigger-news</p>') |
There was a problem hiding this comment.
| news.text = ('<p>Big news https://foo.ch/big-news and bigger news' | |
| 'can be found here https://foo.ch/bigger-news</p>') | |
| news.text = Markup('<p>Big news https://foo.ch/big-news and bigger news' | |
| 'can be found here https://foo.ch/bigger-news</p>') |
| news.text = ('<p>Big news https://foo.ch/big-news and bigger news' | ||
| 'can be found here https://foo.ch/bigger-news</p>') | ||
| session.add(news) | ||
| news_text = str(news.text) |
There was a problem hiding this comment.
| news_text = str(news.text) | |
| news_text = news.text | |
| assert news_text is not None |
| 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) |
There was a problem hiding this comment.
| 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) | |
| def get_topic_text() -> Markup: | |
| t = TopicCollection(session).by_title('Foo Topic') | |
| assert t is not None and t.text is not None | |
| return t.text | |
| def get_news_text() -> Markup: | |
| n = NewsCollection(request).by_title('Big News') | |
| assert n is not None and n.text is not None | |
| return n.text |
| 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 |
There was a problem hiding this comment.
I think you should use an <a> tag in at least one of your tests, to make sure those remain intact as well, it should actually be very rare to encounter a naked link, they should almost always be part of an <a> tag in these fields.
Org: Fix migrate links tool
Use
re.subnto count URL occurrences per field (not just whether a field changed), and wrap thesubstituted value in
Markupwhen the original wasMarkupto prevent double-escaping HTMLentities.
TYPE: Bugfix
LINK: ogc-3003