-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for multiform with 2 forms of the same type
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Feature: ProfileFormView | ||
A demo view for illustrating how to use a MultiModelFormView where two of the forms are of the | ||
same form type | ||
|
||
Scenario: A user creates a profile | ||
Given that a user fills in the profile form with valid input | ||
When the user submits the profile form | ||
Then a Profile and 2 unique Photo instance are created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pylint: disable=function-redefined, no-name-in-module, import-error | ||
from behave import given | ||
from behave import then | ||
from behave import when | ||
|
||
from base.models import Photo, Profile | ||
|
||
|
||
@given('that a user fills in the profile form with valid input') | ||
def step_impl(context): | ||
context.browser.visit(context.get_url('profiles_new')) | ||
context.browser.fill('name', 'lando calrissian') | ||
context.browser.attach_file('avatar-image', 'test.png') | ||
context.browser.choose('avatar-tag', Photo.UNKNOWN) | ||
context.browser.attach_file('background-image', 'test1.ico') | ||
context.browser.choose('background-tag', Photo.PLANT) | ||
|
||
@when('the user submits the profile form') | ||
def step_impl(context): | ||
context.browser.find_by_css('input[type=submit]').first.click() | ||
|
||
@then('a Profile and 2 unique Photo instance are created') | ||
def step_impl(context): | ||
assert Photo.objects.count() == 2 | ||
assert Profile.objects.count() == 1 | ||
|
||
# TODO: compare hash of image contents instead of name | ||
photo1 = Photo.objects.order_by('created_at').first().image.name | ||
assert photo1 == './test.png' or photo1 == './test1.ico' | ||
photo2 = Photo.objects.order_by('created_at').last().image.name | ||
assert photo2 == './test.png' or photo2 == './test1.ico' | ||
assert photo1 != photo2 |