Giter Club home page Giter Club logo

shared-api-tests's Introduction

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

shared-api-tests's People

Contributors

mjy avatar jhill1 avatar dwinter avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.