diff --git a/luncho/blueprints/users.py b/luncho/blueprints/users.py index fa984ba..f4ff0b3 100644 --- a/luncho/blueprints/users.py +++ b/luncho/blueprints/users.py @@ -5,14 +5,14 @@ from flask import Blueprint from flask import request -# from flask import jsonify +from flask import jsonify # from flask import current_app from pony.orm import commit from luncho.helpers import ForceJSON -from luncho.database import User +from luncho.server import User users = Blueprint('users', __name__) diff --git a/luncho/helpers.py b/luncho/helpers.py index 643d936..2b9cca9 100644 --- a/luncho/helpers.py +++ b/luncho/helpers.py @@ -8,6 +8,7 @@ from functools import wraps from flask import request from flask import jsonify + class ForceJSON(object): def __init__(self, required=None): self.required = required or [] @@ -18,18 +19,19 @@ class ForceJSON(object): json = request.get_json(force=True, silent=True) if not json: return jsonify(status='ERROR', - error='Request MUST be in JSON format'), 400 + error='Request MUST be in JSON format'), 400 # now we have the JSON, let's check if all the fields are here. missing = [] - for field in required or []: + for field in self.required or []: if not field in json: missing.append(field) if missing: + fields = ', '.join(missing) + error = 'Missing fields: {fields}'.format(fields=fields) return jsonify(status='ERROR', - error='Missing fields: {fields}'.format( - fields=', '.join(missing))) + error=error) return func(*args, **kwargs) return check_json diff --git a/tests/users_tests.py b/tests/users_tests.py index c4262ef..74c29a7 100644 --- a/tests/users_tests.py +++ b/tests/users_tests.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- encoding: utf-8 -*- -import os import tempfile import unittest import json @@ -13,17 +12,23 @@ class TestUsers(unittest.TestCase): """Test users request.""" def setUp(self): - (_, server.app.config['SQLITE_FILENAME']) = tempfile.mkstemp() + (_, name) = tempfile.mkstemp() + + server.app.config['SQLITE_FILENAME'] = name + server.app.config['TESTING'] = True + + print server.app.config['SQLITE_FILENAME'] self.app = server.app.test_client() def tearDown(self): - os.unlick(server.app.config['SQLITE_FILENAME']) + # os.unlink(server.app.config['SQLITE_FILENAME']) + pass def test_create_user(self): request = {'username': 'username', 'full_name': 'full name', 'password': 'hash'} - rv = self.app.put('/users/', + rv = self.app.put('/user/', data=json.dumps(request), content_type='application/json') print rv.data