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
Exemple #2
0
@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)
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))
Exemple #4
0
    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]
@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)))
Exemple #6
0
@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)
Exemple #7
0
@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)
Exemple #8
0
@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)
Exemple #9
0
@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]
        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