Esempio n. 1
0
 def __init__(self, apikey=None, secretkey=None, _url=None,
              version=None, validation=None,
              monitor_id=None, name=None, m_type=None, tag=None):
     customurl = _url or _api_url()
     self.monitor_id = monitor_id
     self.name = name
     self.m_type = m_type
     self.tag  = tag
     self.monitor_params = None
     # if monitor_id is None:
     #     raise MonitisError("monitor_id is required")
     Monitis.__init__(self, apikey=apikey, secretkey=secretkey,
                      _url=customurl, version=version,
                      validation=validation)
Esempio n. 2
0
class TestMonitisApi:
    def setUp(self):
        self.mon = Monitis()
        # Monitis.sandbox = True
    
    def test_environ_key(self):
        env_key = environ_key("HOME")
        assert(env_key is not None)
        env_key = environ_key("A_VERY_VERY_UNLIKELY_ENV_VARIABLE")
        assert(env_key is None)
        
    def test_resolve_apikey(self):
        apikey = resolve_apikey()
        # apikey is a string of exactly 26 uppercase alphanumeric characters
        matched = match('^[0-9A-Z]{26}$', apikey)
        assert matched is not None
    
    def test_resolve_secretkey(self):
        secretkey = resolve_secretkey()
        matched = match('^[0-9A-Z]{26}$', secretkey)
        assert matched is not None
    
    def test_checksum(self):
        assert_equal(self.mon.checksum(secretkey='notReallyASecret',
                                       key2="foo", key1="bar"),
                          "ML1TdJ/wQc06CdIREtddB19wsKM=")
        assert_equal(checksum(secretkey='notReallyASecret',
                                       key2="foo", key1="bar"),
                          "ML1TdJ/wQc06CdIREtddB19wsKM=")

    def test_camel2under(self):
        words = {'test_word': 'testWord',
                 'uptime_sla': 'uptimeSLA',
                 'initial_caps_here': 'InitialCapsHere',
                 'this_would_be_weird': 'THIsWOULdBeWEIRD'}
        for converted, word in words.items():
            assert_equal(converted, camel2under(word))
    
    def test_checktime(self):
        # delta between checktime and the current time should be < 5 sec
        assert abs(int(checktime()) - int(str(int(time())) + "000")) < 5000
    
    def test_timestamp(self):
        # TODO allow for a delta, though at 1 sec resolution this will 
        # rarely fail
        assert_equal(timestamp(), datetime.utcnow().strftime("%F %T"))
    
    def test_get(self):
        # this test needs a simple API call, secretkey fits the bill
        # http://www.monitis.com/api?action=secretkey&apikey=${MONITIS_APIKEY}
        secret_key = get(action='secretkey')['secretkey']
        assert_equals(secret_key,resolve_secretkey())
    
    def test_MonitisError(self):
        '''Test calls to the API that raise a MonitisError'''
        try:
            get(action='secretkey',apikey='bad_api_key')
        except MonitisError, error:
            assert_equal(str(error), 
                'MonitisError(API Error: {"error":"Authentication failure"})')
Esempio n. 3
0
 def setUp(self):
     self.mon = Monitis()
Esempio n. 4
0
 def setUp(self):
     self.mon = Monitis()
Esempio n. 5
0
class TestMonitisApi:
    def setUp(self):
        self.mon = Monitis()
        # Monitis.sandbox = True

    def test_environ_key(self):
        env_key = environ_key("HOME")
        assert (env_key is not None)
        env_key = environ_key("A_VERY_VERY_UNLIKELY_ENV_VARIABLE")
        assert (env_key is None)

    def test_resolve_apikey(self):
        apikey = resolve_apikey()
        # apikey is a string of exactly 26 uppercase alphanumeric characters
        matched = match('^[0-9A-Z]{26}$', apikey)
        assert matched is not None

    def test_resolve_secretkey(self):
        secretkey = resolve_secretkey()
        matched = match('^[0-9A-Z]{26}$', secretkey)
        assert matched is not None

    def test_checksum(self):
        assert_equal(
            self.mon.checksum(secretkey='notReallyASecret',
                              key2="foo",
                              key1="bar"), "ML1TdJ/wQc06CdIREtddB19wsKM=")
        assert_equal(
            checksum(secretkey='notReallyASecret', key2="foo", key1="bar"),
            "ML1TdJ/wQc06CdIREtddB19wsKM=")

    def test_camel2under(self):
        words = {
            'test_word': 'testWord',
            'uptime_sla': 'uptimeSLA',
            'initial_caps_here': 'InitialCapsHere',
            'this_would_be_weird': 'THIsWOULdBeWEIRD'
        }
        for converted, word in words.items():
            assert_equal(converted, camel2under(word))

    def test_checktime(self):
        # delta between checktime and the current time should be < 5 sec
        assert abs(int(checktime()) - int(str(int(time())) + "000")) < 5000

    def test_timestamp(self):
        # TODO allow for a delta, though at 1 sec resolution this will
        # rarely fail
        assert_equal(timestamp(), datetime.utcnow().strftime("%F %T"))

    def test_get(self):
        # this test needs a simple API call, secretkey fits the bill
        # http://www.monitis.com/api?action=secretkey&apikey=${MONITIS_APIKEY}
        secret_key = get(action='secretkey')['secretkey']
        assert_equals(secret_key, resolve_secretkey())

    def test_MonitisError(self):
        '''Test calls to the API that raise a MonitisError'''
        try:
            get(action='secretkey', apikey='bad_api_key')
        except MonitisError, error:
            assert_equal(
                str(error),
                'MonitisError(API Error: {"error":"Authentication failure"})')