vendredi 21 juillet 2017

testing my GAE application with virtualenv in Python

I'm trying to test my datastore with unittest on my GAE application running locally

when i'm running a simple query on the datastore, I get an error from my virtualenv:

Error
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/Users/thibault/projects/backend/cron/gmail/test_gmail_api.py", line 40, in test_get_conversation_id_by_email
    res = get_conversation_id_from_email('test@gmail.com')
  File "/Users/thibault/projects/backend/cron/gmail/api_gmail.py", line 158, in get_conversation_id_from_email
    user_list = User.query(User.emails == email_user).fetch(use_cache=True, use_memcache=True)
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
    return wrapped(*args, **kwds)
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 1218, in fetch
    return self.fetch_async(limit, **q_options).get_result()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
    return wrapped(*args, **kwds)
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 1238, in fetch_async
    qry = self._fix_namespace()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 922, in _fix_namespace
    namespace = namespace_manager.get_namespace()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/namespace_manager/namespace_manager.py", line 88, in get_namespace
    name = _config.default_namespace_for_request()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 351, in __getattr__
    self._update_configs()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 287, in _update_configs
    self._registry.initialize()
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 160, in initialize
    import_func(self._modname)
  File "/Users/thibault/projects/backend/appengine_config.py", line 8, in <module>
    vendor.add('lib')
  File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/vendor/__init__.py", line 44, in add
    'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access lib: No such virtualenv or site directory

I'm using the ide pycharm. I don't understand why it can't find the lib folder because, when I run my app locally, there is no problem at all.
the error append only when I run a test.
here is my test:

class TestBodyMail(unittest.TestCase):

    def test_get_conversation_id_by_email(self):
        res = get_conversation_id_from_email('test@gmail.com')
        self.assertEqual(res,'2a4427fe77d2f0d2')
        res = get_conversation_id_from_email('test@not_a_user.com')
        self.assertEqual(res, None)

if __name__ == '__main__':
    unittest.main()

the tested function:

def get_conversation_id_from_email(email_user):
    """
    Args:
      email_user: the email user

    Returns:
       the conversation id
    """
    user_list = User.query(User.emails == email_user).fetch(use_cache=True, use_memcache=True)
    if len(user_list) == 0:
        return None
    for user_match in user_list:
        return user_match.device_ids[0]

Aucun commentaire:

Enregistrer un commentaire