Skip to content
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

Report output fixes & changes, additional tests #48

Merged
merged 5 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 30 additions & 33 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import confy
from confy import read_environment_file, env
import os
from fabric.api import cd, run, local, get, settings
from fabric.contrib.files import exists, upload_template

confy.read_environment_file()
DEPLOY_REPO_URL = os.environ['DEPLOY_REPO_URL']
DEPLOY_TARGET = os.environ['DEPLOY_TARGET']
DEPLOY_VENV_PATH = os.environ['DEPLOY_VENV_PATH']
DEPLOY_VENV_NAME = os.environ['DEPLOY_VENV_NAME']
DEPLOY_DEBUG = os.environ['DEPLOY_DEBUG']
DEPLOY_PORT = os.environ['DEPLOY_PORT']
DEPLOY_DATABASE_URL = os.environ['DEPLOY_DATABASE_URL']
DEPLOY_SECRET_KEY = os.environ['DEPLOY_SECRET_KEY']
DEPLOY_CSRF_COOKIE_SECURE = os.environ['DEPLOY_CSRF_COOKIE_SECURE']
DEPLOY_SESSION_COOKIE_SECURE = os.environ['DEPLOY_SESSION_COOKIE_SECURE']
DEPLOY_USER = os.environ['DEPLOY_USER']
DEPLOY_DB_NAME = os.environ['DEPLOY_DB_NAME']
DEPLOY_DB_USER = os.environ['DEPLOY_DB_USER']
DEPLOY_SUPERUSER_USERNAME = os.environ['DEPLOY_SUPERUSER_USERNAME']
DEPLOY_SUPERUSER_EMAIL = os.environ['DEPLOY_SUPERUSER_EMAIL']
DEPLOY_SUPERUSER_PASSWORD = os.environ['DEPLOY_SUPERUSER_PASSWORD']
DEPLOY_SUPERVISOR_NAME = os.environ['DEPLOY_SUPERVISOR_NAME']
DEPLOY_EMAIL_HOST = os.environ['DEPLOY_EMAIL_HOST']
DEPLOY_EMAIL_PORT = os.environ['DEPLOY_EMAIL_PORT']
DEPLOY_SITE_URL = os.environ['SITE_URL']
GEOSERVER_WMS_URL = os.environ['GEOSERVER_WMS_URL']
GEOSERVER_WFS_URL = os.environ['GEOSERVER_WFS_URL']
read_environment_file()
DEPLOY_REPO_URL = env('DEPLOY_REPO_URL', '')
DEPLOY_TARGET = env('DEPLOY_TARGET', '')
DEPLOY_VENV_PATH = env('DEPLOY_VENV_PATH', '')
DEPLOY_VENV_NAME = env('DEPLOY_VENV_NAME', '')
DEPLOY_DEBUG = env('DEPLOY_DEBUG', '')
DEPLOY_PORT = env('DEPLOY_PORT', '')
DEPLOY_DATABASE_URL = env('DEPLOY_DATABASE_URL', '')
DEPLOY_SECRET_KEY = env('DEPLOY_SECRET_KEY', '')
DEPLOY_CSRF_COOKIE_SECURE = env('DEPLOY_CSRF_COOKIE_SECURE', '')
DEPLOY_SESSION_COOKIE_SECURE = env('DEPLOY_SESSION_COOKIE_SECURE', '')
DEPLOY_USER = env('DEPLOY_USER', '')
DEPLOY_DB_NAME = env('DEPLOY_DB_NAME', 'db')
DEPLOY_DB_USER = env('DEPLOY_DB_USER', 'dbuser')
DEPLOY_SUPERUSER_USERNAME = env('DEPLOY_SUPERUSER_USERNAME', 'superuser')
DEPLOY_SUPERUSER_EMAIL = env('DEPLOY_SUPERUSER_EMAIL', 'test@email.com')
DEPLOY_SUPERUSER_PASSWORD = env('DEPLOY_SUPERUSER_PASSWORD', 'pass')
DEPLOY_SUPERVISOR_NAME = env('DEPLOY_SUPERVISOR_NAME', 'sv')
DEPLOY_EMAIL_HOST = env('DEPLOY_EMAIL_HOST', 'email.host')
DEPLOY_EMAIL_PORT = env('DEPLOY_EMAIL_PORT', '25')
DEPLOY_SITE_URL = env('SITE_URL', 'url')
GEOSERVER_WMS_URL = env('GEOSERVER_WMS_URL', 'url')
GEOSERVER_WFS_URL = env('GEOSERVER_WFS_URL', 'url')


def _get_latest_source():
Expand Down Expand Up @@ -109,8 +109,8 @@ def _create_db():
"""Creates a database on the deploy target. Assumes that PGHOST and PGUSER are set.
"""
db = {
'NAME': os.environ['DEPLOY_DB_NAME'],
'USER': os.environ['DEPLOY_DB_USER'],
'NAME': DEPLOY_DB_NAME,
'USER': DEPLOY_DB_USER,
}
sql = '''CREATE DATABASE {NAME} OWNER {USER};
\c {NAME}'''.format(**db)
Expand All @@ -126,11 +126,8 @@ def _migrate():


def _create_superuser():
un = os.environ['DEPLOY_SUPERUSER_USERNAME']
em = os.environ['DEPLOY_SUPERUSER_EMAIL']
pw = os.environ['DEPLOY_SUPERUSER_PASSWORD']
script = """from django.contrib.auth.models import User;
User.objects.create_superuser('{}', '{}', '{}')""".format(un, em, pw)
User.objects.create_superuser('{}', '{}', '{}')""".format(DEPLOY_SUPERUSER_USERNAME, DEPLOY_SUPERUSER_EMAIL, DEPLOY_SUPERUSER_PASSWORD)
with cd(DEPLOY_TARGET):
run_str = 'source {}/{}/bin/activate && echo "{}" | python manage.py shell'
run(run_str.format(DEPLOY_VENV_PATH, DEPLOY_VENV_NAME, script), shell='/bin/bash')
Expand Down Expand Up @@ -175,9 +172,9 @@ def update_repo():
def export_legacy_json():
"""Dump, compress and download legacy PRS data to JSON fixtures for import to PRS2.
"""
EXPORT_VENV_PATH = os.environ['EXPORT_VENV_PATH']
EXPORT_VENV_NAME = os.environ['EXPORT_VENV_NAME']
EXPORT_TARGET = os.environ['EXPORT_TARGET']
EXPORT_VENV_PATH = env('EXPORT_VENV_PATH', '')
EXPORT_VENV_NAME = env('EXPORT_VENV_NAME', 'venv')
EXPORT_TARGET = env('EXPORT_TARGET', '')

models = [
('auth.Group', 'auth_group.json'),
Expand Down
91 changes: 91 additions & 0 deletions prs2/referral/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import, print_function, unicode_literals
from datetime import date
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import Client
Expand Down Expand Up @@ -561,3 +562,93 @@ def test_get(self):
self.assertEquals(response.status_code, 200)
self.assertTrue(self.ref_tagged in response.context['object_list'])
self.assertFalse(self.ref_untagged in response.context['object_list'])


class TaskActionTest(PrsViewsTestCase):

def setUp(self):
super(TaskActionTest, self).setUp()
self.task = Task.objects.all()[0]

def test_get_update(self):
"""Test the Task update view responds
"""
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'update'})
response = self.client.get(url)
self.assertEquals(response.status_code, 200)

def test_cant_update_stopped_task(self):
"""Test that a stopped task can't be updated
"""
self.task.stop_date = date.today()
self.task.save()
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'update'})
response = self.client.get(url)
# Response should be a redirect to the object URL.
self.assertRedirects(response, self.task.get_absolute_url())
# Test that the redirected response contains an error message.
response = self.client.get(url, follow=True)
messages = response.context['messages']._get()[0]
self.assertIsNot(messages[0].message.find("You can't edit a stopped task"), -1)

def test_cant_stop_completed_task(self):
"""Test that a completed task can't be stopped
"""
self.task.complete_date = date.today()
self.task.save()
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'stop'})
response = self.client.get(url)
# Response should be a redirect to the object URL.
self.assertRedirects(response, self.task.get_absolute_url())
# Test that the redirected response contains an error message.
response = self.client.get(url, follow=True)
messages = response.context['messages']._get()[0]
self.assertIsNot(messages[0].message.find("You can't stop a completed task"), -1)

def test_cant_restart_unstopped_task(self):
"""Test that a non-stopped task can't be started
"""
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'start'})
response = self.client.get(url)
# Response should be a redirect to the object URL.
self.assertRedirects(response, self.task.get_absolute_url())
# Test that the redirected response contains an error message.
response = self.client.get(url, follow=True)
messages = response.context['messages']._get()[0]
self.assertIsNot(messages[0].message.find("You can't restart a non-stopped task"), -1)

def test_cant_inherit_owned_task_task(self):
"""Test that you can't inherit a task assigned to you
"""
self.task.assigned_user = self.n_user
self.task.save()
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'inherit'})
response = self.client.get(url)
# Response should be a redirect to the object URL.
self.assertRedirects(response, self.task.get_absolute_url())
# Test that the redirected response contains an error message.
response = self.client.get(url, follow=True)
messages = response.context['messages']._get()[0]
self.assertIsNot(messages[0].message.find("That task is already assigned to you"), -1)

def test_cant_cancel_completed_task(self):
"""Test that a completed task can't be cancelled
"""
self.task.complete_date = date.today()
self.task.save()
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'cancel'})
response = self.client.get(url)
# Response should be a redirect to the object URL.
self.assertRedirects(response, self.task.get_absolute_url())
# Test that the redirected response contains an error message.
response = self.client.get(url, follow=True)
messages = response.context['messages']._get()[0]
self.assertIsNot(messages[0].message.find('That task is already completed'), -1)

def test_cant_add_task_to_task(self):
"""Test that a task can't be added to another task
"""
url = reverse('task_action', kwargs={'pk': self.task.pk, 'action': 'add'})
response = self.client.get(url)
# Response should be a redirect to the object URL.
self.assertRedirects(response, self.task.get_absolute_url())
6 changes: 3 additions & 3 deletions prs2/referral/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ def get(self, request, *args, **kwargs):
messages.error(request, "You can't restart a non-stopped task!")
return redirect(task.get_absolute_url())
if action == 'inherit' and task.assigned_user == request.user:
messages.info(request, 'That task is already assigned to you.')
return redirect(task.get_absolute_url())
if action == 'complete' and task.complete_date:
return redirect(task.get_absolute_url())
if action == 'cancel' and task.complete_date:
if action in ['complete', 'cancel'] and task.complete_date:
messages.info(request, 'That task is already completed.')
return redirect(task.get_absolute_url())
# We can't (yet) add a task to a task.
if action == 'add':
Expand Down
Loading