Skip to content

Commit

Permalink
adding schema_utils.py to project
Browse files Browse the repository at this point in the history
  • Loading branch information
lockefox committed Apr 10, 2018
1 parent e2bde07 commit 597b12f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include prosper/test_utils/version.txt
include prosper/test_utils/version.txt
include prosper/test_utils/root_schema.schema
Empty file.
61 changes: 61 additions & 0 deletions prosper/test_utils/schema_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""schema testers"""
import json
import logging
import pathlib


import genson
import pymongo
import semantic_version


ROOT_SCHEMA = pathlib.Path(__file__).parent / 'root_schema.schema'

class MongoContextManager:
"""context manager for mongo connections
Notes:
connection_str requires {username}, {password} format strings
Args:
username (str): MongoDB Username
password (str): MongoDB Password
connection_str (str): connection string to platform
"""
logger = logging.getLogger('PROSPER__test_helper')
def __init__(self, username, password, connection_str):
self.username = username
self.password = password
self.connection_str = connection_str
self._testmode = False
self._testmode_filepath = pathlib.Path(__file__).parent / 'testdb.json'

# TODO: validate {} in connection_str

def __get_connector(self):
"""switches between testmode/prod connectors
Returns:
pymongo.MongoCollection: connection to mongodb
"""
if self._testmode:
import tinymongo
return tinymongo.TinyMongoClient(self._testmode_filepath)

return pymongo.MongoClient(
self.connection_str.format(
username=self.username,
password=self.password,
)
)

def __enter__(self):
"""with MongoContextManager() entrypoint"""
self.connection = self.__get_connector()
return self.connection

def __exit__(self, *exc):
"""with MongoContextManager() exitpoint"""
self.connection_str.close()
17 changes: 14 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class PyTest(TestCommand):
http://doc.pytest.org/en/latest/goodpractices.html#manual-integration
"""
user_options = [('pytest-args=', 'a', 'Arguments to pass to pytest')]
user_options = [
('pytest-args=', 'a', 'Arguments to pass to pytest')

]

def initialize_options(self):
TestCommand.initialize_options(self)
Expand Down Expand Up @@ -99,24 +102,32 @@ def run_tests(self):
packages=hack_find_packages('prosper'),
include_package_data=True,
package_data={
'': ['LICENSE', 'README.rst'],
'': ['LICENSE', 'README.rst', ],
'prosper': [
'test_utils/root_schema.schema',
'test_utils/version.txt',
],
},
python_requires='>=3.5',
install_requires=[
'prospercommon',
'requests',
'semantic_version',
'plumbum',
'docker',
'genson',
'pymongo[tls]',
],
tests_require=[
'pytest',
'pytest_cov',
'tinymongo',
],
extras_require={
'dev':[
'sphinx',
'sphinxcontrib-napoleon',
]
],
},
cmdclass={
'test':PyTest,
Expand Down

0 comments on commit 597b12f

Please sign in to comment.