|
|
@ -20,9 +20,7 @@ class TestUsers(LunchoTests): |
|
|
|
'full_name': 'full name', |
|
|
|
'full_name': 'full name', |
|
|
|
'password': 'hash'} |
|
|
|
'password': 'hash'} |
|
|
|
rv = self.put('/user/', request) |
|
|
|
rv = self.put('/user/', request) |
|
|
|
|
|
|
|
self.assertJsonOk(rv) |
|
|
|
self.assertStatusCode(rv, 200) |
|
|
|
|
|
|
|
self.assertJson(rv, {'status': 'OK'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# db check |
|
|
|
# db check |
|
|
|
self.assertIsNotNone(User.query.filter_by(username='username').first()) |
|
|
|
self.assertIsNotNone(User.query.filter_by(username='username').first()) |
|
|
@ -36,30 +34,19 @@ class TestUsers(LunchoTests): |
|
|
|
'full_name': 'full name', |
|
|
|
'full_name': 'full name', |
|
|
|
'password': 'hash'} |
|
|
|
'password': 'hash'} |
|
|
|
rv = self.put('/user/', data=request) |
|
|
|
rv = self.put('/user/', data=request) |
|
|
|
|
|
|
|
self.assertJsonError(rv, 409, 'Username already exists') |
|
|
|
expected = {"status": "ERROR", |
|
|
|
|
|
|
|
"error": "Username already exists"} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 409) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_json(self): |
|
|
|
def test_no_json(self): |
|
|
|
"""Do a request that it's not JSON.""" |
|
|
|
"""Do a request that it's not JSON.""" |
|
|
|
rv = self.put('/user/', '') |
|
|
|
rv = self.put('/user/', '') |
|
|
|
|
|
|
|
self.assertJsonError(rv, 400, 'Request MUST be in JSON format') |
|
|
|
expected = {"error": "Request MUST be in JSON format", |
|
|
|
|
|
|
|
"status": "ERROR"} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 400) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_fields(self): |
|
|
|
def test_missing_fields(self): |
|
|
|
"""Send a request with missing fields.""" |
|
|
|
"""Send a request with missing fields.""" |
|
|
|
request = {'password': 'hash'} |
|
|
|
request = {'password': 'hash'} |
|
|
|
rv = self.put('/user/', request) |
|
|
|
rv = self.put('/user/', request) |
|
|
|
|
|
|
|
self.assertJsonError(rv, 400, 'Missing fields', fields=['username', |
|
|
|
expected = {'error': 'Missing fields: username, full_name', |
|
|
|
'full_name']) |
|
|
|
'status': 'ERROR'} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 400) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestExistingUsers(LunchoTests): |
|
|
|
class TestExistingUsers(LunchoTests): |
|
|
@ -84,8 +71,7 @@ class TestExistingUsers(LunchoTests): |
|
|
|
request) |
|
|
|
request) |
|
|
|
|
|
|
|
|
|
|
|
expected = {'status': 'OK'} |
|
|
|
expected = {'status': 'OK'} |
|
|
|
self.assertStatusCode(rv, 200) |
|
|
|
self.assertJsonOk(rv) |
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# check in the database |
|
|
|
# check in the database |
|
|
|
user = User.query.filter_by(username='test').first() |
|
|
|
user = User.query.filter_by(username='test').first() |
|
|
@ -99,10 +85,7 @@ class TestExistingUsers(LunchoTests): |
|
|
|
rv = self.post('/user/{token}/'.format(token='no-token'), |
|
|
|
rv = self.post('/user/{token}/'.format(token='no-token'), |
|
|
|
request) |
|
|
|
request) |
|
|
|
|
|
|
|
|
|
|
|
expected = {'status': 'ERROR', |
|
|
|
self.assertJsonError(rv, 404, 'User not found (via token)') |
|
|
|
'error': 'User not found (via token)'} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 404) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_expired_token(self): |
|
|
|
def test_expired_token(self): |
|
|
|
"""Send a token that exists but it's not valid for today.""" |
|
|
|
"""Send a token that exists but it's not valid for today.""" |
|
|
@ -116,18 +99,12 @@ class TestExistingUsers(LunchoTests): |
|
|
|
rv = self.post('/user/{token}/'.format(token=self.user.token), |
|
|
|
rv = self.post('/user/{token}/'.format(token=self.user.token), |
|
|
|
request) |
|
|
|
request) |
|
|
|
|
|
|
|
|
|
|
|
expected = {'status': 'ERROR', |
|
|
|
self.assertJsonError(rv, 400, 'Invalid token') |
|
|
|
'error': 'Invalid token'} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 400) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete_user(self): |
|
|
|
def test_delete_user(self): |
|
|
|
"""Delete a user.""" |
|
|
|
"""Delete a user.""" |
|
|
|
rv = self.delete('/user/{token}/'.format(token=self.user.token)) |
|
|
|
rv = self.delete('/user/{token}/'.format(token=self.user.token)) |
|
|
|
|
|
|
|
self.assertJsonOk(rv) |
|
|
|
expected = {'status': 'OK'} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 200) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# check the database |
|
|
|
# check the database |
|
|
|
user = User.query.filter_by(username='test').first() |
|
|
|
user = User.query.filter_by(username='test').first() |
|
|
@ -137,10 +114,7 @@ class TestExistingUsers(LunchoTests): |
|
|
|
"""Send a delete to a non-existing token.""" |
|
|
|
"""Send a delete to a non-existing token.""" |
|
|
|
rv = self.delete('/user/{token}/'.format(token='no-token')) |
|
|
|
rv = self.delete('/user/{token}/'.format(token='no-token')) |
|
|
|
|
|
|
|
|
|
|
|
expected = {'status': 'ERROR', |
|
|
|
self.assertJsonError(rv, 404, 'User not found (via token)') |
|
|
|
'error': 'User not found (via token)'} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 404) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete_expired_token(self): |
|
|
|
def test_delete_expired_token(self): |
|
|
|
"""Send a delete to a token for yesterday.""" |
|
|
|
"""Send a delete to a token for yesterday.""" |
|
|
@ -150,10 +124,7 @@ class TestExistingUsers(LunchoTests): |
|
|
|
|
|
|
|
|
|
|
|
rv = self.delete('/user/{token}/'.format(token=self.user.token)) |
|
|
|
rv = self.delete('/user/{token}/'.format(token=self.user.token)) |
|
|
|
|
|
|
|
|
|
|
|
expected = {'status': 'ERROR', |
|
|
|
self.assertJsonError(rv, 400, 'Invalid token') |
|
|
|
'error': 'Invalid token'} |
|
|
|
|
|
|
|
self.assertStatusCode(rv, 400) |
|
|
|
|
|
|
|
self.assertJson(rv, expected) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|