|
| 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 |
0 commit comments