-
-
Save milancermak/24c9cbf6ed700aca4c7f7b117c86cb0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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