Skip to content
Snippets Groups Projects
Commit 34af2649 authored by Martin Burchell's avatar Martin Burchell
Browse files

Changed tests to create actual item in database

parent 11a53d64
No related branches found
No related tags found
1 merge request!37Items can be edited when form is submitted
......@@ -4,7 +4,9 @@ from django.contrib import messages
from django.core.urlresolvers import reverse
from django.test import RequestFactory
import transport
from ..views.item import AddEditItemView
from .views_tests import (
assert_message,
fix_messages,
......@@ -12,12 +14,16 @@ from .views_tests import (
@pytest.fixture
def item():
return {'id': "1234"}
msg = {'body': "What is the cuse of Ebola?"}
response = transport.items.create(msg)
return response
@pytest.fixture
def view(item):
view = AddEditItemView()
view.item = item
url = reverse('item-edit',
kwargs={'item_id': item['id']})
......@@ -37,12 +43,12 @@ def form(view):
@pytest.mark.django_db
def test_item_update_logs_message_and_redirects(view, form, item):
def test_item_update_logs_message_and_redirects(view, form):
view.item_type = {'long_name': 'Question'}
form.cleaned_data = {
'next': '/',
'id': item['id'],
'id': view.item['id'],
}
response = view.form_valid(form)
......@@ -50,20 +56,28 @@ def test_item_update_logs_message_and_redirects(view, form, item):
assert_message(view.request,
messages.SUCCESS,
"Question 1234 successfully updated.")
"Question %s successfully updated." % view.item['id'])
@pytest.mark.django_db
def test_item_update_without_type_logs_message(view, form, item):
def test_item_update_without_type_logs_message(view, form):
view.item_type = None
form.cleaned_data = {
'next': '/',
'id': item['id'],
'id': view.item['id'],
}
view.form_valid(form)
assert_message(view.request,
messages.SUCCESS,
"Item %s successfully updated." % item['id'])
"Item %s successfully updated." % view.item['id'])
@pytest.mark.django_db
def test_no_category_when_item_type_not_set(view):
view.item_type = None
initial = view.get_initial()
assert 'category' not in initial
......@@ -88,10 +88,12 @@ class AddEditItemView(FormView):
'timestamp': self.item['timestamp'],
'next': self.request.GET.get('next', self.request.path)
}
taxonomy = ITEM_TYPE_CATEGORY.get(self.item_type['name'])
if (taxonomy and taxonomy in self.item_terms
and len(self.item_terms[taxonomy]) > 0):
initial['category'] = self.item_terms[taxonomy][0]['name']
item_type = getattr(self, 'item_type', None)
if item_type is not None:
taxonomy = ITEM_TYPE_CATEGORY.get(item_type['name'])
if (taxonomy and taxonomy in self.item_terms and len(self.item_terms[taxonomy]) > 0):
initial['category'] = self.item_terms[taxonomy][0]['name']
return initial
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment