Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flask API 를 테스트하기 위한 아이디어
# 실제 API
def get_collections(serializer):
collections = orm.foo()
paging = orm.bar()
return serializer.serialize(items=collections, paging=paging)
# 테스트
def test_serializer_get_collections():
collections = fixture_collections()
paging = fixture_paging()
serializer = ListSerializer()
result = serializer.serialize(items=collections, paging=paging)
assert_equal(len(result['items']), 3)
assert_nil(len(result['paging']['next']))
def test_api_get_collections():
serializer = StubListSerializer()
get_collections(serializer)
assert_equal(len(serializer.executions['serialize']), 1)
class StubListSerializer(object):
executions = {}
def serialize(items, paging):
executions.setdefault('serialize', [])
executions['serialize'].append((items, paging))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment