Browse Source

fixed the tests

master
Julio Biason 11 years ago
parent
commit
e466071888
  1. 4
      luncho/blueprints/users.py
  2. 8
      luncho/helpers.py
  3. 13
      tests/users_tests.py

4
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__)

8
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 []
@ -22,14 +23,15 @@ class ForceJSON(object):
# 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

13
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

Loading…
Cancel
Save