From 3e3876437acbc739763df809fe504eeaf44d50ec Mon Sep 17 00:00:00 2001 From: amplifi Date: Thu, 8 Dec 2016 02:06:33 +1000 Subject: [PATCH] Modifies loadpolicies to remove necessity of update flag and ensure it runs at provisioning Reference Issue #978 --- cadasta/accounts/load.py | 7 ++-- .../management/commands/loadpolicies.py | 8 +--- .../test_management_commands_loadpolicies.py | 6 +-- .../core/management/commands/loadstatic.py | 37 +++++++------------ cadasta/core/tests/factories.py | 4 +- .../core/tests/test_management_commands.py | 2 - .../roles/webserver/production/tasks/main.yml | 8 ++++ 7 files changed, 30 insertions(+), 42 deletions(-) diff --git a/cadasta/accounts/load.py b/cadasta/accounts/load.py index 3187fe9c1..1a19ad350 100644 --- a/cadasta/accounts/load.py +++ b/cadasta/accounts/load.py @@ -3,7 +3,7 @@ from tutelary import models -def run(verbose=True, force=False, update=False): +def run(verbose=True, force=False): PERMISSIONS_DIR = settings.BASE_DIR + '/permissions/' if force: @@ -16,9 +16,8 @@ def run(verbose=True, force=False, update=False): 'project-manager', 'data-collector', 'project-user']: try: pols[pol] = models.Policy.objects.get(name=pol) - if update: - pols[pol].body = open(PERMISSIONS_DIR + pol + '.json').read() - pols[pol].save() + pols[pol].body = open(PERMISSIONS_DIR + pol + '.json').read() + pols[pol].save() except: pols[pol] = models.Policy.objects.create( name=pol, diff --git a/cadasta/accounts/management/commands/loadpolicies.py b/cadasta/accounts/management/commands/loadpolicies.py index c91340bd1..72b522220 100644 --- a/cadasta/accounts/management/commands/loadpolicies.py +++ b/cadasta/accounts/management/commands/loadpolicies.py @@ -13,11 +13,5 @@ def add_arguments(self, parser): dest='force', default=False) - parser.add_argument( - '--update', - action='store_true', - dest='update', - default=False) - def handle(self, *args, **options): - load.run(force=options['force'], update=options['update']) + load.run(force=options['force']) diff --git a/cadasta/accounts/tests/test_management_commands_loadpolicies.py b/cadasta/accounts/tests/test_management_commands_loadpolicies.py index a442b3432..4eae78c45 100644 --- a/cadasta/accounts/tests/test_management_commands_loadpolicies.py +++ b/cadasta/accounts/tests/test_management_commands_loadpolicies.py @@ -25,10 +25,10 @@ def test_command_no_args(self): call_command('loadpolicies') assert accounts.load.run.call_count == 1 assert accounts.load.run.args == () - assert accounts.load.run.kwargs == {'force': False, 'update': False} + assert accounts.load.run.kwargs == {'force': False} def test_command_with_args(self): - call_command('loadpolicies', force=True, update=True) + call_command('loadpolicies', force=True) assert accounts.load.run.call_count == 1 assert accounts.load.run.args == () - assert accounts.load.run.kwargs == {'force': True, 'update': True} + assert accounts.load.run.kwargs == {'force': True} diff --git a/cadasta/core/management/commands/loadstatic.py b/cadasta/core/management/commands/loadstatic.py index cbf9f52d7..bbf09f837 100644 --- a/cadasta/core/management/commands/loadstatic.py +++ b/cadasta/core/management/commands/loadstatic.py @@ -19,30 +19,19 @@ def add_arguments(self, parser): default=False, help='Force object deletion and recreation' ) - parser.add_argument( - '--update-policies', - action='store_true', - dest='update_policies', - default=False, - help='Force update of tutelary policies from JSON files' - ) def handle(self, *args, **options): - if options['update_policies']: - print('PERFORMING POLICY UPDATE FROM FILES!!!\n') - loadpolicies.Command().handle(force=False, update=True) - else: - # All of the following are idempotent unless "force" is used. - if options['force']: - print('FORCING STATIC DATA RELOAD!!!\n') + # All of the following are idempotent unless "force" is used. + if options['force']: + print('FORCING STATIC DATA RELOAD!!!\n') - print('LOADING SITE\n') - loadsite.Command().handle(force=options['force']) - print('LOADING COUNTRIES\n') - loadcountries.Command().handle(force=options['force']) - print('LOADING POLICIES\n') - loadpolicies.Command().handle(force=options['force'], update=False) - print('LOADING ATTRIBUTE TYPES\n') - loadattrtypes.Command().handle(force=options['force']) - print('LOADING TENURE RELATIONSHIP TYPES\n') - loadtenurereltypes.Command().handle(force=options['force']) + print('LOADING SITE\n') + loadsite.Command().handle(force=options['force']) + print('LOADING COUNTRIES\n') + loadcountries.Command().handle(force=options['force']) + print('LOADING POLICIES\n') + loadpolicies.Command().handle(force=options['force']) + print('LOADING ATTRIBUTE TYPES\n') + loadattrtypes.Command().handle(force=options['force']) + print('LOADING TENURE RELATIONSHIP TYPES\n') + loadtenurereltypes.Command().handle(force=options['force']) diff --git a/cadasta/core/tests/factories.py b/cadasta/core/tests/factories.py index d3d4bd797..e9b04588e 100644 --- a/cadasta/core/tests/factories.py +++ b/cadasta/core/tests/factories.py @@ -28,8 +28,8 @@ def _adjust_kwargs(cls, **kwargs): kwargs['body'] = open(body_file).read() return kwargs - def load_policies(update=False): - load.run(force=not update, update=update) + def load_policies(force=True): + load.run(force) class RoleFactory(factory.django.DjangoModelFactory): diff --git a/cadasta/core/tests/test_management_commands.py b/cadasta/core/tests/test_management_commands.py index 65c62eaf8..4c03ef133 100644 --- a/cadasta/core/tests/test_management_commands.py +++ b/cadasta/core/tests/test_management_commands.py @@ -20,8 +20,6 @@ def test_fixture_setup(self): data.delete_test_projects() data.add_test_organizations() PolicyFactory.load_policies() - # Just for test coverage... - PolicyFactory.load_policies(update=True) create_attribute_types() load_tenure_relationship_types() data.add_test_users_and_roles() diff --git a/provision/roles/webserver/production/tasks/main.yml b/provision/roles/webserver/production/tasks/main.yml index 391c412a6..ed8fda512 100644 --- a/provision/roles/webserver/production/tasks/main.yml +++ b/provision/roles/webserver/production/tasks/main.yml @@ -85,6 +85,14 @@ notify: - Restart nginx +- name: Load static data + become: yes + become_user: "{{ app_user }}" + django_manage: command=loadstatic + app_path="{{ application_path }}cadasta" + virtualenv="{{ virtualenv_path }}" + settings="{{ django_settings }}" + - name: Link static content become: yes become_user: "{{ app_user }}"