Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/webapp/features/upload_poll_result.py
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/webapp/features/upload_poll_result.py')
-rw-r--r--webapp/webapp/features/upload_poll_result.py60
1 files changed, 45 insertions, 15 deletions
diff --git a/webapp/webapp/features/upload_poll_result.py b/webapp/webapp/features/upload_poll_result.py
index dc15c42..1ed2650 100644
--- a/webapp/webapp/features/upload_poll_result.py
+++ b/webapp/webapp/features/upload_poll_result.py
@@ -1,29 +1,59 @@
# -*- coding: utf-8 -*-
+import os
+
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)
+from polls.models import Poll, PollResultFile
@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)
+ fixtures_path = world.fixtures_path
+ file_path = os.path.join(fixtures_path, file_name)
+ rf = PollResultFile(file_path)
+ assert_equals(pollster_username, rf.get_pollster_username())
-@step(u'And I upload "([^"]*)" on "([^"]*)"')
-def upload_file_name_on_time_string(step, file_name, time_string):
- b = world.browser
+def get_result_file_path_from_fixture(file_name):
+ fixtures_path = world.fixtures_path
+ result_file_path = os.path.join(fixtures_path, file_name)
+ return result_file_path
+
+
+def load_file(browser, file_name, position=1):
+ b = browser
+ poll_result_path = get_result_file_path_from_fixture(file_name)
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()
+ input_xpath = "(//input[@name='result'])[{0}]".format(str(position))
+ file_input = b.find_by_xpath(input_xpath).first
+ file_input.type(poll_result_path)
+
+
+def click_on_by_xpath(browser, xpath):
+ b = browser
+ b.find_by_xpath(xpath).click()
+
+
+@step(u'And I load "([^"]*)" on position "([^"]*)"')
+def load_file_name(step, file_name, position):
+ b = world.browser
+ load_file(b, file_name, position)
+
+
+@step(u'When I upload loaded files')
+def when_i_upload_loaded_files(step):
+ b = world.browser
+ xpath = '/html/body/div/div[2]/form/div[1]/div/button'
+ click_on_by_xpath(b, xpath)
+
+
+@step(u'I upload "([^"]*)"')
+def upload_file_name(step, file_name):
+ b = world.browser
+ load_file(b, file_name)
+ xpath = '/html/body/div/div[2]/form/div[1]/div/button'
+ click_on_by_xpath(b, xpath)
@step(u'Then I should see a message that says "([^"]*)" and "([^"]*)"')