Example #1
0
def test_application_schema_json_detail_view(admin_client):
    app = Application()
    app.title = u"My first application"
    app.firstname = u"John"
    app.lastname = u"Doe"
    app.email = u"*****@*****.**"
    app.save()

    response = admin_client.get("/application/{}/".format(app.id), HTTP_CONTENT_TYPE="application/schema+json")

    assert 200 == response.status_code
    assert "application/schema+json" in response.get("Content-Type")
    assert "title" in json.loads(response.content.decode()).get("properties")
Example #2
0
def test_application_schema_json_detail_view(admin_client):
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    response = admin_client.get('/application/{}/'.format(app.id),
                                HTTP_CONTENT_TYPE='application/schema+json')

    assert 200 == response.status_code
    assert 'application/schema+json' in response.get('Content-Type')
    assert 'title' in json.loads(response.content.decode()).get('properties')
Example #3
0
def test_application_json_list_view(admin_client):
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    response = admin_client.get('/application/',
                                HTTP_ACCEPT='application/json')

    assert 200 == response.status_code
    assert 'application/json' in response.get('Content-Type')
    assert u'PagedCollection' == json.loads(
        response.content.decode()).get('@type')
    assert 1 == len(json.loads(response.content.decode()).get('member'), )
    assert u'My first application' == \
        json.loads(response.content.decode()).get('member')[0].get('title')
Example #4
0
def test_application_json_detail_view(admin_client):
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    response = admin_client.get('/application/{}/'.format(app.id),
                                HTTP_ACCEPT='application/json')

    assert 200 == response.status_code
    assert 'application/json' in response.get('Content-Type')
    assert u'Resource' == json.loads(response.content.decode()).get('@type')
    assert u'My first application' == \
        json.loads(response.content.decode()).get('title')
    assert 'parent' in json.loads(response.content.decode()).keys()
    assert u'http://testserver/application/' == \
        json.loads(response.content.decode()).get('parent')
Example #5
0
def test_json_schema_serializer():
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    serializer = JsonSchemaSerializer()
    result = serializer.to_representation(app)

    assert result.get('title').startswith('Application')
    assert 'object' == result.get('type')

    assert 'salutation' == result['properties']['salutation']['key']
    assert 'salutation' == result['properties']['salutation']['title']
    assert 'string' == result['properties']['salutation']['type']
    assert 'salutation' in result['form']

    assert 'firstname' == result['properties']['firstname']['key']
    assert 'First name' == result['properties']['firstname']['title']
    assert 'string' == result['properties']['firstname']['type']
    assert 'firstname' in result['required']
    assert 'firstname' in result['form']

    assert 'lastname' == result['properties']['lastname']['key']
    assert 'Last name' == result['properties']['lastname']['title']
    assert 'string' == result['properties']['lastname']['type']
    assert 'lastname' in result['form']

    assert 'email' == result['properties']['email']['key']
    assert 'Email address' == result['properties']['email']['title']
    assert 'string' == result['properties']['email']['type']
    assert '^\\S+@\\S+$' == result['properties']['email']['pattern']
    assert 'email' in result['form']

    assert 'first_time_application' == result['properties'][
        'first_time_application']['key']  # noqa
    assert 'first_time_application' == result['properties'][
        'first_time_application']['title']  # noqa
    assert 'boolean' == result['properties']['first_time_application']['type']
    assert 'first_time_application' in result['form']
def test_application_json_list_view(admin_client):
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    response = admin_client.get(
        '/application/',
        HTTP_ACCEPT='application/json'
    )

    assert 200 == response.status_code
    assert 'application/json' in response.get('Content-Type')
    assert u'PagedCollection' == json.loads(
        response.content.decode()).get('@type')
    assert 1 == len(json.loads(response.content.decode()).get('member'), )
    assert u'My first application' == \
        json.loads(response.content.decode()).get('member')[0].get('title')
def test_application_json_detail_view(admin_client):
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    response = admin_client.get(
        '/application/{}/'.format(app.id),
        HTTP_ACCEPT='application/json'
    )

    assert 200 == response.status_code
    assert 'application/json' in response.get('Content-Type')
    assert u'Resource' == json.loads(response.content.decode()).get('@type')
    assert u'My first application' == \
        json.loads(response.content.decode()).get('title')
    assert 'parent' in json.loads(response.content.decode()).keys()
    assert u'http://testserver/application/' == \
        json.loads(response.content.decode()).get('parent')
def test_json_schema_serializer():
    app = Application()
    app.title = u'My first application'
    app.firstname = u'John'
    app.lastname = u'Doe'
    app.email = u'*****@*****.**'
    app.save()

    serializer = JsonSchemaSerializer()
    result = serializer.to_representation(app)

    assert result.get('title').startswith('Application')
    assert 'object' == result.get('type')

    assert 'salutation' == result['properties']['salutation']['key']
    assert 'salutation' == result['properties']['salutation']['title']
    assert 'string' == result['properties']['salutation']['type']
    assert 'salutation' in result['form']

    assert 'firstname' == result['properties']['firstname']['key']
    assert 'First name' == result['properties']['firstname']['title']
    assert 'string' == result['properties']['firstname']['type']
    assert 'firstname' in result['required']
    assert 'firstname' in result['form']

    assert 'lastname' == result['properties']['lastname']['key']
    assert 'Last name' == result['properties']['lastname']['title']
    assert 'string' == result['properties']['lastname']['type']
    assert 'lastname' in result['form']

    assert 'email' == result['properties']['email']['key']
    assert 'Email address' == result['properties']['email']['title']
    assert 'string' == result['properties']['email']['type']
    assert '^\\S+@\\S+$' == result['properties']['email']['pattern']
    assert 'email' in result['form']

    assert 'first_time_application' == result['properties']['first_time_application']['key']  # noqa
    assert 'first_time_application' == result['properties']['first_time_application']['title']  # noqa
    assert 'boolean' == result['properties']['first_time_application']['type']
    assert 'first_time_application' in result['form']