Skip to content

Commit

Permalink
Merge pull request #390 from Cadasta/bugs/email-subject
Browse files Browse the repository at this point in the history
Fixes #387: new command to replace default site object
  • Loading branch information
ian-ross authored Jul 11, 2016
2 parents d8a1759 + 7e0757d commit ba2e041
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cadasta/core/management/commands/loadeverything.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions cadasta/core/management/commands/loadsite.py
Original file line number Diff line number Diff line change
@@ -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."
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.test import TestCase
from django.contrib.sites.models import Site

from core.tests.factories import PolicyFactory
from ..fixtures import FixturesData
from tutelary.models import Policy
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):
Expand Down Expand Up @@ -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."
16 changes: 16 additions & 0 deletions provision/roles/cadasta/application/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down

0 comments on commit ba2e041

Please sign in to comment.