def get(self, key):
     #try local configuration first
     configuration_instance = ServiceLocator.resolve(ConfigurationLocal)
     if configuration_instance is not None:
         configuration_value = configuration_instance.get(key)
         if configuration_value is not None:
             return configuration_value
     #try remote configuration second
     configuration_instance = ServiceLocator.resolve(ConfigurationRemote)
     if configuration_instance is not None:
         configuration_value = configuration_instance.get(key)
         if configuration_value is not None:
             return configuration_value
     raise Exception('key not found')
Beispiel #2
0
 def test_sms_gateway_dynamic(self):
     #get default sms gateway
     sms_gateway = ServiceLocator.resolve(SmsGateway)
     success_value = sms_gateway.send('+2783456789', 'Hello from Python!')
     print success_value
     if not success_value:
         print 'test_sms_gateway_dynamic (FAIL)'
         return
     print 'test_sms_gateway_dynamic (PASS)'
Beispiel #3
0
 def test_configuration_remote_dynamic(self):
     #get default local configuration
     configuration_remote = ServiceLocator.resolve(ConfigurationRemote)
     configuration_value = configuration_remote.get('sample_key')
     print configuration_value
     if configuration_value != 'https://clickatel.co.za/api/userid?987':
         print 'test_configuration_remote_dynamic (FAIL)'
         return
     print 'test_configuration_remote_dynamic (PASS)'
Beispiel #4
0
 def test_configuration_chain_dynamic(self):
     #get default local configuration
     configuration_chain = ServiceLocator.resolve(ConfigurationChain)
     configuration_value = configuration_chain.get('sample_key')
     print configuration_value
     if configuration_value != 'http://clickatel.co.za/api/userid?123':
         print 'test_configuration_chain_dynamic (FAIL)'
         return
     print 'test_configuration_chain_dynamic (PASS)'
Beispiel #5
0
    def test_postgres_singleton(self):
        #get default postgres connection
        postgres_connection = ServiceLocator.resolve(PostgresConnection)
        dummy_data = postgres_connection.fetchone('SELECT * FROM SomeDummy')
        print dummy_data

        postgres_connection_2 = ServiceLocator.resolve(PostgresConnection)
        dummy_data2 = postgres_connection_2.fetchone('SELECT * FROM SomeDummy2')
        print dummy_data2

        #check if the instance is being reused (singleton)
        # -- we used it twice
        connection_usage_count = postgres_connection_2.get_usage_count()
        print 'Postgres connection was used \'%s\' times' % connection_usage_count
        if connection_usage_count != 2:
            print 'test_postgres_singleton (FAIL)'
            return
        print 'test_postgres_singleton (PASS)'