Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
34af2649
Commit
34af2649
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Changed tests to create actual item in database
parent
11a53d64
No related branches found
No related tags found
1 merge request
!37
Items can be edited when form is submitted
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/hid/tests/add_edit_item_view_tests.py
+21
-7
21 additions, 7 deletions
django/website/hid/tests/add_edit_item_view_tests.py
django/website/hid/views/item.py
+6
-4
6 additions, 4 deletions
django/website/hid/views/item.py
with
27 additions
and
11 deletions
django/website/hid/tests/add_edit_item_view_tests.py
+
21
−
7
View file @
34af2649
...
...
@@ -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
This diff is collapsed.
Click to expand it.
django/website/hid/views/item.py
+
6
−
4
View file @
34af2649
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment