コード例 #1
0
import pytest
from pytest_bdd import parsers
from pytest_bdd import given, when, then, scenarios
from boofuzz import helpers
from boofuzz import ip_constants


scenarios('helpers_udp_checksum.feature')


@given('Empty msg')
def msg_empty(context):
    context.msg = b''


@given(parsers.cfparse('msg {msg}'))
def msg_1_byte(context, msg):
    context.msg = ast.literal_eval(msg)


@given('msg with 60 bytes')
def msg_60_bytes(context):
    # Use each bit at least once...
    all_16_bits = b'\x00\x01\x00\x02\x00\x04\x00\x08\x00\x10\x00\x20\x00\x40\x00\x80' + \
                  b'\x01\x00\x02\x00\x04\x00\x08\x00\x10\x00\x20\x00\x40\x00\x80\x00'
    # Then fill the remaining bytes.
    # Note that using all FF bytes causes a boring pattern, since FFFF + FFFF
    # with carry is just FFFF again. 0x8001 adds just a little bit at a time,
    # hopefully ensuring that all bytes are actually factored into the answer.
    filler = b'\x80\x01' * ((60 - len(all_16_bits)) // 2)
    context.msg = all_16_bits + filler
コード例 #2
0
ファイル: test_persons.py プロジェクト: brianmay/spud
@when('we delete a person called <name>')
def step_delete_person(session, persons, name):
    desired_person = models.person.objects.get(first_name=name)

    url = "/api/persons/%d/" % desired_person.id
    session.delete(url)


@when('we list all persons')
def step_list_persons(session, persons):
    url = "/api/persons/"
    session.get(url)


@then(parsers.cfparse(
    'the person <name> notes should be {notes}'))
def step_test_person_notes(name, notes):
    person = models.person.objects.get(first_name=name)
    assert person.notes == notes


@then('the person called <name> should exist')
def step_test_person_valid(name):
    models.person.objects.get(first_name=name)


@then('the person called <name> should not exist')
def step_test_person_not_exist(name):
    with pytest.raises(models.person.DoesNotExist):
        models.person.objects.get(first_name=name)
コード例 #3
0
from ldap3.core import exceptions
import pytest
from pytest_bdd import scenarios, when, then, parsers

import tldap.database
from tldap import Q
from tldap.django.models import Counters
from tldap.exceptions import ObjectDoesNotExist
from tests.database import Group

scenarios('groups.feature')


@when(parsers.cfparse('we create a group called {name}'))
def step_create_group(ldap, name):
    """ Test if we can create a group. """
    group = Group({
        'cn': name,
        'gidNumber': 10,
        'memberUid': [],
    })
    tldap.database.insert(group)


@when(parsers.cfparse('we modify a group called {name}'))
def step_modify_group(ldap, name):
    """ Test if we can modify a group. """
    group = tldap.database.get_one(Group, Q(cn=name))
    changes = tldap.database.changeset(group, {'gidNumber': 11})
    tldap.database.save(changes)
    group = tldap.database.get_one(Group, Q(cn=name))
コード例 #4
0
import pytest
from pytest_bdd import parsers, scenarios, given, when, then

from salty import Shaker

scenarios('../features/serving.feature')


@given(parsers.cfparse("A Salt Shaker with {doses:d} doses"))
def salt_shaker(doses):
    yield Shaker(doses)


@pytest.fixture
@when("I shake it once")
def served(salt_shaker):
    yield salt_shaker.shake()


@then(parsers.cfparse("{expected_served:d} salt dose falls on my plate"))
def served_doses(served, expected_served):
    assert served == expected_served


@then("It's empty!")
def its_empty(salt_shaker):
    assert salt_shaker.remaining == 0
コード例 #5
0

@when('the user changes the <color> of the device')
def the_user_changes_the_color_of_the_device(color):
    """the user changes the <color> of the device."""
    web_app.change_property_softassert("color",color)


@when('the user changes the <name> of the device')
def the_user_changes_the_name_of_the_device(name):
    """the user changes the <name> of the device."""
    web_app.change_property_softassert("name",name)



@when(parsers.cfparse('the user changes the brightness to "{n}"'))
def the_user_changes_the_brightness_to(n):
    """the user changes the brightness to "5"."""
    print("Changing brightness to "+ str(n) +"...")
    web_app.change_property_softassert("brightness",n)


@when('the user disconnect the device and re-connect again to the same device')
def the_user_disconnect_the_device_and_reconnect_again_to_the_same_device():
    """the user disconnect the device and re-connect again to the same device."""
    assert web_app.disconnect_from_device()
    assert web_app.connect_to_device1()



コード例 #6
0
from pytest_bdd import scenario, given, when, then, scenarios, parsers
from tango import Database, DeviceProxy, CmdArgType as ArgType # type: ignore
from time import sleep
import requests
import json
import sys
import logging
import pytest

@given(parsers.parse("a device called {device_name}"), target_fixture='device_proxy')
def device_proxy(run_context, device_name):
  return DeviceProxy(device_name)

@pytest.fixture
@when(parsers.cfparse("I call the command {command_name}({parameter:String?})", extra_types=dict(String=str)))
def call_command(device_proxy, command_name, parameter):
  if parameter is None:
    return device_proxy.command_inout(command_name)
  else:
    command_info = device_proxy.command_query(command_name)
    # {0: tango._tango.CmdArgType.DevVoid,
    #  1: tango._tango.CmdArgType.DevBoolean,*
    #  2: tango._tango.CmdArgType.DevShort,*
    #  3: tango._tango.CmdArgType.DevLong,*
    #  4: tango._tango.CmdArgType.DevFloat,*
    #  5: tango._tango.CmdArgType.DevDouble,*
    #  6: tango._tango.CmdArgType.DevUShort,*
    #  7: tango._tango.CmdArgType.DevULong,*
    #  8: tango._tango.CmdArgType.DevString,*
    #  9: tango._tango.CmdArgType.DevVarCharArray,
コード例 #7
0
ファイル: test_feedbacks.py プロジェクト: brianmay/spud
@when('we delete a feedback with photo <photo_name>')
def step_delete_feedback(session, photos, feedbacks, photo_name):
    photo = photos[photo_name]
    feedback = models.feedback.objects.get(cover_photo=photo)
    url = "/api/feedbacks/%d/" % int(feedback.pk)
    session.delete(url)


@when('we list all feedbacks')
def step_list_feedbacks(session, feedbacks):
    url = "/api/feedbacks/"
    session.get(url)


@then(parsers.cfparse(
    'the feedback <photo_name> comment should be {comment}'))
def step_test_feedback_comment(photos, photo_name, comment):
    photo = photos[photo_name]
    feedback = models.feedback.objects.get(cover_photo=photo)
    assert feedback.comment == comment


@then('the feedback with photo <photo_name> should exist')
def step_test_feedback_valid(photos, photo_name):
    photo = photos[photo_name]
    models.feedback.objects.get(cover_photo=photo)


@then('the feedback with photo <photo_name> should not exist')
def step_test_feedback_not_exist(photos, photo_name):
    photo = photos[photo_name]
コード例 #8
0
@pytest.fixture()
def basket4():
    return Basket(2)


scenarios('../features/paramater_test.feature')
# @pytest.mark.test_param_add
# @scenario('../features/paramater_test.feature', 'Add items to the Basket')
# def test_add_items_to_the_basket():
#     """Add items to the Basket."""
#     pass


@given(
    parsers.cfparse('The Basket has "{initial:Number}" items',
                    extra_types=EXTRA_TYPE))
#given('The Basket has "2" items')
def the_basket_has_2_items(initial):
    """The Basket has "2" items."""
    return Basket(initial)


@when(
    parsers.cfparse('"{some:Number}" items are added in to Basket',
                    extra_types=EXTRA_TYPE))
def items_are_added_in_to_basket(basket4, some):
    """"4" items are added in to Basket."""
    basket4.addItem(some)


@then(
コード例 #9
0
)
import pytest


@pytest.fixture()
def basket4():
    return Basket(2)


@pytest.mark.test_param_add
@scenario('../features/paramater_test.feature', 'Add items to the Basket')
def test_add_items_to_the_basket():
    """Add items to the Basket."""
    pass

@given(parsers.cfparse('The Basket has "{initial:Number}" items',extra_types=dict(Number=int)))
#given('The Basket has "2" items')
def the_basket_has_2_items(initial):
    """The Basket has "2" items."""
    return Basket(initial)


@when(parsers.cfparse('"{some:Number}" items are added in to Basket',extra_types=dict(Number=int)))
def items_are_added_in_to_basket(basket4,some):
    """"4" items are added in to Basket."""
    basket4.addItem(some)


@then(parsers.cfparse('The Basket contains in "{final:Number}" Basket',extra_types=dict(Number=int)))
def the_basket_contains_in_6_basket(basket4,final):
    """The Basket contains in "6" Basket."""
コード例 #10
0
ファイル: test_categorys.py プロジェクト: brianmay/spud
@when('we delete a category called <name>')
def step_delete_category(session, categorys, name):
    desired_category = models.category.objects.get(title=name)

    url = "/api/categorys/%d/" % desired_category.id
    session.delete(url)


@when('we list all categorys')
def step_list_categorys(session, categorys):
    url = "/api/categorys/"
    session.get(url)


@then(parsers.cfparse(
    'the category <name> description should be {description}'))
def step_test_category_description(name, description):
    category = models.category.objects.get(title=name)
    assert category.description == description


@then('the category called <name> should exist')
def step_test_category_valid(name):
    models.category.objects.get(title=name)


@then('the category called <name> should not exist')
def step_test_category_not_exist(name):
    with pytest.raises(models.category.DoesNotExist):
        models.category.objects.get(title=name)
コード例 #11
0

@scenario('TestCases/claim_add.feature', 'Verify that user can add new claim')
def test_verify_that_user_can_add_new_claim():
    """Verify that user can add claim - 2."""


@given('User is on Avatar Insurance Login Page')
def user_is_on_avatar_insurance_login_page():
    avatarLoginPage.open_avatar()
    print("User navigated to Home Page")
    """User is on Avatar Insurance Login Page."""
    #raise NotImplementedError


@when(parsers.cfparse("User logs in with user '{user}'"))
def click_on_login_btn(user):
    avatarLoginPage.login(user)
    print("User clicked on item")


@when("User clicks on claim in top navigation bar")
def click_on_claim_in_top_navigation_bar():
    avatarTopNavBar.click_on_claims()


@when('User clicks Add Claim button')
def user_clicks_on_update_claim_button():
    """User clicks on Update Claim button."""
    avatarClaimsHomepage.click_add_button()
    time.sleep(10)
コード例 #12
0
ファイル: test_photos.py プロジェクト: brianmay/spud
@when('we delete a photo called <name>')
def step_delete_photo(session, photos, name):
    desired_photo = models.photo.objects.get(title=name)

    url = "/api/photos/%d/" % desired_photo.id
    session.delete(url)


@when('we list all photos')
def step_list_photos(session, photos):
    url = "/api/photos/"
    session.get(url)


@then(parsers.cfparse(
    'the photo <name> description should be {description}'))
def step_test_photo_description(name, description):
    photo = models.photo.objects.get(title=name)
    assert photo.description == description


@then('the photo called <name> should exist')
def step_test_photo_valid(name):
    models.photo.objects.get(title=name)


@then('the photo called <name> should not exist')
def step_test_photo_not_exist(name):
    with pytest.raises(models.photo.DoesNotExist):
        models.photo.objects.get(title=name)
コード例 #13
0
    if action == 'appears on':
        descriptor = create_fake_device(name)
        test_context.add_device_to_network(name, descriptor, notify=True)
    else:
        test_context.remove_device_to_network(name, notify=True)


@when('the client unsubscribes for discovery events')
@sync
async def unsubscribe_discovery_events(event_bus_connection):
    result = await event_bus_connection.send(method='unsubscribe',
                                             params={'category': 'discovery'})
    assert result is True


@then(parsers.cfparse('the client will be notified about the {action} {name}'))
@sync
async def check_device_notification(test_context, event_bus_connection, action,
                                    name):
    action_to_methods = {'new': 'new_device', 'lost': 'device_lost'}
    assert action in action_to_methods
    descriptor = create_fake_device(name)
    event = await event_bus_connection.wait_for_notification()
    assert event.params['udn'] == descriptor.udn
    assert event.method == action_to_methods.get(action)


@then(
    parsers.cfparse(
        'the media server {name} will be in the library API device list'))
@sync
コード例 #14
0
ファイル: test_albums.py プロジェクト: brianmay/spud
@when('we delete an album called <name>')
def step_delete_album(session, albums, name):
    desired_album = models.album.objects.get(title=name)

    url = "/api/albums/%d/" % desired_album.id
    session.delete(url)


@when('we list all albums')
def step_list_albums(session, albums):
    url = "/api/albums/"
    session.get(url)


@then(parsers.cfparse('the album <name> description should be {description}'))
def step_test_album_description(name, description):
    album = models.album.objects.get(title=name)
    assert album.description == description


@then('the album called <name> should exist')
def step_test_album_valid(name):
    models.album.objects.get(title=name)


@then('the album called <name> should not exist')
def step_test_album_not_exist(name):
    with pytest.raises(models.album.DoesNotExist):
        models.album.objects.get(title=name)
コード例 #15
0
from pytest_bdd import scenario, parsers, given, when, then

from cucumbers import CucumberBasket
import pytest


@scenario('cucumber.feature', 'Add cucumbers to a basket')
def test_arguments():
    pass


@given(
    parsers.cfparse('the basket has "{initial:d}" cucumbers',
                    extra_types=dict(d=int)))
def basket(initial):
    return CucumberBasket(initial_count=initial)


@when(
    parsers.cfparse('"{some:d}" cucumbers are added to the basket',
                    extra_types=dict(d=int)))
def add_cucumbers(basket, some):
    basket.add(some)


@then(
    parsers.cfparse('the basket contains "{total:d}" cucumbers',
                    extra_types=dict(d=int)))
def basket_has_total(basket, total):
    assert basket.count == total
コード例 #16
0
    'admin has subscription with id 901 of <object_type> with id 901 as admin-subscription-901'
)
def admin_subscription_with_id_of_an_factory_2(admin, object_type, context):
    create_subscription(admin, object_type, 901, 901, 'admin-subscription-901')


@given(
    'admin has subscription with id 902 of <object_type> with id 902 as admin-subscription-902'
)
def admin_subscription_with_id_of_an_factory_3(admin, object_type, context):
    create_subscription(admin, object_type, 902, 902, 'admin-subscription-902')


@given(
    parsers.cfparse(
        'admin has subscription with id {s_id:d} of {object_type} with id {f_id:d} as {s_name}'
    ))
def admin_subscription_with_id_of_an_factory(admin, s_id, object_type, f_id,
                                             s_name, context):
    create_subscription(admin, object_type, f_id, s_id, s_name)


@given(
    parsers.cfparse(
        'admin has second subscription with id {s_id:d} of {object_type} with id {f_id:d} as {s_name}'
    ))
def second_admin_subscription_with_id_of_an_factory(admin, s_id, object_type,
                                                    f_id, s_name, context):
    create_subscription(admin, object_type, f_id, s_id, s_name)

コード例 #17
0
fake = Faker()

scenarios('../features/ui/register_ui.feature')
STR_EXTRA = {"String": str}
fake_password = fake.name()


@given("the user is on register page")
def step_impl(browser):
    browser.get(SIGNUP_URL)


@when(
    parsers.cfparse(
        'the user enters name "{name:String}" ,username "{username:String}" ,email "{email:String}",password "{password:String}" ,and confirm password "{password_confirm:String}"',
        extra_types=STR_EXTRA))
