- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
store_entity rework to add selective overwrite #61
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
store_entity rework to add selective overwrite #61
Conversation
| Pull Request Test Coverage Report for Build 9939539897Details
 
 
 
 💛 - Coveralls | 
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.
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 | 
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.
We should introduce an enum here, otherwise typos are likely
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.
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 | 
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.
'None' and 'false' should alse be enum values for consistancy and autocomplete support.
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.
Implemented with df2a469
| self._overwrite_per_class["by name"][model_name] = param | ||
| self._overwrite_per_class["by type"][model_type] = param | ||
|  | ||
| def store_entity( | 
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.
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
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.
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
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.
@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): | 
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.
Beside this integration test we should add a unit test for apply_override_policy()
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.
@SimonStier This implies that apply_overwrite_policy() should be accessible independently of store_entity() - correct?
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.
Correct =)
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.
* added inplace option to osw.core.OSW._ApplyOverwriteParam * moved template handling to store_entity to make osw.core.OSW_apply_overwrite_policy a static method
* added unit test for osw.core.OSW_apply_overwrite_policy * modified test of osw.core.OSW.store_entity
…up_key counting for non-matching groups
| @SimonStier Should be ready for merge. Please check cc43216 for potentially unwanted silent passes on pages without osw id in title or without jsondata | 
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