Пример #1
0
class ConnectionRestApi:
    def __init__(self, context=None):
        self.context = context
        self.service = ConnectionService(context)

    @handle_request()
    def add(self):
        """
        Add connection.
        :param body: Add connection request.
        :return: Added connection id.
        """
        return self.service.add(from_json(self.context['body']))

    @handle_request()
    def get(self):
        """
        Get connection.
        :return: Connection
        """
        return self.service.get(self.context['path_parameters']['connection_id']).model

    @handle_request()
    def list(self):
        items = [connection.model for connection in self.service.list()]
        return {'items': items, 'count': len(items)}

    @handle_request()
    def delete(self):
        connection_id = self.context['path_parameters']['connection_id']
        self.service.delete(connection_id)
        return f'Successfully removed connection {connection_id}'
Пример #2
0
 def test_repo_called_with_entity(self, model_new, mock_ddb_table):
     ConnectionService().add(model_new)
     mock_table = boto3.resource('dynamodb').Table('connections')
     args_list = mock_table.put_item.call_args_list
     assert args_list[-1]
     args, kwargs = args_list[-1]
     assert kwargs['Item']['client'] == 'my client'
Пример #3
0
 def test_get_not_found(self, mock_ddb_table):
     boto3.resource('dynamodb').Table(
         'connections').get_item.return_value = {
             'status_code': '200'
         }
     with pytest.raises(ResourceNotFoundException):
         ConnectionService().get(str(uuid.uuid4()))
Пример #4
0
 def test_repo_table_name_from_env_variables(self, model_valid,
                                             mock_ddb_table):
     os.environ['env'] = 'my_env'
     os.environ['client'] = 'my_client'
     ConnectionService().delete(model_valid['connection_id'])
     args, kwargs = boto3.resource(
         'dynamodb').delete_item.call_args_list[-1]
     assert kwargs['TableName'] == 'connections_dev_dan'
Пример #5
0
 def test_add_connection_metadata(self, model_new, mock_ddb_table):
     ConnectionService().add(model_new)
     args, kwargs = boto3.resource('dynamodb').Table(
         'connections').put_item.call_args_list[-1]
     metadata = kwargs['Item'].get('metadata')
     assert metadata
     validate_date_format(metadata['created'])
     validate_date_format(metadata['updated'])
 def test_connection_created_event(self, setup, model_new):
     ConnectionService().add(model_new)
 def test_playground(self):
     # ConnectionService().get(str(uuid.uuid4()))
     print(ConnectionService().list())
Пример #8
0
 def __init__(self, context=None):
     self.context = context
     self.service = ConnectionService(context)
Пример #9
0
 def test_repo_table_name(self, model_valid, mock_ddb_table):
     ConnectionService().delete(model_valid['connection_id'])
     args, kwargs = boto3.resource(
         'dynamodb').delete_item.call_args_list[-1]
     assert kwargs['TableName'] == 'connections_dev_dan'