Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/webapp/features/researcher_adds_images_to_options.py
blob: b651c50fc9591111a463616d125d67b33aacd242 (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
import os

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

from steps import click_on


@step(u'create a new poll "([^"]*)"')
def create_a_new_poll_poll_name(step, poll_name):
    b = world.browser
    click_on(b, "polls")
    click_on(b, "new_poll")
    b.fill("name", poll_name)
    click_on(b, "save")
    assert_true(b.is_text_present("guardada correctamente"))


@step(u'add a group "([^"]*)"')
def add_a_group_name(step, group_name):
    b = world.browser
    click_on(b, "group_add")
    b.fill("groups.0.name", group_name)


@step(u'add a question "([^"]*)" as "([^"]*)"')
def add_a_question_as_question_type(step, question, question_type):
    b = world.browser
    button = b.find_by_xpath('//*[@id="WGroupContainer"]/div/legend/button[2]')
    button.click()
    b.fill("groups.0.fields.0.name", question)
    b.select("groups.0.fields.0.widget_type", question_type)


@step(u'And add a option "([^"]*)" with weight "([^"]*)" and image "([^"]*)"')
def add_option_with_weight_and_image(step, option, weight, image):
    b = world.browser
    fixtures_path = world.fixtures_path
    img_path = os.path.join(fixtures_path, image)

    add_option = b.find_by_xpath(
        '//*[@id="WGroupContainer"]/div/fieldset/div/div[3]/div[1]/div/button')
    add_option.click()

    p = '//*[@id="WGroupContainer"]/div/fieldset/div/div[4]/div/div/label/span'
    opt_id = b.find_by_xpath(p).text
    b.fill('groups.0.fields.0.options.{id}.text'.format(id=opt_id), option)
    b.fill('groups.0.fields.0.options.{id}.weight'.format(id=opt_id), weight)
    input_ = 'groups.0.fields.0.options.{id}.img'.format(id=opt_id)
    script = """
        a = $('input[name="{name}"]');
        span = a.parent('span');$(span).removeClass('btn-file');
        """.format(name=input_)
    b.execute_script(script)
    b.attach_file(input_, img_path)


@step(u'And an image is in option "([^"]*)"')
def image_is_in_option(step, option):
    b = world.browser
    p = '//*[@id="WGroupContainer"]/div/fieldset/div/div[5]/div/div/label/span'
    opt_id = b.find_by_xpath(p).text
    imgs = b.find_by_tag('img') if b.find_by_tag('img') else []
    filtered_imgs = []
    for img in imgs:
        if img['img_src'] and (opt_id in img['img_src']):
            filtered_imgs.append(img)
    assert_equals(1, len(filtered_imgs))