# -*- coding: utf-8 -*- from lettuce import step, world from nose.tools import assert_true, assert_equals from polls.models import Poll from poll_result_details import (create_poll_result_file, get_pollster_by_username) @step(u'And "([^"]*)" is authored by "([^"]*)"') def result_file_is_authored_by_pollster(step, file_name, pollster_username): pollster = get_pollster_by_username(pollster_username) data = {} data['poll_id'] = world.poll_id.__str__() data['pollster_username'] = pollster.username data['pollster_id'] = pollster.id.__str__() data['result'] = {} world.poll_result_path = create_poll_result_file(data, file_name) @step(u'And I upload "([^"]*)" on "([^"]*)"') def upload_file_name_on_time_string(step, file_name, time_string): b = world.browser b.find_by_xpath('/html/body/div/div[2]/form/fieldset/div/button').click() b.attach_file('result', world.poll_result_path) b.find_by_xpath('/html/body/div/div[2]/form/div[1]/div/button').click() @step(u'Then I should see a message that says "([^"]*)" and "([^"]*)"') def i_should_see_a_message_that_says_text1_and_text2(step, text1, text2): b = world.browser assert_true(b.is_text_present(text1)) assert_true(b.is_text_present(text2)) @step(u'And "([^"]*)" has the time string "([^"]*)"') def file_name_has_the_time_string_time_string(step, file_name, time_string): poll = Poll.get(world.poll_id) result_files = poll.get_result_files() result_file = filter( lambda f: file_name == f.get_file_name(), result_files)[0] # Using (mock) Clock class from django settings assert_equals(time_string, result_file.get_upload_timestamp())