diff --git a/panko/tests/functional/gabbi/fixtures.py b/panko/tests/functional/gabbi/fixtures.py index 8e1299c2..4f56df17 100644 --- a/panko/tests/functional/gabbi/fixtures.py +++ b/panko/tests/functional/gabbi/fixtures.py @@ -26,6 +26,7 @@ from oslo_policy import opts from oslo_utils import fileutils import six from six.moves.urllib import parse as urlparse +import sqlalchemy_utils from panko.api import app from panko.event.storage import models @@ -44,12 +45,6 @@ def setup_app(): return app.load_app(**LOAD_APP_KWARGS) -# TODO(chdent): For now only MongoDB is supported, because of easy -# database name handling and intentional focus on the API, not the -# data store. -ENGINES = ['mongodb'] - - class ConfigFixture(fixture.GabbiFixture): """Establish the relevant configuration for a test run.""" @@ -66,10 +61,6 @@ class ConfigFixture(fixture.GabbiFixture): if not db_url: raise case.SkipTest('No database connection configured') - engine = urlparse.urlparse(db_url).scheme - if engine not in ENGINES: - raise case.SkipTest('Database engine not supported') - conf = self.conf = service.prepare_service([], []) opts.set_defaults(self.conf) @@ -88,16 +79,28 @@ class ConfigFixture(fixture.GabbiFixture): 'panko/tests/functional/gabbi/gabbi_paste.ini') ) - database_name = '%s-%s' % (db_url, str(uuid.uuid4())) - conf.set_override('connection', database_name, group='database') + parsed_url = list(urlparse.urlparse(db_url)) + parsed_url[2] += '-%s' % str(uuid.uuid4()).replace('-', '') + db_url = urlparse.urlunparse(parsed_url) + + conf.set_override('connection', db_url, group='database') conf.set_override('event_connection', '', group='database') + if (parsed_url[0].startswith("mysql") + or parsed_url[0].startswith("postgresql")): + sqlalchemy_utils.create_database(conf.database.connection) + + self.conn = storage.get_connection_from_config(self.conf) + self.conn.upgrade() + LOAD_APP_KWARGS = { 'conf': conf, } def stop_fixture(self): """Reset the config and remove data.""" + if self.conn: + self.conn.clear() if self.conf: storage.get_connection_from_config(self.conf).clear() @@ -108,10 +111,6 @@ class EventDataFixture(ConfigFixture): def start_fixture(self): """Create some events.""" super(EventDataFixture, self).start_fixture() - self.conn = None - if not self.conf: - return - self.conn = storage.get_connection_from_config(self.conf) events = [] name_list = ['chocolate.chip', 'peanut.butter', 'sugar'] for ix, name in enumerate(name_list): @@ -126,12 +125,6 @@ class EventDataFixture(ConfigFixture): events.append(event) self.conn.record_events(events) - def stop_fixture(self): - """Destroy the events.""" - if self.conn: - self.conn.db.event.remove({'event_type': '/^cookies_/'}) - super(EventDataFixture, self).stop_fixture() - class CORSConfigFixture(fixture.GabbiFixture): """Inject mock configuration for the CORS middleware.""" diff --git a/panko/tests/functional/gabbi/gabbits/api-events-with-data.yaml b/panko/tests/functional/gabbi/gabbits/api-events-with-data.yaml index 0209db46..ec3053d7 100644 --- a/panko/tests/functional/gabbi/gabbits/api-events-with-data.yaml +++ b/panko/tests/functional/gabbi/gabbits/api-events-with-data.yaml @@ -14,19 +14,20 @@ tests: X-Project-Id: project1 response_headers: content-type: application/json; charset=UTF-8 + verbose: True response_json_paths: - $.[0].event_type: cookies_chocolate.chip - $.[0].traits.[0].value: chocolate.chip - $.[0].traits.[1].value: '0' - $.[0].raw.nested.inside: value - $.[1].event_type: cookies_peanut.butter - $.[1].traits.[0].name: type - $.[1].traits.[1].name: ate - $.[1].raw.nested.inside: value - $.[2].event_type: cookies_sugar - $.[2].traits.[0].type: string - $.[2].traits.[1].type: integer - $.[2].raw.nested.inside: value + $[/event_type].[0].event_type: cookies_chocolate.chip + $[/event_type].[0].traits[/value].[0].value: '0' + $[/event_type].[0].traits[/value].[1].value: chocolate.chip + $[/event_type].[0].raw.nested.inside: value + $[/event_type].[1].event_type: cookies_peanut.butter + $[/event_type].[1].traits[/name].[0].name: ate + $[/event_type].[1].traits[/name].[1].name: type + $[/event_type].[1].raw.nested.inside: value + $[/event_type].[2].event_type: cookies_sugar + $[/event_type].[2].traits[/type].[0].type: integer + $[/event_type].[2].traits[/type].[1].type: string + $[/event_type].[2].raw.nested.inside: value # this attempts to get all the events with invalid parameters and expects a 400 - name: get events with bad params @@ -48,8 +49,8 @@ tests: response_headers: content-type: application/json; charset=UTF-8 response_json_paths: - $.[0].event_type: cookies_chocolate.chip - $.[0].traits.[0].value: chocolate.chip + $[/event_type].[0].event_type: cookies_chocolate.chip + $[/event_type].[0].traits[/value].[1].value: chocolate.chip # this attempts to query the events with the correct data query syntax and # expects a matching event @@ -69,8 +70,8 @@ tests: response_headers: content-type: application/json; charset=UTF-8 response_json_paths: - $.[0].event_type: cookies_chocolate.chip - $.[0].traits.[0].value: chocolate.chip + $[/event_type].[0].event_type: cookies_chocolate.chip + $[/event_type].[0].traits[/value].[1].value: chocolate.chip # this attempts to query the events with the correct parameterized query syntax # but a bad field name and expects an empty list @@ -132,8 +133,8 @@ tests: content-type: application/json; charset=UTF-8 response_json_paths: $.event_type: cookies_chocolate.chip - $.traits.[0].value: chocolate.chip - $.traits.[1].value: '0' + $.traits[/value].[0].value: '0' + $.traits[/value].[1].value: chocolate.chip # Get a single event by message_id no data is present so should return a 404 - name: get a single event that does not exist diff --git a/test-requirements.txt b/test-requirements.txt index 128e98ec..e478470c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -24,3 +24,4 @@ os-testr>=0.4.1 # Apache-2.0 WebTest>=2.0 # MIT pifpaf>=0.0.11 reno +sqlalchemy-utils