Skip to content

OpenTreeOfLife/shared-api-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shared-api-tests

This repository contains a set of .json files that specify conditions for unit tests on the OT API. The specifications are intended to be used across languages, at present wrappers in R, Python, and Ruby are using them. Further discussion is available on the open tree wiki

usage

See the individual language implementations for example usage.

If you want curl the raw files directly you can use the raw.gihubusercontent.com reference to an individual files like so:

  https://raw.githubusercontent.com/OpenTreeOfLife/shared-api-tests/master/graph_of_life.json

format

There is one file for each API: taxonomy, trns, graph_of_life, studies, and tree_of_life. Within each file there are multiple named "tests". The basic format for an individual "test" (or testing context) is:

{
  "test_name": {
    "test_function": "test_function_name",
    "test_input": { dictionary_of_input },
    "tests": { dictionary_of_tests }
  }
}

test_name

A descriptive name wrapping a set of tests.

test_function

The name of a binding function. Function names were designed to be shared across R, Python, and Ruby. They map 1:1 with an API URL. The naming convention is referenced on the open tree wiki.

tests

A dictionary of tests organized by type. Most of the individual tests are in the format:

[specification, message]

The message is the message to display when the tests fails.

Some types of tests allow for multiple tests to be defined.

The following types of tests are available:

  • contains - Tests that a key is present in the response.
  • contains_error - Tests that the response contains the a key "error".
  • deep_equals - Tests that a nested key in the response return a specific value.
  • equals - Tests that one or more keys in the response return a specific value.
  • length_greater_than - Tests that the value for a given key contains greater than N items.
  • of_type - Tests that the response provided is of the specified type.
  • parameters_error - Tests that the request object has detected, prior to askign for a response, that the parameters passed are invalid.

parameters_error

Value is a string.

 "message'

contains

Value is an Array of Arrays. Each inner Array defines a response key to check for and message to provide on failure of the test.

[
 ["key","message"],
 ["other_key", "other_message']
]

equals

Value is an Array of Arrays. Each inner Array contains an array with a key/value pair, and a message.

[
 [ ["key", "value'], "message" ],               
 [ ["other_key", "other_value'], "message"]    
]

deep_equals

Value is an Array of Arrays. Each inner Array contains:

{
[
  [ 
   [ ["key1","key2", "key3"], "value'], "message" ]
  ],
  [
   ...
  ]
]

This is is translated to the test:

  response[key1][key2][key3] == value

contains_error

Points to message.

  "message"

Where ErrorName is the class in {what language} that is raised.

length_greater_than

Value is an Array of Arrays, each inner Array looks like

[
  ["response_key",bound_value], "message"
]

of_type

Value is an Array with two values:

  [type, message]

At present only 'dict' is used as a type. This corresponds to a Ruby Hash.

contributing

Fork the repo, add the test, VALIDATE THE JSON, and send us a pull request.

licence

BSD

About

json-formatted specifications for unit testing frameworks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5