Beispiel #1
0
    def test_simple_action_config_value_provided_overriden_in_datastore(self):
        wrapper = PythonActionWrapper(pack='dummy_pack_5',
                                      file_path=PASCAL_ROW_ACTION_PATH,
                                      user='******')

        # No values provided in the datastore
        instance = wrapper._get_action_instance()
        self.assertEqual(instance.config['api_key'],
                         'some_api_key')  # static value
        self.assertEqual(instance.config['regions'],
                         ['us-west-1'])  # static value
        self.assertEqual(instance.config['api_secret'], None)
        self.assertEqual(instance.config['private_key_path'], None)

        # api_secret overriden in the datastore (user scoped value)
        config_service.set_datastore_value_for_config_key(
            pack_name='dummy_pack_5',
            key_name='api_secret',
            user='******',
            value='foosecret',
            secret=True)

        # private_key_path overriden in the datastore (global / non-user scoped value)
        config_service.set_datastore_value_for_config_key(
            pack_name='dummy_pack_5',
            key_name='private_key_path',
            value='foopath')

        instance = wrapper._get_action_instance()
        self.assertEqual(instance.config['api_key'],
                         'some_api_key')  # static value
        self.assertEqual(instance.config['regions'],
                         ['us-west-1'])  # static value
        self.assertEqual(instance.config['api_secret'], 'foosecret')
        self.assertEqual(instance.config['private_key_path'], 'foopath')
Beispiel #2
0
    def test_simple_action_config_value_provided_overriden_in_datastore(self):
        wrapper = PythonActionWrapper(pack='dummy_pack_5', file_path=PASCAL_ROW_ACTION_PATH,
                                      user='******')

        # No values provided in the datastore
        instance = wrapper._get_action_instance()
        self.assertEqual(instance.config['api_key'], 'some_api_key')  # static value
        self.assertEqual(instance.config['regions'], ['us-west-1'])  # static value
        self.assertEqual(instance.config['api_secret'], None)
        self.assertEqual(instance.config['private_key_path'], None)

        # api_secret overriden in the datastore (user scoped value)
        config_service.set_datastore_value_for_config_key(pack_name='dummy_pack_5',
                                                          key_name='api_secret',
                                                          user='******',
                                                          value='foosecret',
                                                          secret=True)

        # private_key_path overriden in the datastore (global / non-user scoped value)
        config_service.set_datastore_value_for_config_key(pack_name='dummy_pack_5',
                                                          key_name='private_key_path',
                                                          value='foopath')

        instance = wrapper._get_action_instance()
        self.assertEqual(instance.config['api_key'], 'some_api_key')  # static value
        self.assertEqual(instance.config['regions'], ['us-west-1'])  # static value
        self.assertEqual(instance.config['api_secret'], 'foosecret')
        self.assertEqual(instance.config['private_key_path'], 'foopath')
Beispiel #3
0
 def test_python_action_wrapper_action_script_file_contains_invalid_syntax_friendly_error(
         self):
     wrapper = PythonActionWrapper(pack='dummy_pack_5',
                                   file_path=ACTION_2_PATH,
                                   user='******')
     expected_msg = (
         'Failed to load action class from file ".*?invalid_syntax.py" '
         '\(action file most likely doesn\'t exist or contains invalid syntax\): '
         'No module named invalid')
     self.assertRaisesRegexp(Exception, expected_msg,
                             wrapper._get_action_instance)
Beispiel #4
0
    def test_python_action_wrapper_action_script_file_doesnt_exist_friendly_error(
            self):
        # File in a directory which is not a Python package
        wrapper = PythonActionWrapper(pack='dummy_pack_5',
                                      file_path='/tmp/doesnt.exist',
                                      user='******')

        expected_msg = 'File "/tmp/doesnt.exist" has no action class or the file doesn\'t exist.'
        self.assertRaisesRegexp(Exception, expected_msg,
                                wrapper._get_action_instance)

        # File in a directory which is a Python package
        wrapper = PythonActionWrapper(pack='dummy_pack_5',
                                      file_path=ACTION_1_PATH,
                                      user='******')

        expected_msg = (
            'Failed to load action class from file ".*?list_repos_doesnt_exist.py" '
            '\(action file most likely doesn\'t exist or contains invalid syntax\): '
            '\[Errno 2\] No such file or directory')
        self.assertRaisesRegexp(Exception, expected_msg,
                                wrapper._get_action_instance)