Skip to content

Instantly share code, notes, and snippets.

@alexsoyes
Created September 19, 2022 02:29
Show Gist options
  • Save alexsoyes/1c8ddd46bbea48d411eabdd8ce16ab80 to your computer and use it in GitHub Desktop.
Save alexsoyes/1c8ddd46bbea48d411eabdd8ce16ab80 to your computer and use it in GitHub Desktop.
An example of Behave testing.
from behave import given, when, then
import requests
@given(u'The manager asks for the "{mandatory}" skill Java with the id "{id}" and the level "{level:d}"')
def step_impl(context, mandatory, id, level):
context.payload = dict()
context.payload['asked_skills'] = []
context.payload['asked_languages'] = []
context.payload['among_skills'] = []
context.payload['among_languages'] = []
isMandatory = mandatory == 'mandatory'
context.payload['asked_skills'].append({
'id': id,
'level': level,
'isMandatory': isMandatory
})
pass
@given(u'The manager asks for the "{mandatory}" skill Project Management with the id "{id}" and the level "{level:d}"')
def step_impl(context, mandatory, id, level):
isMandatory = mandatory == 'mandatory'
context.payload['asked_skills'].append({
'id': id,
'level': level,
'isMandatory': isMandatory
})
pass
@given(u'The manager asks for the language French with the id "{id}" of level "{level:d}"')
def step_impl(context, id, level):
context.payload['asked_languages'].append({
'id': id,
'level': level
})
pass
@given(u'The manager asks for the language English with the id "{id}" of level "{level:d}"')
def step_impl(context, id, level):
context.payload['asked_languages'].append({
'id': id,
'level': level
})
pass
@when(u'The skill Java Enterprise with id "{id}" of level "{level:d}" is provided')
def step_impl(context, id, level):
context.payload['among_skills'].append({
'id': id,
'level': level
})
pass
@when(u'The language French with the id "{id}" of level "{level:d}" is provided')
def step_impl(context, id, level):
context.payload['among_languages'].append({
'id': id,
'level': level
})
pass
@when(u'The language English with the id "{id}" of level "{level:d}" is provided')
def step_impl(context, id, level):
context.payload['among_languages'].append({
'id': id,
'level': level
})
pass
@then(u'The matching must equal "{matching}"')
def step_impl(context, matching):
response: requests.Response = requests.post(context.url + '/v2/getMatching', json=context.payload, headers=context.headers)
jsonResponse = response.json()
assert jsonResponse.get('matching') == matching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment