예제 #1
0
    def test_handler_b64(self, content_mock):
        """Test handler b64."""
        plain = u'Hello, world'
        encoded = base64.b64encode(plain.encode('utf8')).decode('utf-8')

        content_mock.return_value = plain
        out = FileLookup.handle(u'base64:file://tmp/test')
        self.assertEqual(encoded, out)
예제 #2
0
    def test_handler_b64(self, content_mock: mock.MagicMock) -> None:
        """Test handler b64."""
        plain = "Hello, world"
        encoded = base64.b64encode(plain.encode("utf8")).decode("utf-8")

        content_mock.return_value = plain
        out = FileLookup.handle("base64:file://tmp/test")
        self.assertEqual(encoded, out)
예제 #3
0
    def test_handler_parameterized_b64(self, content_mock, codec_mock):
        """Test handler parameterized b64."""
        result = mock.Mock()
        codec_mock.return_value = result

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

        self.assertEqual(result, out)
예제 #4
0
    def test_handler_parameterized(self, content_mock, codec_mock):
        """Test handler parameterized."""
        result = mock.Mock()
        codec_mock.return_value = result

        out = FileLookup.handle(u"parameterized:file://tmp/test")
        codec_mock.assert_called_once_with(content_mock.return_value, False)

        self.assertEqual(result, out)
예제 #5
0
    def test_handler_json_parameterized(
        self, content_mock: mock.MagicMock, codec_mock: mock.MagicMock
    ) -> None:
        """Test handler json parameterized."""
        result = mock.Mock()
        codec_mock.return_value = result

        out = FileLookup.handle("json-parameterized:file://tmp/test")
        codec_mock.assert_called_once_with(
            content_mock.return_value, parameterized=True
        )

        self.assertEqual(result, out)
예제 #6
0
    def test_handler_yaml(
        self, content_mock: mock.MagicMock, codec_mock: mock.MagicMock
    ) -> None:
        """Test handler yaml."""
        result = mock.Mock()
        codec_mock.return_value = result

        out = FileLookup.handle("yaml:file://tmp/test")
        codec_mock.assert_called_once_with(
            content_mock.return_value, parameterized=False
        )

        self.assertEqual(result, out)
예제 #7
0
 def test_unknown_codec(self, _):
     """Test unknown codec."""
     with self.assertRaises(KeyError):
         FileLookup.handle(u'bad:file://tmp/test')
예제 #8
0
 def test_handler_plain(self, _):
     """Test handler plain."""
     out = FileLookup.handle(u'plain:file://tmp/test')
     self.assertEqual(u'Hello, world', out)
예제 #9
0
 def test_file_loaded(self, content_mock):
     """Test file loaded."""
     FileLookup.handle(u'plain:file://tmp/test')
     content_mock.assert_called_with(u'file://tmp/test')
예제 #10
0
 def test_unknown_codec(self, _: mock.MagicMock) -> None:
     """Test unknown codec."""
     with self.assertRaises(KeyError):
         FileLookup.handle("bad:file://tmp/test")
예제 #11
0
 def test_handler_plain(self, _: mock.MagicMock) -> None:
     """Test handler plain."""
     out = FileLookup.handle("plain:file://tmp/test")
     self.assertEqual("Hello, world", out)
예제 #12
0
 def test_file_loaded(self, content_mock: mock.MagicMock) -> None:
     """Test file loaded."""
     FileLookup.handle("plain:file://tmp/test")
     content_mock.assert_called_with("file://tmp/test")