#!/usr/bin/env python

# THIS IS NOT A PROPER TESTING FRAMEWORK - it's just
# a tool for doing simple sanity checking (20130406/straup)

import sys
import optparse
import ConfigParser

import logging

import youarehere.api.client

if __name__ == '__main__':

    parser = optparse.OptionParser()
    parser.add_option('--config', dest='config', action='store', help='...', default=None)
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="enable chatty logging; default is false", default=False)

    (opts, args) = parser.parse_args()

    if opts.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    cfg = ConfigParser.ConfigParser()
    cfg.read(opts.config)

    #

    token = cfg.get('api', 'access_token')
    host = cfg.get('api', 'host')

    # Mostly stuff for doing development - this isn't
    # anything that you should need to care about once
    # the API is live and public (20130403/straup)

    kwargs = {}

    for opt in ('username', 'password', 'use_https'):
        
        if cfg.has_option('api', opt):

            if opt == 'use_https':
                kwargs[opt] = bool(int(cfg.get('api', opt)))
            else:
                kwargs[opt] = cfg.get('api', opt)
    
    # put me in a file or something...
    
    tests = {
        'api.spec.formats' : {},
        'api.spec.methods': {},
        'test.echo': {'foo': 'bar' },
        'test.error': {},
        'youarehere.corrections.getCorrectionsByDate': { 'start_date': '2013-04-01', 'end_date': '2013-04-02' },
        'youarehere.geo.geocode' : { 'query': 'melbourne' },
        'youarehere.geo.reverseGeocode' : { 'lat': 40.683789, 'lon': -73.989958, 'filter': 'localities' },
        'youarehere.geo.filters.getList' : {},
        }

    #

    api = youarehere.api.client.OAuth2(token, host, **kwargs)

    for method, args in tests.items():

        logging.info("testing %s w/ %s" % (method, args))

        try:
            rsp = api.call(method, **args)
            logging.debug(rsp)
        except Exception, e:
            logging.error("API error: %s" % e)
            continue

        if rsp['stat'] != 'ok' and method != 'test.error':
            logging.error("API error: %s" % rsp)
            continue

        logging.info("%s OK" % method)

    #

    logging.info("done")
    sys.exit()

@@ -1419,24 +1419,28 @@
 %7D,%0A        '
+api.
 test.echo': 
@@ -1465,16 +1465,20 @@
        '
+api.
 test.err
@@ -1510,14 +1510,13 @@
 ere.
-correc
+asser
 tion
@@ -1524,14 +1524,13 @@
 .get
-Correc
+Asser
 tion
@@ -1593,24 +1593,83 @@
 3-04-02' %7D,%0A
+        'youarehere.assertions.perspectives.getList' : %7B%7D,%0A
         'you
@@ -1820,24 +1820,24 @@
 alities' %7D,%0A
-
         'you
@@ -1863,32 +1863,79 @@
 .getList' : %7B%7D,%0A
+        'youarehere.geo.sources.getList' : %7B%7D,%0A
         %7D%0A%0A    #

update test script per naming changes and new methods