예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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()
예제 #4
0
 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)
예제 #5
0
파일: app.py 프로젝트: whwjiang/mp-viz
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)
예제 #6
0
 def test_request_vis_empty(self):
     q = Query('0+1%vis')
     self.assertTrue(True)
예제 #7
0
 def test_hardest_invalid_route_t(self):
     with self.assertRaises(Exception) as context:
         q = Query('0%hardest-blob')
예제 #8
0
 def test_bad_single_query_user(self):
     with self.assertRaises(KeyError) as context:
         q = Query('3%user')
예제 #9
0
 def test_malformed_single_query(self):
     with self.assertRaises(Exception) as context:
         q = Query('0%boi')
예제 #10
0
 def test_duplicate_users_error(self):
     with self.assertRaises(KeyError) as context:
         q = Query('2+2%tick')
예제 #11
0
 def test_bad_users(self):
     with self.assertRaises(KeyError) as context:
         q = Query('2+3%tick')
예제 #12
0
 def test_invalid_query(self):
     with self.assertRaises(Exception) as context:
         q = Query('0+1%tock')
예제 #13
0
 def test_tick_failure(self):
     q = Query('0+1%tick')
     result = q.send_request()
     self.assertEqual(len(result['tick']), 0)
예제 #14
0
 def test_todo_success(self):
     q = Query('0+1%todo')
     result = q.send_request()
     self.assertEqual(len(result['todo']), 1)
예제 #15
0
 def test_all(self):
     q = Query('200305518+200696013%all')
     result = q.send_request()
     pprint(result)
예제 #16
0
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():