Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/a158972595146231_parallel_testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Aug 16, 2016
2 parents 934f857 + fa1a678 commit 59af404
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/openprocurement/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
"""Main entry point
"""
import gevent.monkey
gevent.monkey.patch_all()
if 'test' not in __import__('sys').argv[0]:
import gevent.monkey
gevent.monkey.patch_all()
import os
from boto.s3.connection import S3Connection, Location
from couchdb import Server as CouchdbServer, Session
Expand Down
39 changes: 32 additions & 7 deletions src/openprocurement/api/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from openprocurement.api.models import SANDBOX_MODE
from openprocurement.api.utils import VERSION, apply_data_patch
from openprocurement.api.design import sync_design


now = datetime.now()
Expand Down Expand Up @@ -211,17 +212,42 @@ class BaseWebTest(unittest.TestCase):
It setups the database before each test and delete it after.
"""

relative_to = os.path.dirname(__file__)

@classmethod
def setUpClass(cls):
while True:
try:
cls.app = webtest.TestApp("config:tests.ini", relative_to=cls.relative_to)
except:
pass
else:
break
cls.app.RequestClass = PrefixedRequestClass
cls.couchdb_server = cls.app.app.registry.couchdb_server
cls.db = cls.app.app.registry.db
cls.db_name = cls.db.name

@classmethod
def tearDownClass(cls):
try:
cls.couchdb_server.delete(cls.db_name)
except:
pass

def setUp(self):
self.app = webtest.TestApp(
"config:tests.ini", relative_to=os.path.dirname(__file__))
self.app.RequestClass = PrefixedRequestClass
self.db_name += uuid4().hex
self.couchdb_server.create(self.db_name)
db = self.couchdb_server[self.db_name]
sync_design(db)
self.app.app.registry.db = db
self.db = self.app.app.registry.db
self.db_name = self.db.name
self.app.authorization = ('Basic', ('token', ''))
#self.app.authorization = ('Basic', ('broker', ''))
self.couchdb_server = self.app.app.registry.couchdb_server
self.db = self.app.app.registry.db

def tearDown(self):
del self.couchdb_server[self.db.name]
self.couchdb_server.delete(self.db_name)


class BaseTenderWebTest(BaseWebTest):
Expand Down Expand Up @@ -432,5 +458,4 @@ def create_tender(self):
self.set_status(self.initial_status)

def tearDown(self):
del self.db[self.tender_id]
super(BaseTenderWebTest, self).tearDown()
4 changes: 4 additions & 0 deletions src/openprocurement/api/tests/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class MigrateTest(BaseWebTest):

def setUp(self):
super(MigrateTest, self).setUp()
migrate_data(self.couchdb_server[self.db_name])

def test_migrate(self):
self.assertEqual(get_db_schema_version(self.db), SCHEMA_VERSION)
migrate_data(self.db, 1)
Expand Down

0 comments on commit 59af404

Please sign in to comment.