Пример #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
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():