def send_data(browser, name, username, email, password, password_confirm):
    name_field = browser.find_element_by_name("name")
    username_field = browser.find_element_by_name("username")
    email_field = browser.find_element_by_name("email")
    password_field = browser.find_element_by_name("password")
    password_confirm_field = browser.find_element_by_name("confirmPassword")

    name_field.send_keys(fake.name())
    username_field.send_keys(fake.name())
    email_field.send_keys(fake.email())
    password_field.send_keys(fake_password)
    password_confirm_field.send_keys(fake_password)
    time.sleep(3)
    browser.find_element_by_class_name("register-button").click()
コード例 #18
0
ファイル: test_relations.py プロジェクト: brianmay/spud
    photo_2 = photos[photo_2]
    desired_relation = models.photo_relation.objects.get(
            photo_1=photo_1, photo_2=photo_2)

    url = "/api/relations/%d/" % desired_relation.id
    session.delete(url)


@when('we list all relations')
def step_list_relations(session, relations):
    url = "/api/relations/"
    session.get(url)


@then(parsers.cfparse(
    'the relation between <photo_1> and <photo_2> '
    'description 1 should be {description}'))
def step_test_relation_description_1(photo_1, photo_2, description, photos):
    photo_1 = photos[photo_1]
    photo_2 = photos[photo_2]
    relation = models.photo_relation.objects.get(
            photo_1=photo_1, photo_2=photo_2)
    assert relation.desc_1 == description


@then(parsers.cfparse(
    'the relation between <photo_1> and <photo_2> '
    'description 2 should be {description}'))
def step_test_relation_description_2(photo_1, photo_2, description, photos):
    photo_1 = photos[photo_1]
    photo_2 = photos[photo_2]
コード例 #19
0
@given('I have basic autocomplete control',
       target_fixture='autocomplete_control')
@step
def basic_autocomplete_control(autocomplete_demo_page):
    return autocomplete_demo_page.basic_autocomplete


@when('I start typing <text> in basic autocomplete control')
@step
def start_typing_value_into_basic_autocomplete(basic_autocomplete_control,
                                               text):
    basic_autocomplete_control.value = text


@when('I selected value <value> in autocomplete dropdown')
@when(parsers.cfparse('I selected value \'{value}\' in autocomplete dropdown'))
@step
def select_value_in_basic_autocomplete_dropdown(autocomplete_control, value):
    autocomplete_control.select_value(value)


@then('Autocomplete control value should be <value>')
@then(parsers.cfparse('Autocomplete control value should be \'{value}\''))
@step
def autocomplete_control_value_should_be(autocomplete_control, value, driver):
    allure.attach(driver.get_screenshot_as_png(),
                  name='screenshot',
                  attachment_type=allure.attachment_type.PNG)
    actual_val = autocomplete_control.value
    assert actual_val == value
コード例 #20
0
@scenario("..\\features\\registration.feature",
          'Registration',
          example_converters=exampleConvertors)
def test_registration():
    pass


@when("I click on Account")
@when("I select Register option from dropdown menu")
def click_account(account):
    account.click_account()


@when(
    parsers.cfparse(
        'I enter "{firstname:value}" "{lastname:value}" "{email:value}" "{password:value}""{confirm:value}"',
        extra_types=extraTypes))
@when('I enter "<firstname>" "<lastname>" "<email>" "<password>" "<confirm>"')
def provide_registration_data(account, firstname, lastname, email, password,
                              confirm):
    account.fill_registration(firstname, lastname, email, password, confirm)


@when("I select the checkbox")
def select_checkbox(account):
    account.checkbox()


@when("I click the Register button")
def click_register_button(account):
    account.click_registration_button()
コード例 #21
0
ファイル: test_args.py プロジェクト: PatrickMassot/pytest-bdd
@scenario_when('Argument in when, step 2')
def test_argument_in_when_step_2():
    pass


def test_multiple_given(request):
    """Using the same given fixture raises an error."""
    @scenario_args('Using the same given fixture raises an error')
    def test():
        pass
    with pytest.raises(exceptions.GivenAlreadyUsed):
        test(request)


@given(parsers.cfparse('I have {euro:d} Euro'))
def i_have(euro, values):
    assert euro == values.pop(0)


@when(parsers.cfparse('I pay {euro:d} Euro'))
def i_pay(euro, values, request):
    assert euro == values.pop(0)


@then(parsers.cfparse('I should have {euro:d} Euro'))
def i_should_have(euro, values):
    assert euro == values.pop(0)


@given(parsers.cfparse('I have an argument {arg:Number}', extra_types=dict(Number=int)))
コード例 #22
0
@allure.story("Advanced checkbox on/off, label test")
@scenario('react_controls/checkbox.feature', 'Advanced checkbox on off')
def test_checkbox_advanced():
    pass


# Basic autocomplete steps


@given('I have basic checkbox control', target_fixture='checkbox_control')
@step
def basic_checkbox_control(checkbox_demo_page: CheckboxPage):
    return checkbox_demo_page.first_checkbox


@then(parsers.cfparse('Checkbox checked state should be \'{state}\''))
@step
def checkbox_checked_state_should_be(checkbox_control: ReactCheckbox,
                                     state: str):
    checked = state == 'On'
    assert checkbox_control.checked is checked


@when('I toggle checkbox state')
@step
def i_toggle_checkbox_state(checkbox_control: ReactCheckbox):
    checkbox_control.click()


@when(parsers.cfparse('I set checkbox state to \'{state}\''))
@step
コード例 #23
0
ファイル: test_args.py プロジェクト: zacky131/pytest-bdd
@scenario_when('Argument in when, step 2')
def test_argument_in_when_step_2():
    pass


def test_multiple_given(request):
    """Using the same given fixture raises an error."""
    @scenario_args('Using the same given fixture raises an error')
    def test():
        pass

    with pytest.raises(exceptions.GivenAlreadyUsed):
        test(request)


@given(parsers.cfparse('I have {euro:d} Euro'))
def i_have(euro, values):
    assert euro == values.pop(0)


@when(parsers.cfparse('I pay {euro:d} Euro'))
def i_pay(euro, values, request):
    assert euro == values.pop(0)


@then(parsers.cfparse('I should have {euro:d} Euro'))
def i_should_have(euro, values):
    assert euro == values.pop(0)


@given(
コード例 #24
0
CONVERTERS = {
    'initial_month': int,
    'initial_year': int,
    'years_to_ssa': int,
    'months_to_ssa': int,
    'ssa_month': int,
    'ssa_year': int
}

scenarios('../features/retirement.feature', example_converters=CONVERTERS)


@given(
    parsers.cfparse(
        'the user wants to know date to start receiving full SSA benefits',
        extra_types=EXTRA_TYPES))
@given('the user wants to know date to start receiving full SSA benefits')
def test_user_inputs():
    pass


@when(
    parsers.cfparse('"{initial_year:Number}" year is entered',
                    extra_types=EXTRA_TYPES))
@when('"<initial_year>" year is entered')
def calculate_retirement(initial_year):
    pass


@then(
コード例 #25
0
avatarClaimsHomepage = AvatarClaimsHomepage()
avatartoast = AvatarToastMessages()


@scenario(r'TestCases/producer_add.feature', 'Verify producer add feature')
def test_verify_that_user_can_add_producer():
    print('Scenario--> Verify that user can add producer')


@given("User is on Avatar Insurance Login Page")
def go_to_homepage():
    avatarLoginPage.open_avatar()
    print("User navigated to Home Page")


@when(parsers.cfparse("User logs in with user '{user}'"))
def click_on_login_btn(user):
    avatarLoginPage.login(user)
    print("User clicked on item")


@when("User clicks on producer in top navigation bar")
def click_on_claim_in_top_navigation_bar():
    avatarTopNavBar.click_on_producer()


@when("User clicks on Add Agency")
def click_on_add_agency():
    avatarProducer.click_add_agency()
    time.sleep(5)
コード例 #26
0
@then('user clicks on "Signup" button')
def user_clicks_on_signup_button(browser):
    """user clicks on "Signup" button."""
    time.sleep(5)
    signup = SignupPage(browser)
    signup.click_signup()


@when('user clicks on "Signup" button')
def user_clicks_on_signup_button(browser):
    """user clicks on "Signup" button."""
    signup = SignupPage(browser)
    signup.click_signup()


@then(parsers.cfparse('user verifies "{title}" title is displayed'))
def user_verifies__citi_wealth_builder__investor_profile_title_is_displayed(browser, title):
    """user verifies " Citi Wealth Builder - Investor Profile" title is displayed."""
    assert title == browser.title


@then(parsers.cfparse('user verifies "{title}" title is not displayed'))
def user_verifies__citi_wealth_builder__investor_profile_title_is_not_displayed(browser, title):
    """user verifies " Citi Wealth Builder - Investor Profile" title is not displayed."""
    assert title != browser.title


@then(parsers.cfparse('user sees page title as "{title}"'))
def user_sees_page_title_as_citi_wealth_builder__investor_profile(browser, title):
    """user sees page title as "Citi Wealth Builder - Investor Profile"."""
    assert title == browser.title
コード例 #27
0
import sys

from pytest_bdd import scenario, parsers, given, when, then

sys.path.append("C://Users//tibi//Documents//tau-pytest-bdd//tests//cucumbers.py")
from cucumbers import CucumberBasket

@scenario("../feature/cucumbers.feature","Add cucumbers to a basket")
EXTRA_TYPES = {
    'Number' : int,
}
def test_add():
    pass


@given(parsers.cfparse('the basket has "{initial:Number}" cucumbers', extra_types=dict(EXTRA_TYPES)))
def basket(initial):
    return CucumberBasket(initial_count=initial)

@when(parsers.cfparse('they are added "{some:Number}" cucumbers to the basket', extra_types=dict(EXTRA_TYPES)))
def add_cucumbers(basket, some):
    basket.add(some)

@then(parsers.cfparse('the basket has "{total:Number}" cucumbers', extra_types=dict(EXTRA_TYPES)))
def basket_has_total(basket, total):
    assert basket = total


@scenario("../feature/cucumbers.feature" , "Remove cucumbers from a basket")
def test_remove():
    pass
コード例 #28
0
ファイル: test_retirement.py プロジェクト: bin1688/Gherkin
    'year': int,
    'month': int,
    'retireAge': int,
    'addMonths': int,
    'retireYear': int,
}


@scenarios("../features/retirement.feature", example_converters=CONVERTERS)
def test_retirement():
    pass


@given(
    parsers.cfparse(
        "the year and month of birth '{year:number}', '{month:number}'",
        extra_types=EXTRA_TYPES))
def birth_year_month1(year, month):
    return RetirementAgeCalculator(year, month)


@when("the retire age is returned")
def get_retire_age(birth_year_month1):
    return birth_year_month1.retire_age


@then(
    parsers.cfparse("verify the age is equals '{expected:number}'",
                    extra_types=EXTRA_TYPES))
def verify_age(get_retire_age, expected):
    assert get_retire_age == 67
コード例 #29
0
import pytest
from pytest_bdd import parsers
from pytest_bdd import given, when, then, scenarios
from boofuzz import helpers
from boofuzz import ip_constants


scenarios('helpers_udp_checksum.feature')


@given('Empty msg')
def msg_empty(context):
    context.msg = b''


@given(parsers.cfparse('msg {msg}'))
def msg_1_byte(context, msg):
    context.msg = ast.literal_eval(msg)


@given('msg with 60 bytes')
def msg_60_bytes(context):
    # Use each bit at least once...
    all_16_bits = b'\x00\x01\x00\x02\x00\x04\x00\x08\x00\x10\x00\x20\x00\x40\x00\x80' + \
                  b'\x01\x00\x02\x00\x04\x00\x08\x00\x10\x00\x20\x00\x40\x00\x80\x00'
    # Then fill the remaining bytes.
    # Note that using all FF bytes causes a boring pattern, since FFFF + FFFF
    # with carry is just FFFF again. 0x8001 adds just a little bit at a time,
    # hopefully ensuring that all bytes are actually factored into the answer.
    filler = b'\x80\x01' * ((60 - len(all_16_bits)) // 2)
    context.msg = all_16_bits + filler
コード例 #30
0
)
from cucumbers import CucumberBasket
from functools import partial

scenarios('../features/cucumbers.feature')
#@scenario('features\cucumbers.feature', 'Add cucumbers to the basket')
#def test_add_cucumbers_to_the_basket():
#    pass

EXTRA_TYPES = {
    'Number': int,
}


# parse_num = partial(parser.cfparse(, extra_types=EXTRA_TYPES)
@given(parsers.cfparse('the basket has "{initial:Number}" cucumbers'),
       extra_types=EXTRA_TYPES)
def basket(initial):
    return CucumberBasket(initial_count=initial)


@when(parsers.cfparse('"{some:Number}" cucumbers are added to the basket'),
      extra_types=EXTRA_TYPES)
def cucumbers_are_added_to_the_basket(basket, some):
    basket.add(some)


@then(parsers.cfparse('the basket contains "{total:Number}" cucumbers'),
      extra_types=EXTRA_TYPES)
def the_basket_contains_6_cucumbers(basket, total):
    assert basket.count() == total
コード例 #31
0
ファイル: test_web.py プロジェクト: vish1202/PytestBddDemo
# Fixtures

@pytest.fixture
def browser():
    b = webdriver.Firefox()
    b.implicitly_wait(10)
    yield b
    b.quit()


# Given Steps

@given('the DuckDuckGo home page is displayed')
def ddg_home(browser):
    browser.get(DUCKDUCKGO_HOME)


# When Steps

@when(parsers.cfparse('the user searches for "{phrase}"'))
def search_phrase(phrase):
    # search_input = browser.find_element_by_name('q')
    # search_input.send_keys(phrase + Keys.RETURN)
    print("When Statement executed" + phrase)


# Then Steps
@then(parsers.cfparse('results are shown for "{phrase}"'))
def search_results(phrase):
    print("Then Statement executed" + phrase)
コード例 #32
0
CONVERTERS = {'year': int, 'years': int, 'month': int}


@scenario('../features/retirement_age.feature', 'Correct age of '
          'retirement is returned')
def test_ranges():
    pass


@given('the Full Retirement Age Calculator has ' 'started')
def step_impl():
    pass


@when(
    parsers.cfparse('the year "{year:Number}" is entered',
                    extra_types=EXTRA_TYPES))
@when('the year "<year>" is entered')
def enter_year(setup, year):
    year = int(year)
    setup.calculate_receipt_age(year)


@then(
    parsers.cfparse(
        'the full retirement age displayed is "{'
        'years:Number}","{month:Number}"',
        extra_types=EXTRA_TYPES))
@then('the full retirement age displayed is "<years>", "<month>"')
def step_impl(setup, years, month):
    years = int(years)
    month = int(month)
コード例 #33
0
EXTRA_TYPES = {
    'Number': int,
}

CONVERTERS = {
    'initial': int,
    'some': int,
    'total': int,
}

# scenarios('../features/durians.feature')
scenarios('../features/durians.feature', example_converters=CONVERTERS)


@given(parsers.cfparse('the bamboo basket has "{initial:Number}" durians',
                       extra_types=EXTRA_TYPES),
       target_fixture="basket")
@given('the bamboo basket has "<initial>" durians')
def basket(initial):
    return DurianBasket(initial_count=initial)


@when(
    parsers.cfparse('"{some:Number}" durians are added to the bamboo basket',
                    extra_types=EXTRA_TYPES))
@when('"<some>" durians are added to the bamboo basket')
def add_durians(basket, some):
    basket.add(some)


@when(
コード例 #34
0
    'retirement_age_month': int,
    'retirement_date_month': str,
    'retirement_date_year': int,
}
parse_num = partial(parsers.cfparse, extra_types=EXTRA_TYPES)

scenarios('../features/FullRetirementAge.feature',
          example_converters=CONVERTERS)


@given("the program is started")
def step_impl():
    pass


@when(parsers.cfparse('the user enters a valid "{year_choice}" year of birth'))
@when('the user enters a valid "<year_choice>" year of birth')
def age_calc(year_choice):
    date_validation(year_choice, "year")
    return Retirement(year_choice=year_choice)


@when(parsers.cfparse('the user enters a valid "{month_choice}" year of birth')
      )
@when('the user enters a valid "<month_choice>" month of birth')
def set_month(age_calc, month_choice):
    date_validation(month_choice, "month")
    age_calc.month_choice = month_choice


@then(
コード例 #35
0
scenarios('features/bidding.feature')


def add_numbered_cards_of_suit_to_hand(hand, n, suit):
    numbered_cards = ['2', '3', '4', '5', '6', '7', '8', '9']
    for _ in range(n):
        random.shuffle(numbered_cards)
        hand.add(pydealer.Card(numbered_cards.pop(), suit))


@given('I have a hand of cards')
def hand_of_cards():
    return pydealer.Stack()


@when(parsers.cfparse('I have {num:d} numbered {suit}'))
def add_numbered_cards(hand_of_cards, num, suit):
    add_numbered_cards_of_suit_to_hand(hand_of_cards, num, suit)


@when(parsers.cfparse('I have the {value} of {suit}'))
def add_card_of_value(hand_of_cards, value, suit):
    hand_of_cards.add(pydealer.Card(value, suit))


@when('I have the three lowest Hearts')
def add_three_lowest_hearts(hand_of_cards):
    hand_of_cards.add(pydealer.Card('Two', 'Hearts'))
    hand_of_cards.add(pydealer.Card('Three', 'Hearts'))
    hand_of_cards.add(pydealer.Card('Four', 'Hearts'))
コード例 #36
0
from pytest_bdd import scenarios, given, when, then, parsers
import pytest
from .async_utils import sync
from functools import wraps
import asyncio
import logging

_logger = logging.getLogger(__name__)

scenarios('media_renderer_api.feature')


@when(parsers.cfparse('the playback volume of AcmeRenderer changes to {volume:d}'))
@sync
async def external_volume_change(test_context, event_bus_connection, volume):
    device = test_context.get_device('AcmeRenderer')
    await device.service('urn:schemas-upnp-org:service:RenderingControl:1')._set_volume(volume)


@when(parsers.cfparse('the client requests to change the volume of {device_name} to {volume:d}'))
@sync
async def change_renderer_volume(test_context, device_name, webclient, volume):
    if device_name == "an unkown device":
        udn = 'fake-udn-no-device-has-this'
    else:
        device = test_context.get_device(device_name)
        udn = device.udn
    test_context.last_response = await webclient.put(f'/player/{udn}/volume', json={'volume_percent': volume})


@when(parsers.cfparse('the client requests the volume of {device_name}'))
コード例 #37
0
    avatarCreatequote.input_streetname(street_name)


@when('User enters <year_built>')
def user_enters_year_built(year_built):
    """User enters <year_built>."""
    avatarCreatequote.input_yearbuilt(year_built)


@when('User enters <zip_code>')
def user_enters_zip_code(zip_code):
    """User enters <zip_code>."""
    avatarCreatequote.input_zipcode(zip_code)


@when(parsers.cfparse("User logs in with user '{user}'"))
def click_on_login_btn(user):
    avatarLoginPage.login(user)
    print("User clicked on item")


@when('User selects <bceg>')
def user_selects_bceg(bceg):
    """User selects <bceg>."""
    avatarCreatequote.select_bceg(bceg)


@when('User selects <construction_type>')
def user_selects_construction_type(construction_type):
    """User selects <construction_type>."""
    avatarCreatequote.select_construction_type(construction_type)
コード例 #38
0
    'ageMonth': int,
    'retireMonth': str,
    'retireYear': int,
    'invalid_inputs': int,
}

scenarios('../features/calcRetirement.feature', example_converters=CONVERTERS)


@given("the program is running")
def test_calc():
    pass


@when(
    parsers.cfparse('I enter "{birthYear:Number}" for the birth year',
                    extra_types=EXTRA_TYPES))
@when('I enter "<birthYear>" for the birth year')
def birth_year(birthYear):
    age, month = retirement(birthYear)
    return age, month


@then(
    parsers.cfparse(
        'my retirement age is "{ageYear:Number}" and '
        '"{ageMonth}" months',
        extra_types=EXTRA_TYPES))
@then('my retirement age is "<ageYear>" years and "<ageMonth>" months')
def retire_age(ageYear, ageMonth):
    assert ageYear, ageMonth == birth_year
コード例 #39
0
from pytest_bdd import scenario, given, when, then, parsers, scenarios
from selenium import webdriver
from pageObjects import page
import sys

sys.path.append("..")
from exceptions.oceaview_exceptions import *


# Given Steps
@given(parsers.cfparse('I have navigated to Oceaview with url {aUrl}'))
@given('I have navigated to Oceaview with url <aUrl>')
def givenNavigateToOceaViewPage(context, chromeBrowser, aUrl):
    context.loginPage = page.LoginPage(chromeBrowser).gotoUrl(aUrl)


@given(parsers.parse('I have entered <userName> into the user name'))
def givenIHaveEnteredSomethingIntoTheUserName(get_config, context, userName):
    context.loginPage.userNameInput_element = get_config.name if (
        get_config and userName == '<default>') else userName
    pass


@given(parsers.parse('I have entered <password> into the password'))
def givenIHaveEnteredSomethingIntoPassword(get_config, context, password):
    context.loginPage.passwordInput_element = password


# When steps

コード例 #40
0
        raise RuntimeError("Unexpected still inside a transaction error.")


@pytest.fixture
def context():
    return {}


@when('we enter a transaction')
def step_start_transaction(ldap):
    transaction.enter_transaction_management()


@when('we commit the transaction')
def step_commit_transaction(ldap):
    transaction.commit()
    transaction.leave_transaction_management()


@when('we rollback the transaction')
def step_rollback_transaction(ldap):
    transaction.rollback()
    transaction.leave_transaction_management()


@then(parsers.cfparse(
    'we should be able confirm the {attribute} attribute is {value}'))
def step_confirm_attribute(context, attribute, value):
    actual_value = context['obj'].get_as_single(attribute)
    assert str(actual_value) == value, attribute