fixed mysql formatting

This commit is contained in:
SamKirsch10 2015-06-26 15:29:01 -06:00
parent 41b70b4dd5
commit 91c0181f08
2 changed files with 28 additions and 17 deletions

View File

@ -21,7 +21,7 @@ import yaml
from monascaclient import ksclient
events_url = "http://192.168.10.4:8082"
events_url = "http://127.0.0.1:8082"
def token():
@ -133,7 +133,7 @@ def test_stream_definition_delete():
data=json.dumps(body),
headers=headers)
stream_dict = json.loads(stream_resp.text)
stream_id = str(stream_dict[0]['id'])
stream_id = str(stream_dict[0]['elements']['id'])
response = requests.delete(
url=events_url + "/v2.0/stream-definitions/{}".format(
stream_id),
@ -181,7 +181,7 @@ def test_transforms():
data=json.dumps(body),
headers=headers)
transform_dict = json.loads(response.text)
transform_dict_id = transform_dict[0]['id']
transform_dict_id = transform_dict['elements'][0]['id']
response = requests.delete(
url=events_url + "/v2.0/transforms/{}".format(transform_dict_id),
data=json.dumps(body),
@ -189,8 +189,8 @@ def test_transforms():
assert response.status_code == 204
print("DELETE /transforms success")
test_stream_definition_post()
test_stream_definition_get()
test_stream_definition_delete()
test_events_get_all()
# test_stream_definition_post()
# test_stream_definition_get()
# test_stream_definition_delete()
# test_events_get_all()
test_transforms()

View File

@ -18,6 +18,7 @@ from oslo_utils import timeutils
from monasca_events_api.common.repositories.mysql import mysql_repository
from monasca_events_api.common.repositories import transforms_repository
from monasca_events_api.common.repositories import constants
LOG = log.getLogger(__name__)
@ -76,15 +77,25 @@ class TransformsRepository(mysql_repository.MySQLRepository,
return rows
def list_transform(self, tenant_id, transform_id):
cnxn, cursor = self._get_cnxn_cursor_tuple()
with cnxn:
cursor.execute("""select * from event_transform
where tenant_id = %s and id = %s and deleted_at
IS NULL order by id """, (tenant_id, transform_id))
return cursor.fetchall()
base_query = """select * from event_transform where deleted_at IS NULL"""
tenant_id_clause = " and tenant_id = \"{}\"".format(tenant_id)
transform_id_clause = " and transform_id = \"{}\"".format(transform_id)
query = (base_query+
tenant_id_clause+
transform_id_clause)
rows = self._execute_query(query, [])
return rows
def delete_transform(self, tenant_id, transform_id):
cnxn, cursor = self._get_cnxn_cursor_tuple()
with cnxn:
cursor.execute("""delete from event_transform
where id = %s and tenant_id = %s""", (transform_id, tenant_id))
now = timeutils.utcnow()
base_query = "update event_transform set deleted_at = \"{}\" where"\
.format(now)
tenant_id_clause = " tenant_id = \"{}\"".format(tenant_id)
transform_id_clause = " and id = \"{}\"".format(transform_id)
query = (base_query +
tenant_id_clause +
transform_id_clause)
self._execute_query(query, [])