Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Faraone committed Jul 21, 2021
1 parent 41fc23f commit 5351e7f
Show file tree
Hide file tree
Showing 14 changed files with 563 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
exclude = .idea,.vscode,.git,pg_data,venv,env,
show-source = True
max-line-length = 100
application-import-names = smarkets
max-cognitive-complexity = 15
ignore = FI1,I100,W503

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pyc
htmlcov
.coverage
coverage.xml
dist
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# EaaS: EaaS e2e AsyncMock changelog

* 1.0.0: initial version
36 changes: 36 additions & 0 deletions HOWTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Welcome to Connect Extension project EaaS e2e AsyncMock

## Next steps

You may open your favorite IDE and start working with your project, please note that this project runs using docker.
You may modify at any time the credentials used to authenticate to connect modifying the file:

*eaas_e2e_asyncmock/.eaas_e2e_asyncmock_dev.env*


In order to start your extension as standalone docker container you can access the project folder and run:

**$ docker compose up eaas_e2e_asyncmock_dev**


please note that in this way you will run the docker container and if you do changes on the code you will need to stop it and start it again.
If you would like to develop and test at same time, we recommend you to run your project using the command

**$ docker compose run eaas_e2e_asyncmock_bash**


Once you get the interactive shell, you can run your extension using the command `cextrun`, stopping the process (using ctrl+c) and starting it back will reload the changes.

Additionally, a basic boilerplate for writing unit tests has been created, you can run the tests using

**$ docker compose run eaas_e2e_asyncmock_test**


## Community Resources

Please take note about this links in order to get additional information:

* https://connect.cloudblue.com/
* https://connect.cloudblue.com/community/modules/devops/
* https://connect.cloudblue.com/community/sdk/python-openapi-client/
* https://connect-openapi-client.readthedocs.io/en/latest/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Welcome to EaaS e2e AsyncMock !


Project description



## License

**EaaS e2e AsyncMock** is licensed under the *Apache Software License 2.0* license.

Empty file added connect_ext/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions connect_ext/extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "EaaS Async Extension for e2e",
"description": "This extension is for e2e tests of EaaS.",
"version": "1.0.0",
"readme_url": "https://github.com/ffaraoneim/eaas-extension-e2e/blob/master/README.md",
"changelog_url": "https://github.com/ffaraoneim/eaas-extension-e2e/blob/master/README.md",
"capabilities": {
"asset_purchase_request_processing": ["pending", "approved", "failed", "inquiring"],
"asset_change_request_processing": ["pending", "approved", "failed", "inquiring"],
"asset_suspend_request_processing": ["pending", "approved", "failed"],
"asset_resume_request_processing": ["pending", "approved", "failed"],
"asset_cancel_request_processing": ["pending", "approved", "failed"],
"asset_adjustment_request_processing": ["pending", "approved", "failed", "inquiring"],
"asset_purchase_request_validation": ["draft"],
"asset_change_request_validation": ["draft"],
"product_action_execution": [],
"product_custom_event_processing": [],
"tier_config_setup_request_processing": ["pending", "failed", "approved", "inquiring"],
"tier_config_change_request_processing": ["pending", "failed", "approved", "inquiring"],
"tier_config_adjustment_request_processing": ["pending", "failed", "approved", "inquiring"],
"tier_config_setup_request_validation": ["draft"],
"tier_config_change_request_validation": ["draft"]
}
}
209 changes: 209 additions & 0 deletions connect_ext/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, CloudBlue
# All rights reserved.
#
from connect.eaas.extension import (
Extension,
ProcessingResponse,
ValidationResponse,
ProductActionResponse,
CustomEventResponse,
)

import random
import string


class E2EExtension(Extension):

def get_response_by_var(self, status):
if status == 'succeeded':
return ProcessingResponse.done()
elif status == 'rescheduled':
return ProcessingResponse.reschedule(86400)
elif status == 'failed':
raise Exception('fail the task man!')
return ProcessingResponse.skip()


async def approve_asset_request(self, request, template_id):
self.logger.info(f'request_id={request["id"]} - template_id={template_id}')
await self.client.requests[request['id']]('approve').post(
{
'template_id': template_id,
}
)
self.logger.info(f"Approved request {request['id']}")

async def approve_tier_request(self, request, template_id):
self.logger.info(f'request_id={request["id"]} - template_id={template_id}')
await self.client.ns('tier').config_requests[request['id']]('approve').post(
{
'template': {
'id': template_id
}
}
)
self.logger.info(f"Approved request {request['id']}")

async def process_asset_purchase_request(self, request):
self.logger.info(
f"Received event for request {request['id']} in status {request['status']}"
)
if 'E2E_EXIT_STATUS' in self.config:
status = self.config['E2E_EXIT_STATUS']
self.logger.info(
f'simulate response of type: {status}',
)
return self.get_response_by_var(status)

if request['status'] == 'pending':
param_a = ''.join(random.choice(string.ascii_lowercase) for _ in range(10))
param_b = ''.join(random.choice(string.ascii_lowercase) for _ in range(6))
await self.client.requests[request['id']].update(
{
"asset": {
"params": [
{
"id": "param_a",
"value": param_a
},
{
"id": "param_b",
"value": param_b
}

]
}
}
)
self.logger.info("Updating fulfillment parameters as follows:"
f"param_a to {param_a} and param_b to {param_b}")
template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_asset_request(request, template_id)

return ProcessingResponse.done()

async def process_asset_change_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)

if request['status'] == 'pending':
template_id = self.config['ASSET_REQUEST_CHANGE_TEMPLATE_ID']
await self.approve_asset_request(request, template_id)
return ProcessingResponse.done()

async def process_asset_suspend_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_asset_request(request, template_id)
return ProcessingResponse.done()

async def process_asset_resume_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_asset_request(request, template_id)
return ProcessingResponse.done()

async def process_asset_cancel_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_asset_request(request, template_id)
return ProcessingResponse.done()

async def process_asset_adjustment_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_asset_request(request, template_id)
return ProcessingResponse.done()

async def validate_tier_config_setup_request(self, request):
self.logger.info(f"TCR Validation with id {request['id']}")
return ValidationResponse.done(request)

async def validate_tier_config_change_request(self, request):
self.logger.info(f"TCR Validation with id {request['id']}")
return ValidationResponse.done(request)

async def validate_asset_purchase_request(self, request):
self.logger.info(f"Asset Validation with if {request['id']}")
return ValidationResponse.done(request)

async def validate_asset_change_request(self, request):
self.logger.info(f"asset Validation with if {request['id']}")
return ValidationResponse.done(request)

async def execute_product_action(self, request):
self.logger.info(f'Product action: {request}')
return ProductActionResponse.done(
http_status=302,
headers={'Location': 'https://google.com'},
)

async def process_product_custom_event(self, request):
self.logger.info(f'Custom event: {request}')
sample_return_body = {
"response": "OK"
}
return CustomEventResponse.done(body=sample_return_body)

async def process_tier_config_setup_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
reseller_fulfillment = ''.join(random.choice(string.ascii_lowercase) for _ in range(10))
await self.client.ns('tier').config_requests[request['id']].update(
{
"params": [
{
"id": "reseller_fulfillment",
"value": reseller_fulfillment
}
]
}
)
template_id = self.config['TIER_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_tier_request(request, template_id)

return ProcessingResponse.done()

async def process_tier_config_change_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
template_id = self.config['TIER_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_tier_request(request, template_id)
return ProcessingResponse.done()

async def process_tier_config_adjustment_request(self, request):
self.logger.info(
f"Received event for request {request['id']}, type {request['type']} "
f"in status {request['status']}"
)
if request['status'] == 'pending':
template_id = self.config['TIER_REQUEST_APPROVE_TEMPLATE_ID']
await self.approve_tier_request(request, template_id)
return ProcessingResponse.done()
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'

services:
eaas_e2e_asyncmock_dev:
container_name: eaas_e2e_asyncmock_dev
image: cloudblueconnect/connect-extension-runner:23.4
command: cextrun -d
volumes:
- .:/extension
env_file:
- .eaas_e2e_asyncmock_dev.env

eaas_e2e_asyncmock_bash:
container_name: eaas_e2e_asyncmock_bash
image: cloudblueconnect/connect-extension-runner:23.4
working_dir: /extension
command: /bin/bash
stdin_open: true
tty: true
volumes:
- .:/extension
env_file:
- .eaas_e2e_asyncmock_dev.env

eaas_e2e_asyncmock_test:
container_name: eaas_e2e_asyncmock_test
image: cloudblueconnect/connect-extension-runner:23.4
working_dir: /extension
command: /bin/bash -c "poetry install && pytest --verbose --cov=connect_ext --cov-report=html --cov-report=term-missing:skip-covered"
volumes:
- .:/extension
env_file:
- .eaas_e2e_asyncmock_dev.env
2 changes: 2 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
create = false
Loading

0 comments on commit 5351e7f

Please sign in to comment.