def test_query_user(self): q = Query('0%user') result = q.send_request() user0_file = open('json/user0.json', 'r') user0_data = json.load(user0_file) user0_file.close() self.assertEqual(result['user'], user0_data)
def test_query_route(self): q = Query('0%route') result = q.send_request() route0_file = open('json/route0.json', 'r') route0_data = json.load(route0_file) route0_file.close() self.assertEqual(result['route'], route0_data)
def test_hardest(self): q = Query('0%hardest') result = q.send_request() route_file = open('json/route0.json', 'r') route_data = json.load(route_file) self.assertEqual(result['hardest']['boulder'], route_data) route_file.close()
def test_unpopular(self): q = Query('0+1%unpopular') result = q.send_request() route0_file = open('json/route0.json', 'r') route0_data = json.load(route0_file) route0_file.close() route1_file = open('json/route1.json', 'r') route1_data = json.load(route1_file) route1_file.close() self.assertEqual(result['unpopular'][0], route0_data) self.assertEqual(result['unpopular'][1], route1_data)
def exec_query(query_str: str): try: q = Query(query_str) return jsonify(q.send_request()) except: return make_response(jsonify({'error': 'Bad request'}), 400)
def test_request_vis_empty(self): q = Query('0+1%vis') self.assertTrue(True)
def test_hardest_invalid_route_t(self): with self.assertRaises(Exception) as context: q = Query('0%hardest-blob')
def test_bad_single_query_user(self): with self.assertRaises(KeyError) as context: q = Query('3%user')
def test_malformed_single_query(self): with self.assertRaises(Exception) as context: q = Query('0%boi')
def test_duplicate_users_error(self): with self.assertRaises(KeyError) as context: q = Query('2+2%tick')
def test_bad_users(self): with self.assertRaises(KeyError) as context: q = Query('2+3%tick')
def test_invalid_query(self): with self.assertRaises(Exception) as context: q = Query('0+1%tock')
def test_tick_failure(self): q = Query('0+1%tick') result = q.send_request() self.assertEqual(len(result['tick']), 0)
def test_todo_success(self): q = Query('0+1%todo') result = q.send_request() self.assertEqual(len(result['todo']), 1)
def test_all(self): q = Query('200305518+200696013%all') result = q.send_request() pprint(result)
from flask import Flask, jsonify, request, jsonify from flask_cors import CORS from flask_sqlalchemy import SQLAlchemy from src.api.query import Query # configuration DEBUG = True # instantiate the app app = Flask(__name__) app.config['JSON_SORT_KEYS'] = False app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost:5432/postgres' db = SQLAlchemy(app) query = Query(db) # enable CORS CORS(app, resources={r'/*': {'origins': '*'}}) @app.route('/', methods=['GET']) def root(): return jsonify({ '/values': '5dklik degerlerinin Json olarak sunulmasi', '/avg': 'ortalama degerinin sunulmasi', '/all': 'Bitcoin degerlerinin hepsini return eder.' }) @app.route('/values', methods=['GET']) def fiveMinutes():