Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #9 from SexualHealthInnovations/reenable-edit-tests-6
Browse files Browse the repository at this point in the history
re-enable edit tests
  • Loading branch information
Kelsey Gilmore-Innis authored Jul 15, 2016
2 parents 3b8a881 + 80de4b0 commit 069784c
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 204 deletions.
30 changes: 30 additions & 0 deletions makemigrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

def make_migrations():
from django.core.management import call_command
call_command('makemigrations', 'test_app')


if __name__ == '__main__':
import sys
sys.path.append('./src/')

try:
from django.conf import settings

settings.configure(
INSTALLED_APPS=[
'django.contrib.contenttypes',
'wizard_builder',
'tests.test_app'
],
)

import django
django.setup()

except ImportError:
import traceback
traceback.print_exc()
raise ImportError('To fix this error, sort out the imports')

make_migrations()
21 changes: 1 addition & 20 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,7 @@
from django.conf import settings
from django.test.utils import get_runner

settings.configure(
DEBUG=True,
USE_TZ=True,
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3",
}
},
ROOT_URLCONF="tests.urls",
INSTALLED_APPS=[
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"wizard_builder",
],
SITE_ID=1,
MIDDLEWARE_CLASSES=('django.contrib.sessions.middleware.SessionMiddleware',),
TEMPLATE_DIRS=['%s/tests/templates' % os.path.abspath(os.path.dirname(__file__))]
)
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'

try:
import django
Expand Down
4 changes: 0 additions & 4 deletions tests/models.py

This file was deleted.

30 changes: 30 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

DEBUG = True

USE_TZ = True

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
}
}

ROOT_URLCONF = "tests.urls"

INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"wizard_builder",
"tests.test_app"
]

SITE_ID = 1

MIDDLEWARE_CLASSES = ('django.contrib.sessions.middleware.SessionMiddleware',)

TEMPLATE_DIRS = ['%s/test_app/templates' % os.path.abspath(os.path.dirname(__file__))]

SECRET_KEY = "not important"
Empty file added tests/test_app/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions tests/test_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-07-13 14:08
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Report',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField()),
],
),
]
Empty file.
6 changes: 6 additions & 0 deletions tests/test_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.db import models


class Report(models.Model):

text = models.TextField(blank=False, null=False)
28 changes: 16 additions & 12 deletions tests/views.py → tests/test_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

from wizard_builder.views import ConfigurableFormWizard

# from .models import Report
from django.http import HttpResponse

from .models import Report


class TestWizard(ConfigurableFormWizard):
# def get_form_to_edit(self, object_to_edit):
# self.form_to_edit = object_to_edit.text

def get_form_to_edit(self, object_to_edit):
if object_to_edit:
return json.loads(object_to_edit.text)
else:
return super(TestWizard, self).get_form_to_edit(object_to_edit)

def done(self, form_list, **kwargs):
# report = Report()
# if self.object_to_edit:
# report = self.object_to_edit
# report.text = self.processed_answers
# report.save()
report = Report()
if self.object_to_edit:
report = self.object_to_edit
report.text = self.processed_answers
report.save()
return HttpResponse(json.dumps(self.processed_answers))


Expand All @@ -24,9 +29,8 @@ def new_test_wizard_view(request, step=None):
step=step)


def edit_test_wizard_view(request, report_id, step=None):
# report = Report.objects.get(id=report_id)
report = None
return TestWizard.wizard_factory(object_to_edit=report).as_view(url_name="test_wizard",
def edit_test_wizard_view(request, edit_id, step=None):
report = Report.objects.get(id=edit_id)
return TestWizard.wizard_factory(object_to_edit=report).as_view(url_name="test_edit_wizard",
template_name='wizard_form.html')(request,
step=step)
6 changes: 6 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


class PageTest(TestCase):

def test_page_can_have_position(self):
page = QuestionPage.objects.create(position=10)
self.assertEqual(QuestionPage.objects.get(pk=page.pk).position, 10)
Expand Down Expand Up @@ -39,6 +40,7 @@ def test_page_infobox_can_be_specified(self):


class ItemTestCase(TestCase):

def setUp(self):
self.page = QuestionPage.objects.create()

Expand Down Expand Up @@ -200,6 +202,7 @@ def test_serializes_correctly(self):


class CheckboxTestCase(ItemTestCase):

def setUp(self):
self.page = QuestionPage.objects.create()
self.question = Checkbox.objects.create(text="this is a checkbox question")
Expand Down Expand Up @@ -240,6 +243,7 @@ def test_serializes_correctly(self):


class DateTestCase(ItemTestCase):

def test_make_field_is_text_input(self):
question = Date.objects.create(text="When did it happen?").make_field()
self.assertIsInstance(question.widget, forms.TextInput)
Expand All @@ -259,6 +263,7 @@ def test_serializes_correctly(self):


class QuestionPageTest(TestCase):

def test_can_save_encouragement(self):
page_id = QuestionPage.objects.create(encouragement="you can do it!").pk
self.assertEqual(QuestionPage.objects.get(pk=page_id).encouragement, "you can do it!")
Expand All @@ -269,6 +274,7 @@ def test_can_save_infobox(self):


class TextPageTest(TestCase):

def test_can_save_with_or_without_title(self):
without_title = TextPage.objects.create(text="here's some instructions")
with_title = TextPage.objects.create(title="This Page's Title", text="more instructions")
Expand Down
Loading

0 comments on commit 069784c

Please sign in to comment.