Add GET /user/ implementation that works
Previously my GET was just a placeholder so I could build URIs against it. Now it actually works and returns information on a user
This commit is contained in:
parent
69228f21ca
commit
6a2cb087fc
|
@ -2,6 +2,8 @@ import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import vanth.platform.user
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('db')
|
@pytest.mark.usefixtures('db')
|
||||||
def test_post(client):
|
def test_post(client):
|
||||||
|
@ -13,3 +15,13 @@ def test_post(client):
|
||||||
response = client.post('/user/', data=json.dumps(data))
|
response = client.post('/user/', data=json.dumps(data))
|
||||||
assert response.status_code == 204
|
assert response.status_code == 204
|
||||||
assert response.headers['Location']
|
assert response.headers['Location']
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('db')
|
||||||
|
def test_get(client):
|
||||||
|
location = vanth.platform.user.create('Blue Stahli', 'blue@stahli.com', 'metamorphosis')
|
||||||
|
response = client.get(location)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json == {
|
||||||
|
'name' : 'Blue Stahli',
|
||||||
|
'username' : 'blue@stahli.com',
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import sepiida.endpoints
|
import sepiida.endpoints
|
||||||
|
import sepiida.errors
|
||||||
import sepiida.fields
|
import sepiida.fields
|
||||||
|
|
||||||
import vanth.platform.user
|
import vanth.platform.user
|
||||||
|
@ -8,7 +9,7 @@ class User(sepiida.endpoints.APIEndpoint):
|
||||||
ENDPOINT = '/user/'
|
ENDPOINT = '/user/'
|
||||||
SIGNATURE = sepiida.fields.JSONObject(s={
|
SIGNATURE = sepiida.fields.JSONObject(s={
|
||||||
'name' : sepiida.fields.String(),
|
'name' : sepiida.fields.String(),
|
||||||
'password' : sepiida.fields.String(),
|
'password' : sepiida.fields.String(methods=['POST', 'PUT']),
|
||||||
'username' : sepiida.fields.String(),
|
'username' : sepiida.fields.String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -19,5 +20,8 @@ class User(sepiida.endpoints.APIEndpoint):
|
||||||
return None, 204, {'Location': uri}
|
return None, 204, {'Location': uri}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(uuid): # pylint: disable=unused-argument
|
def get(uuid):
|
||||||
return {}
|
users = vanth.platform.user.by_filter({'uuid': [str(uuid)]})
|
||||||
|
if not users:
|
||||||
|
raise sepiida.errors.ResourceNotFound()
|
||||||
|
return users[0]
|
||||||
|
|
|
@ -1,12 +1,25 @@
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import chryso.connection
|
import chryso.connection
|
||||||
|
import chryso.queryadapter
|
||||||
import passlib.apps
|
import passlib.apps
|
||||||
import sepiida.routing
|
import sepiida.routing
|
||||||
|
|
||||||
import vanth.tables
|
import vanth.tables
|
||||||
|
|
||||||
|
|
||||||
|
def by_filter(filters):
|
||||||
|
engine = chryso.connection.get()
|
||||||
|
|
||||||
|
query = vanth.tables.User.select()
|
||||||
|
query = chryso.queryadapter.map_and_filter(vanth.tables.User, filters, query)
|
||||||
|
results = engine.execute(query).fetchall()
|
||||||
|
return [{
|
||||||
|
'username' : result[vanth.tables.User.c.username],
|
||||||
|
'password' : result[vanth.tables.User.c.password],
|
||||||
|
'name' : result[vanth.tables.User.c.name],
|
||||||
|
} for result in results]
|
||||||
|
|
||||||
def create(name, username, password):
|
def create(name, username, password):
|
||||||
engine = chryso.connection.get()
|
engine = chryso.connection.get()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue