def validate_service_description(context, resource_name):
  service_description = getattr(context, resource_name)
  service_description_obj = service_description.get(
      u'service_description', None)
  assert service_description_obj is not None, \
      'Expected to find a service_description object in {0}\n{1}'.format(
          resource_name, service_description)
  endpoints = service_description_obj.get(u'endpoints', None)
  assert endpoints is not None, \
      'Expected to find service_description.endpoints in {0}\n{1}'.format(
          resource_name, service_description_obj)
  for endpoint_row in context.table:
    endpoint_name = endpoint_row['endpoint']
    max_query_count = int(endpoint_row['max_query_count'])
    endpoint_obj = endpoints.get(unicode(endpoint_name), None)
    assert endpoint_obj is not None, \
        'Expected to find service_description.endpoints.{0} in {1}\n{2}'.format(
            endpoint_name, resource_name, service_description)
    href = endpoint_obj.get('href', None)
    assert href is not None, \
        'Expected endpoint {0} to contain "href" value'.format(
            endpoint_name)
    query_count = context.query_count
    response = get_resource(context, href)
    if max_query_count > 0:
      assert (context.query_count - query_count) <= max_query_count, \
          'GET of {0} required {1} queries, which is more than {2}'\
            .format(href, context.query_count - query_count, max_query_count)
    assert response.status_code == 200, \
        'Expected status code 200 on GET of endpoint {0} URL {1}, received {2}'\
          .format(response.status_code)
Beispiel #2
0
def validate_service_description(context, resource_name):
  service_description = getattr(context, resource_name)
  service_description_obj = service_description.get(
      u'service_description', None)
  assert service_description_obj is not None, \
      'Expected to find a service_description object in {0}\n{1}'.format(
          resource_name, service_description)
  endpoints = service_description_obj.get(u'endpoints', None)
  assert endpoints is not None, \
      'Expected to find service_description.endpoints in {0}\n{1}'.format(
          resource_name, service_description_obj)
  for endpoint_row in context.table:
    endpoint_name = endpoint_row['endpoint']
    endpoint_obj = endpoints.get(unicode(endpoint_name), None)
    assert endpoint_obj is not None, \
        'Expected to find service_description.endpoints.{0} in {1}\n{2}'.format(
            endpoint_name, resource_name, service_description)
    href = endpoint_obj.get('href', None)
    assert href is not None, \
        'Expected endpoint {0} to contain "href" value'.format(
            endpoint_name)
    response = get_resource(context, href)
    assert response.status_code == 200, \
        'Expected status code 200 on GET of endpoint {0} URL {1}, received {2}'\
          .format(response.status_code)
Beispiel #3
0
def get_view_object_page(context, resourcename, expected_status=200):
    headers = {
        'Accept': 'text/html',
        'X-Requested-By': 'Reciprocity Behave Tests',
    }
    resource = getattr(context, resourcename)
    collection_name = get_inflection(resource.resource_type, 'table_singular')
    uri = '/{collection_name}s/{id}'\
        .format(collection_name=collection_name, id=resource.get('id'))
    response = get_resource(context, uri, headers)
    assert response.status_code == expected_status, response
Beispiel #4
0
def retrieve_model_by_properties(
    context, model, properties, require_exactly_one=False):
  url = get_service_endpoint_url(context, model)
  response = get_resource(context, '{0}?{1}'.format(
    url, urlencode(properties)))
  root = response.json().keys()[0]
  entries = response.json()[root][model.__tablename__]
  if require_exactly_one:
    assert len(entries) == 1
  if len(entries) > 0:
    return entries[0]
  return None
Beispiel #5
0
def retrieve_model_by_properties(context,
                                 model,
                                 properties,
                                 require_exactly_one=False):
    url = get_service_endpoint_url_for_type(context, model)
    response = get_resource(context, '{0}?{1}'.format(url,
                                                      urlencode(properties)))
    root = response.json().keys()[0]
    entries = response.json()[root][model.__tablename__]
    if require_exactly_one:
        assert len(entries) == 1
    if len(entries) > 0:
        return entries[0]
    return None
def get_or_post_with_email(context, email, resource_name):
  resource = None
  response = get_resource(context, "/api/people?email={0}".format(email))
  if response.status_code == 200:
    collection = response.json()['people_collection']['people']
    if len(collection) > 0:
      resource = collection[0]
  if resource is None:
    response = post_example(context, "Person",
        { "email": email, "context": { "id": None } })
    if response.status_code == 201:
      resource = response.json()['person']
  assert resource is not None, \
    'Failed to find or create a person with email: {email}'.format(email=email)
  setattr(context, resource_name, resource)
Beispiel #7
0
def get_or_post_with_email(context, email, resource_name):
    resource = None
    response = get_resource(context, "/api/people?email={0}".format(email))
    if response.status_code == 200:
        collection = response.json()['people_collection']['people']
        if len(collection) > 0:
            resource = collection[0]
    if resource is None:
        response = post_example(context, "Person", {
            "email": email,
            "context": {
                "id": None
            }
        })
        if response.status_code == 201:
            resource = response.json()['person']
    assert resource is not None, \
      'Failed to find or create a person with email: {email}'.format(email=email)
    setattr(context, resource_name, resource)
Beispiel #8
0
def query_with_bad_argument(context, resource_type, querystring):
  url = '{0}?{1}'.format(
      get_service_endpoint_url(context, resource_type),
      querystring)
  context.response = get_resource(context, url)
Beispiel #9
0
def query_with_bad_argument(context, resource_type, querystring):
  url = '{0}?{1}'.format(
      get_service_endpoint_url_for_type(context, resource_type),
      querystring)
  context._response = get_resource(context, url)