Skip to content

Commit

Permalink
add test for multiform with 2 forms of the same type
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBest committed Sep 14, 2017
1 parent e3fdec1 commit d7e97e1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions features/profile_form_view.feature
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
32 changes: 32 additions & 0 deletions features/steps/profile_form_view.py
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
Binary file added test1.ico
Binary file not shown.

0 comments on commit d7e97e1

Please sign in to comment.