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)
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)
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)
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)
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)
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)
def test_unknown_codec(self, _): """Test unknown codec.""" with self.assertRaises(KeyError): FileLookup.handle(u'bad:file://tmp/test')
def test_handler_plain(self, _): """Test handler plain.""" out = FileLookup.handle(u'plain:file://tmp/test') self.assertEqual(u'Hello, world', out)
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')
def test_unknown_codec(self, _: mock.MagicMock) -> None: """Test unknown codec.""" with self.assertRaises(KeyError): FileLookup.handle("bad:file://tmp/test")
def test_handler_plain(self, _: mock.MagicMock) -> None: """Test handler plain.""" out = FileLookup.handle("plain:file://tmp/test") self.assertEqual("Hello, world", out)
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")