def upd_out_msg(msg_out_id, subject, message, metadata, session): new_subject = subject new_message = message new_stamp = datetime.datetime.now() msg_outbound = Table("msg_outbound", metadata, autoload=True) upd = ( msg_outbound.update() .values(subject=new_subject, message=new_message, cb_date=new_stamp) .where(msg_outbound.c.msg_out_id == msg_out_id) ) session.execute(upd) session.commit()
def insert_outbound( reg_num, msg_in_id, node_id, subject, message, metadata, session ): stamp = datetime.datetime.now() msg_out = Table("msg_outbound", metadata, autoload=True) i = insert(msg_out) i = i.values( { "msg_in_id": msg_in_id, "node_id": node_id, "reg_num": reg_num, "subject": subject, "message": message, "cb_date": stamp, } ) session.execute(i)
def proc_link(link_url, metadata, session): # Find URL in DB the_url = str(link_url) status = SVC_Google.link_exists(the_url, metadata) if status[0] == True: # logger.debug("Link Exists, pulling the existing link_code") link_code = status[1] else: # logger.debug("Link Does Not Exists, entering the link into the DB and recovering the code") safe_link = str(link_url) safe_link = safe_link[:511] links = Table("links", metadata, autoload=True) i = insert(links) i = i.values({"link_url": safe_link}) session.execute(i) session.commit() SVC_Google.link_codes(metadata, session) status = SVC_Google.link_exists(link_url, metadata) link_code = status[1] return link_code
def link_codes(metadata, session): links = Table("links", metadata, autoload=True) qry = links.select().where(links.c.link_code == None) res = qry.execute() rowcount = len(res._saved_cursor._result.rows) link_rows = {} cnt = 0 for row in res: link_rows[cnt] = dict(row) link_row = link_rows[cnt] # logger.debug(link_rows[cnt]) cnt += 1 link_id = link_row["link_id"] link_code = SVC_Google.int_to_base36(link_id) # Got B36 Encoding, update link_code links = Table("links", metadata, autoload=True) upd = ( links.update() .values(link_code=link_code) .where(links.c.link_id == link_id) ) session.execute(upd) session.commit()
def test_locations_and_stations(self): session.execute( """INSERT INTO locations (bucket, name, id, description, environment_category, image, position) VALUES (%s, %s, %s, %s, %s, %s, %s)""", (0, 'Test Location', 'test_location', Description( 'Test Location short description', 'Test Location long description'), 'Test Location Category', b'f81a682ca20e7ab00aa4', Position(0.0, 180.0))) session.execute( """INSERT INTO stations_by_location (location_id, station_name, station_id, station_description, station_environment_category, station_image, station_position) VALUES (%s, %s, %s, %s, %s, %s, %s)""", ('test_location', 'Test Station', 'test_station', Description('Test Station short description', 'Test Station long description'), 'Test Station Category', None, Position(30.0, 150.0))) response = self.app.get('/api/locations_and_stations/0') expected_result = [{ "id": "test_location", "name": "Test Location", "description": { "short_description": "Test Location short description", "long_description": "Test Location long description" }, "environment_category": "Test Location Category", "bucket": 0, "image": "ZjgxYTY4MmNhMjBlN2FiMDBhYTQ=", "location_stations": [{ "station_name": "Test Station", "station_image": None, "station_description": { "short_description": "Test Station short description", "long_description": "Test Station long description" }, "station_environment_category": "Test Station Category", "station_position": { "longitude": 150.0, "latitude": 30.0 }, "station_id": "test_station", "location_id": "test_location" }], "position": { "longitude": 180.0, "latitude": 0.0 } }] response_data_decoded = json.loads(response.data.decode('utf-8')) self.assertEqual(len(expected_result), len(response_data_decoded)) for location_expected, location_response in zip( expected_result, response_data_decoded): self.assertDictEqual(location_expected, location_response) session.execute( "DELETE FROM locations WHERE bucket=%s AND name=%s AND id=%s", (0, 'Test Location', 'test_location')) session.execute( "DELETE FROM stations_by_location WHERE location_id=%s AND station_name=%s and station_id=%s", ('test_location', 'Test Station', 'test_station'))