Feature/tox test (#138)
* chg: test: mark slow test * new: test: config for tox * chg: test: mark function as non tox
This commit is contained in:
parent
0c7d5cfe97
commit
e2989b0dcc
19
api/requirements.txt
Normal file
19
api/requirements.txt
Normal file
@ -0,0 +1,19 @@
|
||||
appdirs==1.4.1
|
||||
beautifulsoup4==4.5.3
|
||||
buku==2.9
|
||||
cffi==1.9.1
|
||||
click==6.7
|
||||
cryptography==1.7.2
|
||||
Flask==0.12
|
||||
idna==2.2
|
||||
itsdangerous==0.24
|
||||
Jinja2==2.9.5
|
||||
MarkupSafe==0.23
|
||||
packaging==16.8
|
||||
pyasn1==0.2.2
|
||||
pycparser==2.17
|
||||
pyparsing==2.1.10
|
||||
requests==2.13.0
|
||||
six==1.10.0
|
||||
urllib3==1.20
|
||||
Werkzeug==0.11.15
|
78
api/server.py
Normal file
78
api/server.py
Normal file
@ -0,0 +1,78 @@
|
||||
from buku import BukuDb
|
||||
from flask import Flask, jsonify, request
|
||||
|
||||
|
||||
bukudb = BukuDb()
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/api/tags', methods=['GET'])
|
||||
def get_tags():
|
||||
tags = bukudb.get_tag_all()
|
||||
result = {
|
||||
'tags': tags[0]
|
||||
}
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@app.route('/api/bookmarks', methods=['GET', 'POST'])
|
||||
def bookmarks():
|
||||
if request.method == 'GET':
|
||||
bookmarks = bukudb.get_rec_all()
|
||||
result = {
|
||||
'bookmarks': []
|
||||
}
|
||||
for bookmark in bookmarks:
|
||||
result_bookmark = {
|
||||
'url': bookmark[1],
|
||||
'title': bookmark[2],
|
||||
'tags': list(filter(None, bookmark[3].split(','))),
|
||||
'description': bookmark[4]
|
||||
}
|
||||
result['bookmarks'].append(result_bookmark)
|
||||
return jsonify(result)
|
||||
elif request.method == 'POST':
|
||||
result_flag = bukudb.add_rec(request.form['url'], request.form['title'],
|
||||
request.form['tags'], request.form['description'])
|
||||
if result_flag:
|
||||
return jsonify({'status': 0, 'message': 'success'}), 200, {'ContentType': 'application/json'}
|
||||
else:
|
||||
return jsonify({'status': 1, 'message': 'failure'}), 400, {'ContentType': 'application/json'}
|
||||
|
||||
@app.route('/api/bookmarks/<id>', methods=['GET', 'PUT', 'DELETE'])
|
||||
def bookmark_api(id):
|
||||
try:
|
||||
id = int(id)
|
||||
except ValueError:
|
||||
return jsonify({'status': 1, 'message': 'failure'}), 400, {'ContentType': 'application/json'}
|
||||
if request.method == 'GET':
|
||||
bookmark = bukudb.get_rec_by_id(id)
|
||||
if bookmark is not None:
|
||||
result = {
|
||||
'url': bookmark[1],
|
||||
'title': bookmark[2],
|
||||
'tags': list(filter(None, bookmark[3].split(','))),
|
||||
'description': bookmark[4]
|
||||
}
|
||||
return jsonify(result)
|
||||
else:
|
||||
return jsonify({'status': 1, 'message': 'failure'}), 400, {'ContentType': 'application/json'}
|
||||
elif request.method == 'PUT':
|
||||
result_flag = bukudb.update_rec(id, request.form['url'], request.form.get('title'),
|
||||
request.form['tags'], request.form['description'])
|
||||
if result_flag:
|
||||
return jsonify({'status': 0, 'message': 'success'}), 200, {'ContentType': 'application/json'}
|
||||
else:
|
||||
return jsonify({'status': 1, 'message': 'failure'}), 400, {'ContentType': 'application/json'}
|
||||
else:
|
||||
result_flag = bukudb.delete_rec(id)
|
||||
if result_flag:
|
||||
return jsonify({'status': 0, 'message': 'success'}), 200, {'ContentType': 'application/json'}
|
||||
else:
|
||||
return jsonify({'status': 1, 'message': 'failure'}), 400, {'ContentType': 'application/json'}
|
||||
|
||||
def run():
|
||||
app.run(debug=True)
|
||||
|
||||
run()
|
@ -68,6 +68,7 @@ class TestBukuDb(unittest.TestCase):
|
||||
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
@pytest.mark.non_tox
|
||||
def test_get_default_dbdir(self):
|
||||
dbdir_expected = TEST_TEMP_DBDIR_PATH
|
||||
dbdir_local_expected = os.path.join(os.path.expanduser('~'), '.local', 'share', 'buku')
|
||||
@ -226,6 +227,7 @@ class TestBukuDb(unittest.TestCase):
|
||||
self.assertNotIn(to_delete, from_db)
|
||||
|
||||
# @unittest.skip('skipping')
|
||||
@pytest.mark.slowtest
|
||||
def test_refreshdb(self):
|
||||
self.bdb.add_rec("https://www.google.com/ncr", "?")
|
||||
self.bdb.refreshdb(1, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user