Skip to content

Conversation

@LukasGold
Copy link
Contributor

@LukasGold LukasGold commented Jul 8, 2024

This pull request includes a rework of store_entity() to allow selective overwriting. Not all viable options (e.g. overwriting only property values included in a revision older than x) are implemented yet

@LukasGold LukasGold requested a review from SimonStier July 8, 2024 10:31
@LukasGold LukasGold self-assigned this Jul 8, 2024
@coveralls
Copy link

coveralls commented Jul 8, 2024

Pull Request Test Coverage Report for Build 9939539897

Details

  • 191 of 244 (78.28%) changed or added relevant lines in 4 files are covered.
  • 8 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+2.4%) to 43.142%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/osw/utils/wiki.py 5 6 83.33%
src/osw/wtsite.py 18 22 81.82%
src/osw/core.py 165 213 77.46%
Files with Coverage Reduction New Missed Lines %
src/osw/utils/strings.py 1 53.85%
src/osw/utils/templates.py 1 77.27%
src/osw/wtsite.py 6 36.28%
Totals Coverage Status
Change from base Build 9809956479: 2.4%
Covered Lines: 2222
Relevant Lines: 4129

💛 - Coveralls

Copy link
Contributor

@SimonStier SimonStier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

src/osw/core.py Outdated
bool, # False: never overwrite a property,
# True: always overwrite a property
Literal[
"only empty", # only overwrite if the property is empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should introduce an enum here, otherwise typos are likely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented with df2a469

src/osw/core.py Outdated
"keep existing", # keep the entity, does not add or remove any properties,
# if the page exists, the entity is not stored
],
None, # Not an option to choose from, will be replaced by the default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'None' and 'false' should alse be enum values for consistancy and autocomplete support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented with df2a469

self._overwrite_per_class["by name"][model_name] = param
self._overwrite_per_class["by type"][model_type] = param

def store_entity(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we separate the application of the override policy in another (util) function?
e.g. apply_override_policy(org_page, new_page, policy)
This would improve clearness & testability of the code

Copy link
Contributor Author

@LukasGold LukasGold Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A sketch of what could be done:
We could separate the application of the overwrite of a page (locally setting the slot content + calling page.edit()) into a separate function osw.core.OSW.apply_overwrite_policy(org_page, entity, policy) -> osw.core.wtsite.WtPage

  • a params object would be defined with a validator checking that org_page and entity have the same uuid (for cases where apply_overwrite_policy() is called independently of store_entity().)
  • the store_entity() funtion would still call get_page() to get the original page (if exists)
  • therefore the set_content_and_edit_page() method would need to be moved to e.g. wtsite.WtPage

If it is not desired to access apply_overwrite_policy() independently, we could also define it as a function inside store_entity(), as done for set_content_and_edit_page().

@SimonStier please comment on what you had in mind

Copy link
Contributor Author

@LukasGold LukasGold Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonStier now implemented with b073c50.

# run with: tox -e test -- --wiki_domain domain --wiki_username user --wiki_password pass


def test_store_and_load(wiki_domain, wiki_username, wiki_password):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside this integration test we should add a unit test for apply_override_policy()

Copy link
Contributor Author

@LukasGold LukasGold Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonStier This implies that apply_overwrite_policy() should be accessible independently of store_entity() - correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented in b073c50
test included with 22bac86

@LukasGold LukasGold marked this pull request as draft July 12, 2024 10:01
@LukasGold LukasGold marked this pull request as ready for review July 15, 2024 12:40
@LukasGold
Copy link
Contributor Author

LukasGold commented Jul 15, 2024

@SimonStier Should be ready for merge.

Please check cc43216 for potentially unwanted silent passes on pages without osw id in title or without jsondata
Please check e1ca4b8 for the changes to WtPage.changed regarding compatibility with the overall design philosophy of slot changes / changed page

@simontaurus simontaurus merged commit ca4bb17 into main Jul 16, 2024
@LukasGold LukasGold added the enhancement New feature or request label Jul 16, 2024
@LukasGold LukasGold deleted the store_entity-rework-add-selective-overwrite branch November 28, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants