Adding url to the global context in the start of the before request webhook. Created a test to the wolfram alpha endpoint
parent
704743d81c
commit
7e26e4ba49
|
@ -0,0 +1,20 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from behave import when, then
|
||||
from hamcrest import assert_that
|
||||
|
||||
|
||||
@when('a question is sent')
|
||||
def send_question(context):
|
||||
login = context.device_login
|
||||
access_token = login['accessToken']
|
||||
context.wolfram_response = context.client.get(
|
||||
'/v1/wa?input=what+is+the+capital+of+Brazil',
|
||||
headers=dict(Authorization='Bearer {token}'.format(token=access_token))
|
||||
)
|
||||
|
||||
|
||||
@then('the wolfram alpha endpoint should return 200')
|
||||
def validate_response(context):
|
||||
response = context.wolfram_response
|
||||
assert_that(response.status_code, HTTPStatus.OK)
|
|
@ -0,0 +1,5 @@
|
|||
Feature: Integration with Wolfram Alpha API
|
||||
|
||||
Scenario: Question sent to the wolfram alpha endpoint
|
||||
When a question is sent
|
||||
Then the wolfram alpha endpoint should return 200
|
|
@ -21,13 +21,12 @@ ONE_DAY = 86400
|
|||
|
||||
|
||||
def check_oauth_token():
|
||||
global_context.url = request.url
|
||||
exclude_paths = ['/v1/device/code', '/v1/device/activate', '/api/account', '/v1/auth/token']
|
||||
exclude = any(request.path.startswith(path) for path in exclude_paths)
|
||||
|
||||
if not exclude:
|
||||
headers = request.headers
|
||||
if 'Authorization' not in headers:
|
||||
global_context.url = request.url
|
||||
raise AuthenticationError('Oauth token not found')
|
||||
token_header = headers['Authorization']
|
||||
device_authenticated = False
|
||||
|
@ -37,7 +36,6 @@ def check_oauth_token():
|
|||
if session:
|
||||
device_authenticated = True
|
||||
if not device_authenticated:
|
||||
global_context.url = request.url
|
||||
raise AuthenticationError('device not authorized')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue