{% extends "base.html" %}

{% block title %}Imprimatur{% endblock %}

{% block nav %}
  Imprimatur
{% endblock %}

{% block content %}
  <form action="." method="post" enctype="multipart/form-data">
    <fieldset>
      <legend>Upload Test Script</legend>
      <input type="file" name="file"> <input type="submit" value="Upload">
    </fieldset>
  </form>


  <h2>Runs</h2>

  <ul>
    {% for run in runs %}
      <li><a href="/runs/{{run}}">{{run}}</a></li>
    {% endfor %}
  </ul>


  <h2>Tutorial</h2>

  <p>
    To run an example test script save the following as a file:
  </p>

  <pre>
   [
     {
       'host': 'www.google.com',
       'status_code': 200}] 
  </pre>
  
  <p>
    then upload it using the form above, and it should come back saying all
    tests have passed. Here's another script with some more examples:
  </p>

  <pre>
   [
       {
           'name': "Single regex",
           'port': 5000,
           'host': "localhost",
           'path': "/text_2",
           'status_code': 200,
           'regexes': ['inexhaustible']},
       {
           'name': "Basic auth",
           'path': "/auth",
           'auth': ("conrad", "kurtz"),
           'status_code': 200},
       {
           'name': "File upload",
           'path': "/echo",
           'method': "post",
           'files': {"yellow": "tests/2/crome-file.txt"},
           'regexes': ["yellow", "on the leads"],
           'status_code': 200},
       {
           'name': "Post name and value with regex.",
           'path': "/echo",
           'method': "post",
           'data': {"quote": "Leisure is the mother of philosophy."},
           'status_code': 200,
           'regexes': ["Leisure"]},
       {
           'name': "Repeat until successful.",
           'path': "/counter",
           # 'max' is maximum number of times to try
           # 'period' is the number of seconds to wait between tries
           'tries': {'max': 3, 'period': 1},
           'status_code': 200,
           'regexes': ["The Decline And Fall Of The Roman Empire"]},
       {
           'name': "Regex on header.",
           'path': "/redirect?location=http://localhost:5000/here.html",
           'status_code': 302,
           'regexes': ["here.html"]},
       {
           'name': "HTTP HEAD request.",
           'path': "/text_1",
           'method': "head",
           'status_code': 200}]
  </pre>

  <p>
    The full list of properties for each request is given below. A * after
    the property name means that it is carried over to subsequent requests.
  </p>

  <table>
    <caption>Properties</caption>
    <thead>
      <tr>
        <th>Name</th>
        <th>Notes</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>scheme*</td>
        <td>Can be <code>http</code> (default) or <code>https</code>.</td>
      </tr>
      <tr>
        <td>host*</td>
        <td>Default is <code>localhost</code>.</td>
      </tr>
      <tr>
        <td>port*</td>
        <td>Default is 80.</td>
      </tr>
      <tr>
        <td>auth*</td>
        <td>
          Sequence of username and password eg.
          <code>('conrad', 'kurtz')</code>.
        </td>
      <tr>
        <td>name</td>
        <td>Used to label the request.</td>
      </tr>
      <tr>
        <td>
          path
        </td>
        <td>
          End of the URL eg. <code>/retrieve?product_id=45</code>. Default is
          <code>/</code>.
        </td>
      </tr>
      <tr>
        <td>method</td>
        <td>
          An HTTP method. eg. <code>post</code>. Default is <code>get</code>.
        </td>
      </tr>
      <tr>
        <td>data</td>
        <td>
          Dictionary of post values eg.
          <code>{'id': 45, 'name': 'agnez'}</code>
        </td>
      </tr>
      <tr>
        <td>files</td>
        <td>
          File name and path to upload. Eg.
          <code>{'yellow': 'crome.txt'}</code>
        </td>
      </tr>
      <tr>
        <td>tries</td>
        <td>
          Maximum number of times to try the URL. Default
          <code>{'max': 1, 'period': 1}</code>. The
          <code>max</code> value is the maximum number of times to try, and
          the <code>period</code> is the number of seconds to wait between
          tries.
        </td>
      </tr>
      <tr>
        <td>regexes</td>
        <td>
          Sequence of regular expressions eg.
          <code>[r'goths', r'vandals']</code>.
        </td>
      </tr>
      <tr>
        <td>status_code</td>
        <td>HTTP status code to check for, eg. <code>200</code></td>
      </tr>
    </tbody>
  </table>
{% endblock %}
