Skip to content

Instantly share code, notes, and snippets.

@milancermak
Last active July 16, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milancermak/24c9cbf6ed700aca4c7f7b117c86cb0a to your computer and use it in GitHub Desktop.
Save milancermak/24c9cbf6ed700aca4c7f7b117c86cb0a to your computer and use it in GitHub Desktop.
from botocore import Stubber, ANY
import pytest
import models
@pytest.fixture(scope="function")
def ddb_stubber():
ddb_stubber = Stubber(models.Table.meta.client)
ddb_stubber.activate()
yield ddb_stubber
ddb_stubber.deactivate()
def test_user_exists(ddb_stubber):
user_id = 'user123'
get_item_params = {'TableName': ANY,
'Key': {'id': user_id}}
get_item_response = {'Item': {'id': {'S': user_id},
'name': {'S': 'Spam'}}}
ddb_stubber.add_response('get_item', get_item_response, get_item_params)
result = main.get_user(user_id)
assert result.get('id') == user_id
ddb_stubber.assert_no_pending_responses()
def test_user_missing(ddb_stubber):
user_id = 'user123'
get_item_params = {'TableName': ANY,
'Key': {'id': user_id}}
get_item_response = {}
ddb_stubber.add_response('get_item', get_item_response, get_item_params)
result = main.get_user(user_id)
assert result is None
ddb_stubber.assert_no_pending_responses()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment