diff --git a/cadasta/core/management/commands/loadeverything.py b/cadasta/core/management/commands/loadeverything.py new file mode 100644 index 000000000..44af2e841 --- /dev/null +++ b/cadasta/core/management/commands/loadeverything.py @@ -0,0 +1,15 @@ +from django.core.management.base import BaseCommand + +from core.management.commands import loadfixtures, loadsite +from accounts.management.commands import loadpolicies +from geography.management.commands import loadcountries + + +class Command(BaseCommand): + help = """Load in all site, country, policy and test data.""" + + def handle(self, *args, **options): + loadsite.Command().handle() + loadcountries.Command().handle() + loadpolicies.Command().handle() + loadfixtures.Command().handle(delete=False) diff --git a/cadasta/core/management/commands/loadsite.py b/cadasta/core/management/commands/loadsite.py new file mode 100644 index 000000000..7547bde6f --- /dev/null +++ b/cadasta/core/management/commands/loadsite.py @@ -0,0 +1,16 @@ +from django.core.management.base import BaseCommand +from django.contrib.sites.models import Site + + +class Command(BaseCommand): + help = """Loads initial site object for Cadasta.org.""" + + def handle(self, *args, **options): + if not Site.objects.filter(name='Cadasta').exists(): + site = Site.objects.get(name='example.com') + site.name = 'Cadasta' + site.domain = 'platform.cadasta.org' + site.save() + return "Successfully loaded Cadasta.org object" + else: + return "Cadasta.org object already exists." diff --git a/cadasta/core/tests/test_fixtures.py b/cadasta/core/tests/test_management_commands.py similarity index 71% rename from cadasta/core/tests/test_fixtures.py rename to cadasta/core/tests/test_management_commands.py index 2075a4b53..c5007ec72 100644 --- a/cadasta/core/tests/test_fixtures.py +++ b/cadasta/core/tests/test_management_commands.py @@ -1,4 +1,5 @@ from django.test import TestCase +from django.contrib.sites.models import Site from core.tests.factories import PolicyFactory from ..fixtures import FixturesData @@ -6,6 +7,7 @@ from accounts.models import User from organization.models import Organization, Project from spatial.models import SpatialUnit, SpatialRelationship +from core.management.commands import loadsite class FixturesTest(TestCase): @@ -36,3 +38,14 @@ def test_fixture_setup(self): assert Project.objects.count() == 0 assert SpatialUnit.objects.count() == 0 assert SpatialRelationship.objects.count() == 0 + + +class LoadSiteTest(TestCase): + def test_default_site_replacement(self): + assert Site.objects.filter(name='example.com').exists() + loadsite.Command().handle() + assert len(Site.objects.all()) == 1 + assert Site.objects.filter(name='Cadasta').exists() + response = loadsite.Command().handle() + assert len(Site.objects.all()) == 1 + assert response == "Cadasta.org object already exists." diff --git a/provision/roles/cadasta/application/tasks/main.yml b/provision/roles/cadasta/application/tasks/main.yml index 4f1aef9e2..6fada180b 100644 --- a/provision/roles/cadasta/application/tasks/main.yml +++ b/provision/roles/cadasta/application/tasks/main.yml @@ -99,6 +99,22 @@ virtualenv="{{ virtualenv_path }}" settings="{{ django_settings }}" +- name: Load site object + become: yes + become_user: "{{ app_user }}" + django_manage: command=loadsite + app_path="{{ application_path }}cadasta" + virtualenv="{{ virtualenv_path }}" + settings="{{ django_settings }}" + +- name: Load all data + become: yes + become_user: "{{ app_user }}" + django_manage: command=loadeverything + app_path="{{ application_path }}cadasta" + virtualenv="{{ virtualenv_path }}" + settings="{{ django_settings }}" + - name: Install Bootstrap for SASS processing become: yes become_user: "{{ app_user }}"