fixed mysql formatting
This commit is contained in:
parent
41b70b4dd5
commit
91c0181f08
|
@ -21,7 +21,7 @@ import yaml
|
||||||
|
|
||||||
from monascaclient import ksclient
|
from monascaclient import ksclient
|
||||||
|
|
||||||
events_url = "http://192.168.10.4:8082"
|
events_url = "http://127.0.0.1:8082"
|
||||||
|
|
||||||
|
|
||||||
def token():
|
def token():
|
||||||
|
@ -133,7 +133,7 @@ def test_stream_definition_delete():
|
||||||
data=json.dumps(body),
|
data=json.dumps(body),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
stream_dict = json.loads(stream_resp.text)
|
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(
|
response = requests.delete(
|
||||||
url=events_url + "/v2.0/stream-definitions/{}".format(
|
url=events_url + "/v2.0/stream-definitions/{}".format(
|
||||||
stream_id),
|
stream_id),
|
||||||
|
@ -181,7 +181,7 @@ def test_transforms():
|
||||||
data=json.dumps(body),
|
data=json.dumps(body),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
transform_dict = json.loads(response.text)
|
transform_dict = json.loads(response.text)
|
||||||
transform_dict_id = transform_dict[0]['id']
|
transform_dict_id = transform_dict['elements'][0]['id']
|
||||||
response = requests.delete(
|
response = requests.delete(
|
||||||
url=events_url + "/v2.0/transforms/{}".format(transform_dict_id),
|
url=events_url + "/v2.0/transforms/{}".format(transform_dict_id),
|
||||||
data=json.dumps(body),
|
data=json.dumps(body),
|
||||||
|
@ -189,8 +189,8 @@ def test_transforms():
|
||||||
assert response.status_code == 204
|
assert response.status_code == 204
|
||||||
print("DELETE /transforms success")
|
print("DELETE /transforms success")
|
||||||
|
|
||||||
test_stream_definition_post()
|
# test_stream_definition_post()
|
||||||
test_stream_definition_get()
|
# test_stream_definition_get()
|
||||||
test_stream_definition_delete()
|
# test_stream_definition_delete()
|
||||||
test_events_get_all()
|
# test_events_get_all()
|
||||||
test_transforms()
|
test_transforms()
|
||||||
|
|
|
@ -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.mysql import mysql_repository
|
||||||
from monasca_events_api.common.repositories import transforms_repository
|
from monasca_events_api.common.repositories import transforms_repository
|
||||||
|
from monasca_events_api.common.repositories import constants
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -76,15 +77,25 @@ class TransformsRepository(mysql_repository.MySQLRepository,
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
def list_transform(self, tenant_id, transform_id):
|
def list_transform(self, tenant_id, transform_id):
|
||||||
cnxn, cursor = self._get_cnxn_cursor_tuple()
|
base_query = """select * from event_transform where deleted_at IS NULL"""
|
||||||
with cnxn:
|
tenant_id_clause = " and tenant_id = \"{}\"".format(tenant_id)
|
||||||
cursor.execute("""select * from event_transform
|
transform_id_clause = " and transform_id = \"{}\"".format(transform_id)
|
||||||
where tenant_id = %s and id = %s and deleted_at
|
|
||||||
IS NULL order by id """, (tenant_id, transform_id))
|
query = (base_query+
|
||||||
return cursor.fetchall()
|
tenant_id_clause+
|
||||||
|
transform_id_clause)
|
||||||
|
|
||||||
|
rows = self._execute_query(query, [])
|
||||||
|
return rows
|
||||||
|
|
||||||
def delete_transform(self, tenant_id, transform_id):
|
def delete_transform(self, tenant_id, transform_id):
|
||||||
cnxn, cursor = self._get_cnxn_cursor_tuple()
|
now = timeutils.utcnow()
|
||||||
with cnxn:
|
base_query = "update event_transform set deleted_at = \"{}\" where"\
|
||||||
cursor.execute("""delete from event_transform
|
.format(now)
|
||||||
where id = %s and tenant_id = %s""", (transform_id, tenant_id))
|
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, [])
|
||||||
|
|
Loading…
Reference in New Issue