Skip to content

Bugfix/Fixed typo in module name fixture. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ $ pip install connect-devops-testing-library
DevOps Testing Library has a small request builder to ease the manipulation of the connect requests during testing:

````python
from connect.devops_testing import fixures
from connect.devops_testing import fixtures
import os

template = os.path.dirname(__file__) + '/request.json'

request = (fixures.make_request_builder(template)
request = (fixtures.make_request_builder(template)
.with_type('purchase')
.with_asset_product('PRD-000-000-000', 'Product Name')
.with_asset_configuration_param('SOME_ASSET_CFG__PARAM_ID_A', 'some_cfg_value_a')
Expand All @@ -46,7 +46,7 @@ asserts.asset_params_value_not_equal(request, 'SOME_ASSET_PARAM_ID_001', 'some_e
Using these two features you can easily create a small test to check a purchase request of your processor:

```python
from connect.devops_testing import fixures, asserts
from connect.devops_testing import fixtures, asserts
from my_ext.extension import MyExtension
import os

Expand All @@ -55,7 +55,7 @@ def test_should_approve_request(mocked_connect_client, mocked_service_client, lo
template = os.path.dirname(__file__) + '/request.json'

# prepare the request.
request = (fixures.make_request_builder(template)
request = (fixtures.make_request_builder(template)
.with_type('purchase')
.with_status('pending')
.with_asset_param('subscription_id', '')
Expand All @@ -78,23 +78,23 @@ environment variables in `CONNECT_API_KEY` and `CONNECT_API_URL`. Alternatively,
to the `make_request_dispatcher(api_key=XXX, api_url=YYY)` function. Let's see example:

```python
from connect.devops_testing import asserts, fixures
from connect.devops_testing import asserts, fixtures
import os


def test_should_approve_purchase_request_successfully():
template = os.path.dirname(__file__) + '/request.json'

# prepare the request.
request = (fixures.make_request_builder(template)
request = (fixtures.make_request_builder(template)
.with_type('purchase')
.with_status('pending')
.with_asset_param('subscription_id', '')
.build())

# dispatch the request to connect and wait some time so the
# processor can process the request.
request = (fixures.make_request_dispatcher()
request = (fixtures.make_request_dispatcher()
.provision_request(request, 10, 20))

# evaluate the processed request.
Expand All @@ -114,7 +114,7 @@ Finally, the DevOps Testing Library also allows you to easily use Behave! BDD to
the following code in your `features/environment.py` file

```python
from connect.devops_testing.bdd.fixures import use_connect_request_dispatcher, use_connect_request_builder
from connect.devops_testing.bdd.fixtures import use_connect_request_dispatcher, use_connect_request_builder
# import the built-in steps for e2e testing.
from connect.devops_testing.bdd import steps

Expand Down
50 changes: 50 additions & 0 deletions connect/devops_testing/bdd/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import Optional

from behave.runner import Context

from connect.devops_testing.fixtures import make_request_builder, make_request_dispatcher


def use_connect_request_dispatcher(
context: Context,
api_key: Optional[str] = None,
api_url: Optional[str] = None,
use_specs: bool = True,
timeout: int = 10,
max_attempts: int = 20,
):
"""
Provides a connect request provider into the behave Context object.

:param context: Context
:param api_key: Optional[str] The Connect API key
:param api_url: Optional[str] The Connect API url
:param use_specs: bool True to initialize the Open API Specification
live connection
:param timeout: int The timeout for waiting on each request refresh in seconds.
:param max_attempts: int The max amount of time to refresh a request
:return: None
"""
context.connect = make_request_dispatcher(
api_key=api_key,
api_url=api_url,
use_specs=use_specs,
)
context.timeout = timeout
context.max_attempts = max_attempts
context.request = None


def use_connect_request_builder(context: Context, parameters: Optional[dict] = None):
"""
Provides a connect request builder into the behave Context object.

:param context: Context
:param parameters: Optional[dict] Key-Value dictionary with the key as
param name and value as param id.
:return: None
"""
parameters = {} if parameters is None else parameters

context.parameter = lambda name, default=None: parameters.get(name, default)
context.builder = make_request_builder()
26 changes: 0 additions & 26 deletions connect/devops_testing/bdd/fixures.py

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions tests/bdd/test_fixures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from behave.runner import Context

from connect.devops_testing.bdd.fixures import use_connect_request_dispatcher, use_connect_request_builder
from connect.devops_testing.bdd.fixtures import use_connect_request_dispatcher, use_connect_request_builder
from connect.devops_testing.request import Builder, Dispatcher


Expand All @@ -17,7 +17,7 @@ def test_should_successfully_initialize_request_builder_in_behave_context():
def test_should_successfully_initialize_request_dispatcher_in_behave_context():
context = Context(runner=Mock())

use_connect_request_dispatcher(context, False)
use_connect_request_dispatcher(context, use_specs=False)

assert isinstance(context.connect, Dispatcher)
assert context.request is None
8 changes: 4 additions & 4 deletions tests/test_fixures.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from connect.devops_testing import fixures
from connect.devops_testing import fixtures
from connect.devops_testing.request import Builder, Dispatcher


def test_should_make_successfully_the_request_builder():
_builder = fixures.make_request_builder()
_builder = fixtures.make_request_builder()
assert isinstance(_builder, Builder)


def test_should_make_successfully_the_request_dispatcher_with_credentials_from_env(monkeypatch):
_dispatcher = fixures.make_request_dispatcher(use_specs=False)
_dispatcher = fixtures.make_request_dispatcher(use_specs=False)
assert isinstance(_dispatcher, Dispatcher)


def test_should_make_successfully_the_request_dispatcher_with_given_credentials(monkeypatch):
_dispatcher = fixures.make_request_dispatcher(api_key='sample', api_url='sample', use_specs=False)
_dispatcher = fixtures.make_request_dispatcher(api_key='sample', api_url='sample', use_specs=False)
assert isinstance(_dispatcher, Dispatcher)
38 changes: 19 additions & 19 deletions tests/test_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from connect.devops_testing import fixures
from connect.devops_testing import fixtures
from connect.devops_testing.request import Builder

import pytest
Expand All @@ -15,15 +15,15 @@ def test_request_builder_should_fail_building_request_with_wrong_template_type()


def test_request_builder_should_use_default_asset_template():
request = (fixures.make_request_builder()
request = (fixtures.make_request_builder()
.from_default_asset()
.build())

assert 'asset' in request


def test_request_builder_should_use_default_tier_config_template():
request = (fixures.make_request_builder()
request = (fixtures.make_request_builder()
.from_default_tier_config()
.build())

Expand All @@ -32,12 +32,12 @@ def test_request_builder_should_use_default_tier_config_template():

def test_request_builder_should_raise_exception_on_adding_parameter_to_missing_asset_item():
with pytest.raises(ValueError):
(fixures.make_request_builder()
(fixtures.make_request_builder()
.with_asset_item_param('MISSING', 'PARAM_ID', 'The value'))


def test_request_builder_should_build_successfully_a_valid_asset_request():
request = (fixures.make_request_builder()
request = (fixtures.make_request_builder()
.with_type('purchase')
.with_status('approved')
.with_id('PR-0000-0000-0000-100')
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_request_builder_should_build_successfully_a_valid_asset_request():


def test_request_builder_should_build_successfully_a_valid_tier_config_request():
request = (fixures.make_request_builder()
request = (fixtures.make_request_builder()
.with_type('setup')
.with_status('approved')
.with_id('TCR-000-000-000-100')
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_request_builder_should_build_successfully_a_valid_tier_config_request()
def test_request_builder_should_build_successfully_a_valid_request_from_file_template():
template = os.path.dirname(__file__) + TPL_REQUEST_ASSET

request = (fixures.make_request_builder(template)
request = (fixtures.make_request_builder(template)
.build())

assert request['id'] == 'PR-7658-9572-0778-001'
Expand All @@ -167,7 +167,7 @@ def test_request_builder_should_build_successfully_a_valid_request_from_file_tem
def test_request_dispatcher_should_create_successfully_a_asset_request(sync_client_factory, response_factory):
template = os.path.dirname(__file__) + TPL_REQUEST_ASSET

request = fixures.make_request_builder(template)
request = fixtures.make_request_builder(template)

to_create = (request
.without('id')
Expand All @@ -186,7 +186,7 @@ def test_request_dispatcher_should_create_successfully_a_asset_request(sync_clie
response_factory(value=approved), # request.get (second call)
])

request = (fixures.make_request_dispatcher(client=connect_client)
request = (fixtures.make_request_dispatcher(client=connect_client)
.provision_request(request=to_create, timeout=0, max_attempt=1))

assert isinstance(request, dict)
Expand All @@ -195,7 +195,7 @@ def test_request_dispatcher_should_create_successfully_a_asset_request(sync_clie
def test_request_dispatcher_should_update_successfully_a_asset_request(sync_client_factory, response_factory):
template = os.path.dirname(__file__) + TPL_REQUEST_ASSET

request = fixures.make_request_builder(template)
request = fixtures.make_request_builder(template)

on_server = (request
.with_status('inquiring')
Expand All @@ -219,7 +219,7 @@ def test_request_dispatcher_should_update_successfully_a_asset_request(sync_clie
response_factory(value=approved), # request.get (second call)
])

request = (fixures.make_request_dispatcher(client=connect_client)
request = (fixtures.make_request_dispatcher(client=connect_client)
.provision_request(request=to_update, timeout=0, max_attempt=1))

assert request['asset']['params'][0]['value'] == 'SOME_VALID_VALUE'
Expand All @@ -228,7 +228,7 @@ def test_request_dispatcher_should_update_successfully_a_asset_request(sync_clie
def test_request_dispatcher_should_avoid_update_a_unchanged_asset_request(sync_client_factory, response_factory):
template = os.path.dirname(__file__) + TPL_REQUEST_ASSET

request = fixures.make_request_builder(template)
request = fixtures.make_request_builder(template)

on_server = request.build()

Expand All @@ -246,7 +246,7 @@ def test_request_dispatcher_should_avoid_update_a_unchanged_asset_request(sync_c
response_factory(value=approved), # request.get (second call)
])

request = (fixures.make_request_dispatcher(client=connect_client)
request = (fixtures.make_request_dispatcher(client=connect_client)
.provision_request(request=to_update, timeout=0, max_attempt=1))

assert request['asset']['params'][0]['value'] == ''
Expand All @@ -255,7 +255,7 @@ def test_request_dispatcher_should_avoid_update_a_unchanged_asset_request(sync_c
def test_request_dispatcher_should_create_successfully_a_tier_config_request(sync_client_factory, response_factory):
template = os.path.dirname(__file__) + TPL_REQUEST_TIER_CONFIG

request = fixures.make_request_builder(template)
request = fixtures.make_request_builder(template)

to_create = (request
.without('id')
Expand All @@ -274,7 +274,7 @@ def test_request_dispatcher_should_create_successfully_a_tier_config_request(syn
response_factory(value=approved), # tier.config_request.get (second call)
])

request = (fixures.make_request_dispatcher(client=connect_client)
request = (fixtures.make_request_dispatcher(client=connect_client)
.provision_request(request=to_create, timeout=0, max_attempt=1))

assert isinstance(request, dict)
Expand All @@ -283,7 +283,7 @@ def test_request_dispatcher_should_create_successfully_a_tier_config_request(syn
def test_request_dispatcher_should_update_successfully_a_tier_config_request(sync_client_factory, response_factory):
template = os.path.dirname(__file__) + TPL_REQUEST_TIER_CONFIG

request = fixures.make_request_builder(template)
request = fixtures.make_request_builder(template)

on_server = (request
.with_status('inquiring')
Expand All @@ -307,7 +307,7 @@ def test_request_dispatcher_should_update_successfully_a_tier_config_request(syn
response_factory(value=approved), # tier.config_request.get (second call)
])

request = (fixures.make_request_dispatcher(client=connect_client)
request = (fixtures.make_request_dispatcher(client=connect_client)
.provision_request(request=to_update, timeout=0, max_attempt=1))

assert isinstance(request, dict)
Expand All @@ -317,7 +317,7 @@ def test_request_dispatcher_should_update_successfully_a_tier_config_request(syn
def test_request_dispatcher_should_avoid_update_a_unchanged_tier_config_request(sync_client_factory, response_factory):
template = os.path.dirname(__file__) + TPL_REQUEST_TIER_CONFIG

request = fixures.make_request_builder(template)
request = fixtures.make_request_builder(template)

on_server = request.build()

Expand All @@ -335,7 +335,7 @@ def test_request_dispatcher_should_avoid_update_a_unchanged_tier_config_request(
response_factory(value=approved), # tier.config_request.get (second call)
])

request = (fixures.make_request_dispatcher(client=connect_client)
request = (fixtures.make_request_dispatcher(client=connect_client)
.provision_request(request=to_update, timeout=0, max_attempt=1))

assert request['configuration']['params'][0]['value'] == '000000'
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
exclude =
.idea,.vscode,.git,postgres_data,
*/migrations/*.py,*.eggs,*.egg,tests/,setup.py,
connect/.data,
connect/.data,samples
show-source = True
max-line-length = 120
import-order-style = smarkets
Expand Down