Renamed api_client.check_version() to api_client.is_server_compatible().
Started adding unit tests: pypo-api-validator.py.
This commit is contained in:
parent
5e04c806bd
commit
4684837f2b
|
@ -37,7 +37,7 @@ class ApiClientInterface:
|
||||||
#
|
#
|
||||||
# Should exit the program if this version of pypo is not compatible with
|
# Should exit the program if this version of pypo is not compatible with
|
||||||
# 3rd party software.
|
# 3rd party software.
|
||||||
def check_version(self):
|
def is_server_compatible(self, verbose = True):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Implementation: Required
|
# Implementation: Required
|
||||||
|
@ -108,7 +108,7 @@ class CampcasterApiClient(ApiClientInterface):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def __get_campcaster_version(self):
|
def __get_campcaster_version(self, verbose = True):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
url = self.config["base_url"] + self.config["api_base"] + self.config["version_url"]
|
url = self.config["base_url"] + self.config["api_base"] + self.config["version_url"]
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||||
|
@ -124,26 +124,28 @@ class CampcasterApiClient(ApiClientInterface):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
try:
|
||||||
if e[1] == 401:
|
if e[1] == 401:
|
||||||
print '#####################################'
|
if (verbose):
|
||||||
print '# YOUR API KEY SEEMS TO BE INVALID:'
|
print '#####################################'
|
||||||
print '# ' + self.config["api_key"]
|
print '# YOUR API KEY SEEMS TO BE INVALID:'
|
||||||
print '#####################################'
|
print '# ' + self.config["api_key"]
|
||||||
sys.exit()
|
print '#####################################'
|
||||||
|
return False
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if e[1] == 404:
|
if e[1] == 404:
|
||||||
print '#####################################'
|
if (verbose):
|
||||||
print '# Unable to contact the Campcaster-API'
|
print '#####################################'
|
||||||
print '# ' + url
|
print '# Unable to contact the Campcaster-API'
|
||||||
print '#####################################'
|
print '# ' + url
|
||||||
sys.exit()
|
print '#####################################'
|
||||||
|
return False
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
version = 0
|
version = 0
|
||||||
logger.error("Unable to detect Campcaster Version - %s", e)
|
logger.error("Unable to detect Campcaster Version - %s, Response: %s", e, response)
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
@ -165,21 +167,25 @@ class CampcasterApiClient(ApiClientInterface):
|
||||||
self.get_media(item["uri"], filename)
|
self.get_media(item["uri"], filename)
|
||||||
|
|
||||||
|
|
||||||
def check_version(self):
|
def is_server_compatible(self, verbose = True):
|
||||||
version = self.__get_campcaster_version()
|
version = self.__get_campcaster_version(verbose)
|
||||||
if (version == 0):
|
if (version == 0 or version == False):
|
||||||
print 'Unable to get Campcaster version number.'
|
if (verbose):
|
||||||
print
|
print 'Unable to get Campcaster version number.'
|
||||||
sys.exit()
|
print
|
||||||
|
return False
|
||||||
elif (version[0:4] != "1.6."):
|
elif (version[0:4] != "1.6."):
|
||||||
print 'Campcaster version: ' + str(version)
|
if (verbose):
|
||||||
print 'pypo not compatible with this version of Campcaster.'
|
print 'Campcaster version: ' + str(version)
|
||||||
print
|
print 'pypo not compatible with this version of Campcaster.'
|
||||||
sys.exit()
|
print
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
print 'Campcaster version: ' + str(version)
|
if (verbose):
|
||||||
print 'pypo is compatible with this version of Campcaster.'
|
print 'Campcaster version: ' + str(version)
|
||||||
print
|
print 'pypo is compatible with this version of Campcaster.'
|
||||||
|
print
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_schedule(self, start=None, end=None):
|
def get_schedule(self, start=None, end=None):
|
||||||
|
@ -361,27 +367,31 @@ class ObpApiClient():
|
||||||
self.config = config
|
self.config = config
|
||||||
self.api_auth = urllib.urlencode({'api_key': self.config["api_key"]})
|
self.api_auth = urllib.urlencode({'api_key': self.config["api_key"]})
|
||||||
|
|
||||||
def check_version(self):
|
def is_server_compatible(self, verbose = True):
|
||||||
obp_version = self.get_obp_version()
|
obp_version = self.get_obp_version()
|
||||||
|
|
||||||
if obp_version == 0:
|
if obp_version == 0:
|
||||||
print '#################################################'
|
if (verbose):
|
||||||
print 'Unable to get OBP version. Is OBP up and running?'
|
print '#################################################'
|
||||||
print '#################################################'
|
print 'Unable to get OBP version. Is OBP up and running?'
|
||||||
print
|
print '#################################################'
|
||||||
sys.exit()
|
print
|
||||||
|
return False
|
||||||
elif obp_version < OBP_MIN_VERSION:
|
elif obp_version < OBP_MIN_VERSION:
|
||||||
print 'OBP version: ' + str(obp_version)
|
if (verbose):
|
||||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
print 'OBP version: ' + str(obp_version)
|
||||||
print 'pypo not compatible with this version of OBP'
|
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||||
print
|
print 'pypo not compatible with this version of OBP'
|
||||||
sys.exit()
|
print
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
print 'OBP API: ' + str(API_BASE)
|
if (verbose):
|
||||||
print 'OBP version: ' + str(obp_version)
|
print 'OBP API: ' + str(API_BASE)
|
||||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
print 'OBP version: ' + str(obp_version)
|
||||||
print 'pypo is compatible with this version of OBP'
|
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||||
print
|
print 'pypo is compatible with this version of OBP'
|
||||||
|
print
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_obp_version(self):
|
def get_obp_version(self):
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
[loggers]
|
||||||
|
keys=root
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys=consoleHandler,fileHandlerERROR,fileHandlerDEBUG,nullHandler
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys=simpleFormatter
|
||||||
|
|
||||||
|
[logger_root]
|
||||||
|
level=DEBUG
|
||||||
|
handlers=consoleHandler,fileHandlerERROR,fileHandlerDEBUG
|
||||||
|
|
||||||
|
[logger_libs]
|
||||||
|
handlers=nullHandler
|
||||||
|
level=DEBUG
|
||||||
|
qualname="process"
|
||||||
|
propagate=0
|
||||||
|
|
||||||
|
[handler_consoleHandler]
|
||||||
|
class=StreamHandler
|
||||||
|
level=DEBUG
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=(sys.stdout,)
|
||||||
|
|
||||||
|
[handler_fileHandlerERROR]
|
||||||
|
class=FileHandler
|
||||||
|
level=WARNING
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=("./error.log",)
|
||||||
|
|
||||||
|
[handler_fileHandlerDEBUG]
|
||||||
|
class=FileHandler
|
||||||
|
level=DEBUG
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=("./debug.log",)
|
||||||
|
|
||||||
|
[handler_nullHandler]
|
||||||
|
class=FileHandler
|
||||||
|
level=DEBUG
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=("./log_null.log",)
|
||||||
|
|
||||||
|
|
||||||
|
[formatter_simpleFormatter]
|
||||||
|
format=%(asctime)s %(levelname)s - [%(filename)s : %(funcName)s() : line %(lineno)d] - %(message)s
|
||||||
|
datefmt=
|
||||||
|
|
||||||
|
|
||||||
|
## multitail color sheme
|
||||||
|
## pyml / python
|
||||||
|
# colorscheme:pyml:www.obp.net
|
||||||
|
# cs_re:blue:\[[^ ]*\]
|
||||||
|
# cs_re:red:CRITICAL:*
|
||||||
|
# cs_re:red,black,blink:ERROR:*
|
||||||
|
# cs_re:blue:NOTICE:*
|
||||||
|
# cs_re:cyan:INFO:*
|
||||||
|
# cs_re:green:DEBUG:*
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
from optparse import *
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
import logging
|
||||||
|
import logging.config
|
||||||
|
import shutil
|
||||||
|
import urllib
|
||||||
|
import urllib2
|
||||||
|
import pickle
|
||||||
|
import telnetlib
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
import operator
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
# additional modules (should be checked)
|
||||||
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
# custom imports
|
||||||
|
from util import *
|
||||||
|
from api_clients import *
|
||||||
|
|
||||||
|
import random
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
# configure logging
|
||||||
|
logging.config.fileConfig("logging-api-validator.cfg")
|
||||||
|
|
||||||
|
try:
|
||||||
|
config = ConfigObj('config.cfg')
|
||||||
|
except Exception, e:
|
||||||
|
print 'Error loading config file: ', e
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
class TestApiFunctions(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.api_client = api_client.api_client_factory(config)
|
||||||
|
|
||||||
|
def test_is_server_compatible(self):
|
||||||
|
self.assertTrue(self.api_client.is_server_compatible(False))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
|
@ -105,7 +105,8 @@ class Global:
|
||||||
|
|
||||||
def selfcheck(self):
|
def selfcheck(self):
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.api_client_factory(config)
|
||||||
self.api_client.check_version()
|
if (not self.api_client.is_server_compatible()):
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -76,10 +76,10 @@ class Global:
|
||||||
print
|
print
|
||||||
|
|
||||||
def selfcheck(self):
|
def selfcheck(self):
|
||||||
|
|
||||||
self.api_auth = urllib.urlencode({'api_key': API_KEY})
|
self.api_auth = urllib.urlencode({'api_key': API_KEY})
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.api_client_factory(config)
|
||||||
self.api_client.check_version()
|
if (not self.api_client.is_server_compatible()):
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
class Notify:
|
class Notify:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue