Skip to content

Commit d7e97e1

Browse files
committed
add test for multiform with 2 forms of the same type
1 parent e3fdec1 commit d7e97e1

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

features/profile_form_view.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: ProfileFormView
2+
A demo view for illustrating how to use a MultiModelFormView where two of the forms are of the
3+
same form type
4+
5+
Scenario: A user creates a profile
6+
Given that a user fills in the profile form with valid input
7+
When the user submits the profile form
8+
Then a Profile and 2 unique Photo instance are created
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pylint: disable=function-redefined, no-name-in-module, import-error
2+
from behave import given
3+
from behave import then
4+
from behave import when
5+
6+
from base.models import Photo, Profile
7+
8+
9+
@given('that a user fills in the profile form with valid input')
10+
def step_impl(context):
11+
context.browser.visit(context.get_url('profiles_new'))
12+
context.browser.fill('name', 'lando calrissian')
13+
context.browser.attach_file('avatar-image', 'test.png')
14+
context.browser.choose('avatar-tag', Photo.UNKNOWN)
15+
context.browser.attach_file('background-image', 'test1.ico')
16+
context.browser.choose('background-tag', Photo.PLANT)
17+
18+
@when('the user submits the profile form')
19+
def step_impl(context):
20+
context.browser.find_by_css('input[type=submit]').first.click()
21+
22+
@then('a Profile and 2 unique Photo instance are created')
23+
def step_impl(context):
24+
assert Photo.objects.count() == 2
25+
assert Profile.objects.count() == 1
26+
27+
# TODO: compare hash of image contents instead of name
28+
photo1 = Photo.objects.order_by('created_at').first().image.name
29+
assert photo1 == './test.png' or photo1 == './test1.ico'
30+
photo2 = Photo.objects.order_by('created_at').last().image.name
31+
assert photo2 == './test.png' or photo2 == './test1.ico'
32+
assert photo1 != photo2

test1.ico

6.37 KB
Binary file not shown.

0 commit comments

Comments
 (0)