Created
November 15, 2013 10:16
-
-
Save spacelis/7482155 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" Testing API module. | |
File: test_api.py | |
Author: SpaceLis | |
Email: Wen.Li@tudelft.nl | |
GitHub: http://github.com/spacelis | |
Description: | |
Testing API Module. | |
""" | |
import json | |
import unittest | |
import mock | |
from mock import mock_open | |
from StringIO import StringIO | |
from google.appengine.ext import testbed | |
from apps.profileviewer.api import import_entities | |
class ContextualStringIO(StringIO): | |
def __enter__(self): | |
return self | |
def __exit__(self, *args): | |
self.close() | |
return False | |
# pylint: disable=R0904 | |
@mock.patch('apps.profileviewer.api.flexopen',) | |
class TestImportAPI(unittest.TestCase): | |
""" TestImportAPI. """ | |
def setUp(self): | |
self.testbed = testbed.Testbed() | |
self.testbed.setup_env(app_id='geo-expertise') | |
self.testbed.activate() | |
self.testbed.init_memcache_stub() | |
self.testbed.init_datastore_v3_stub() | |
def tearDown(self): | |
self.testbed.deactivate() | |
def test_importEntity(self, mock_flexopen): | |
""" test_importEntity. """ | |
mock_flexopen.return_value = ContextualStringIO( | |
"screen_name,checkins\nspaceli,\"{\"\"a\"\": 1}\"") | |
def loader(r): | |
""" test_loader. """ | |
self.assertEqual(r['screen_name'], 'spaceli') | |
self.assertEqual(json.loads(r['checkins']), {'a': 1}) | |
import_entities('', loader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment