Esempio n. 1
0
def the_resource_should_have(context, resource):
    response = context.client.get(resource)
    response_data = json.loads(response.content.decode('utf-8'))
    items = response_data.get('results')
    assert_that(items, not_none)
    items = [normalize_data(item) for item in items]
    for row in context.table:
        row = normalize_data(row.as_dict())
        assert_that(items, has_item(has_entries(row)))
Esempio n. 2
0
def the_apps_model_should_have(context, application, model):
    app_model = apps.get_model(application, model)
    headings = context.table.headings
    items = list()
    values = app_model.objects.values(*headings)
    for value in values:
        data = dict()
        for head in headings:
            try:
                data[head] = value.get(head)
            except AttributeError:
                data[head] = None
        items.append(normalize_data(data))

    for row in context.table:
        row = normalize_data(row.as_dict())
        assert_that(items, has_item(has_entries(row)))
Esempio n. 3
0
def the_var_with(context, var):
    factory_class = Apps.get_factory(var)

    for row in context.table:
        factory_object = None
        row = normalize_data(del_key_by_value(row.as_dict()))
        factory_object = factory_class.create(**row)
        assert_that(factory_object, not_none)
Esempio n. 4
0
def the_resource_with_field_value_should_have(context, resource, field, value):
    data = dict()
    url = '{0}/{1}'.format(resource, value)
    response = context.client.get(url)
    for row in context.table:
        data = normalize_data(row.as_dict())

    response_data = json.loads(response.content.decode('utf-8'))
    assert_that(response_data, has_entries(data))
Esempio n. 5
0
def the_var_update_with(context, var):
    model = get_model_app(var)

    for row in context.table:
        row = normalize_data(del_key_by_value(row.as_dict()))
        args_search = dict()
        args_search = {'id': row.get('id')}
        args_search['defaults'] = row
        obj, created = model.objects.update_or_create(**args_search)
        assert_that(obj, not_none)
Esempio n. 6
0
def response_to_dict(response):
    data = dict()
    if isinstance(response.content, bytes):
        data = response.content.decode('utf-8')
        if data:
            data = json.loads(data)
        else:
            data = dict()
            data['content'] = None
    data['status_code'] = response.status_code
    return normalize_data(data)
Esempio n. 7
0
def response_to_dict(response):
    data = {'content': None}
    if isinstance(response.content, bytes):
        content = response.content.decode('utf-8')

    try:
        data = json.loads(content)
    except json.decoder.JSONDecodeError:
        data['content'] = content

    data['status_code'] = response.status_code
    return normalize_data(data)
Esempio n. 8
0
def the_response_of_var_must_be(context, var):
    items = context.response.get(var)
    for row in context.table:
        row = normalize_data(row.as_dict())
        assert_that(items, has_item(has_entries(row)))
Esempio n. 9
0
def append_some(context, var):
    data = list()
    for row in context.table:
        data.append(normalize_data(row.as_dict()))

    setattr(context, var, data)
Esempio n. 10
0
def append_one(context, var):
    data = dict()
    for row in context.table:
        data = normalize_data(row.as_dict())
    setattr(context, var, data)