def test_given_wrong_content_type_then_raises_error(self): registry = ParserRegistry() registry.register('application/json', Mock()) self.assertRaises(ContentTypeError, self.registry.parser_for_content_type, 'content/type')
class TestParserRegistry(unittest.TestCase): def setUp(self): self.registry = ParserRegistry() def test_given_no_parsers_registered_then_raises_error(self): self.assertRaises(ContentTypeError, self.registry.parser_for_content_type, 'content/type') def test_given_wrong_content_type_then_raises_error(self): registry = ParserRegistry() registry.register('application/json', Mock()) self.assertRaises(ContentTypeError, self.registry.parser_for_content_type, 'content/type') def test_given_one_parser_registered_then_return_parser(self): content_type = 'application/json' parser = Mock() self.registry.register('application/json', parser) result = self.registry.parser_for_content_type(content_type) assert_that(result, equal_to(parser))