* Add notify user id in config
* Add dao method to get provider history versions along with tests
* BUG: Provider switching did not handle case where priorities were equal. This
* adds a fix to properly cover this case along with tests
This commit is contained in:
Imdad Ahad
2017-03-02 18:03:53 +00:00
parent 19df677315
commit 37341e7a62
5 changed files with 155 additions and 32 deletions

View File

@@ -1,32 +1,39 @@
from flask import current_app
from app.dao.users_dao import get_user_by_id
def provider_is_already_primary_or_inactive(current_provider, new_provider, identifier):
if current_provider.identifier == identifier:
current_app.logger.warning('Provider {} is already activated'.format(current_provider.display_name))
def provider_is_inactive(new_provider):
if not new_provider.active:
current_app.logger.warning('Cancelling switch to {} as they are inactive'.format(
new_provider.identifier,
))
return True
elif not new_provider.active:
current_app.logger.warning('Cancelling switch from {} to {} as {} is inactive'.format(
current_provider.identifier,
new_provider.identifier,
new_provider.identifier
))
def provider_is_primary(current_provider, new_provider, identifier):
if current_provider.identifier == identifier:
current_app.logger.warning('Provider {} is already activated'.format(current_provider.display_name))
return True
return False
def update_provider_priorities(current_provider, new_provider):
def switch_providers(current_provider, new_provider):
# Automatic update so set as notify user
notify_user = get_user_by_id(current_app.config['NOTIFY_USER_ID'])
current_provider.created_by_id = new_provider.created_by_id = notify_user.id
# Swap priority to change primary provider
if new_provider.priority > current_provider.priority:
new_provider.priority, current_provider.priority = current_provider.priority, new_provider.priority
# Incease other provider priority if equal
# Increase other provider priority if equal
elif new_provider.priority == current_provider.priority:
current_provider.priority += 10
_print_provider_switch_logs(current_provider, new_provider)
return current_provider, new_provider
def _print_provider_switch_logs(current_provider, new_provider):