Advertisement
cmiN

conftest.py

Mar 8th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. """Setups and cleanups for Datastore related tests."""
  2.  
  3.  
  4. import os
  5.  
  6. import pytest
  7.  
  8. from <project>.models import BaseModel, ndb
  9.  
  10.  
  11. NO_CREDENTIALS = not bool(os.getenv("GOOGLE_APPLICATION_CREDENTIALS"))
  12.  
  13. skip_missing_credentials = pytest.mark.skipif(
  14.     NO_CREDENTIALS, reason="missing Datastore credentials"
  15. )
  16.  
  17.  
  18. class TrueStoryModel(BaseModel):
  19.  
  20.     bool_prop = ndb.BooleanProperty(default=False)
  21.     str_prop = ndb.StringProperty(
  22.         default="str_prop", choices=["str_prop", "string_prop"]
  23.     )
  24.     txt_prop = ndb.TextProperty(indexed=False)
  25.     list_prop = ndb.IntegerProperty(repeated=True)
  26.     auto_prop = ndb.ComputedProperty(lambda self: sum(self.list_prop))
  27.  
  28.  
  29. @pytest.fixture
  30. def truestory_model():
  31.     """Returns our default model in order to test the DB for basic functionality."""
  32.     return TrueStoryModel()
  33.  
  34.  
  35. @pytest.fixture(autouse=True, scope="session")
  36. def datastore_cleanup():
  37.     yield
  38.     if not NO_CREDENTIALS:
  39.         items = TrueStoryModel.all(keys_only=True)
  40.         TrueStoryModel.remove_multi([item.key for item in items])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement