Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/webapp/features/upload_poll_result.py
blob: 1ed2650d177627837cb190ac09fc2cdfa53b8c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
import os

from lettuce import step, world
from nose.tools import assert_true, assert_equals

from polls.models import Poll, PollResultFile


@step(u'And "([^"]*)" is authored by "([^"]*)"')
def result_file_is_authored_by_pollster(step, file_name, pollster_username):
    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())


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()
    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 "([^"]*)"')
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())