Exemplo n.º 1
0
    def test_handler_b64(self, content_mock):
        plain = u'Hello, world'
        encoded = base64.b64encode(plain.encode('utf8'))

        content_mock.return_value = plain
        out = handler(u'base64:file://tmp/test')
        self.assertEqual(encoded, out)
Exemplo n.º 2
0
    def test_handler_parameterized_b64(self, content_mock, codec_mock):
        result = mock.Mock()
        codec_mock.return_value = result

        out = handler(u'parameterized-b64:file://tmp/test')
        codec_mock.assert_called_once_with(content_mock.return_value, True)

        self.assertEqual(result, out)
Exemplo n.º 3
0
    def test_handler_json(self, content_mock, codec_mock):
        result = mock.Mock()
        codec_mock.return_value = result

        out = handler(u'json:file://tmp/test')
        codec_mock.assert_called_once_with(content_mock.return_value,
                                           parameterized=False)

        self.assertEqual(result, out)
Exemplo n.º 4
0
 def test_handler_parameterized_b64(self):
     expected = 'Regular text {{Psuedo::Var}} {{RegVar}} {{Non-Var}}'
     processed = {
         'Fn::Base64': {
             'Fn::Join': [
                 '',
                 [
                     'Regular text ', {
                         'Ref': 'Psuedo::Var'
                     }, ' ', {
                         'Ref': 'RegVar'
                     }, ' {{Non-Var}}'
                 ]
             ]
         }
     }
     with mock.patch('stacker.lookups.handlers.file.read_value_from_path',
                     return_value=expected):
         out = handler('parameterized-b64:file://tmp/test')
         self.assertEqual(troposphere.Base64, type(out))
         self.assertEqual(processed, out.data)
Exemplo n.º 5
0
 def test_unknown_codec(self, _):
     with self.assertRaises(KeyError):
         handler(u'bad:file://tmp/test')
Exemplo n.º 6
0
 def test_handler_plain(self, _):
     out = handler(u'plain:file://tmp/test')
     self.assertEqual(u'Hello, world', out)
Exemplo n.º 7
0
 def test_file_loaded(self, content_mock):
     handler(u'plain:file://tmp/test')
     content_mock.assert_called_with(u'file://tmp/test')
Exemplo n.º 8
0
 def test_unknown_codec(self):
     expected = 'Hello, world'
     with mock.patch('stacker.lookups.handlers.file.read_value_from_path',
                     return_value=expected):
         with self.assertRaises(KeyError):
             handler('bad:file://tmp/test')
Exemplo n.º 9
0
 def test_handler_parameterized_b64(self):
     expected = 'Hello, world'
     with mock.patch('stacker.lookups.handlers.file.read_value_from_path',
                     return_value=expected):
         out = handler('parameterized-b64:file://tmp/test')
         self.assertEqual(troposphere.Base64, type(out))
Exemplo n.º 10
0
 def test_handler_b64(self):
     expected = 'Hello, world'
     with mock.patch('stacker.lookups.handlers.file.read_value_from_path',
                     return_value=expected):
         out = handler('base64:file://tmp/test')
         self.assertEqual(expected, base64.b64decode(out))
Exemplo n.º 11
0
 def test_handler_plain(self):
     expected = 'Hello, world'
     with mock.patch('stacker.lookups.handlers.file.read_value_from_path',
                     return_value=expected):
         out = handler('plain:file://tmp/test')
         self.assertEqual(expected, out)
Exemplo n.º 12
0
 def test_file_loaded(self):
     with mock.patch('stacker.lookups.handlers.file.read_value_from_path',
                     return_value='') as amock:
         handler('plain:file://tmp/test')
         amock.assert_called_with('file://tmp/test')