def test_no_tab_title_singular(self): "Test that `tab_title` is required for the singular validator" with self.assertRaises(TextbookValidationError): validate_textbook_json('{"url": "/textbook.pdf"}')
def test_invalid_json_singular(self): "Test that invalid JSON trips the singluar validator" with self.assertRaises(TextbookValidationError): validate_textbook_json("[{1]}")
def test_wrong_json_singular(self): "Test that a JSON list trips the plural validators (requires an object)" with self.assertRaises(TextbookValidationError): validate_textbook_json( '[{"tab_title": "Hi, mom!"}, {"tab_title": "Hi, dad!"}]')
def test_valid_id(self): "Test that a valid ID doesn't trip the validator, and comes out unchanged" self.tb1["id"] = 1 result = validate_textbook_json(json.dumps(self.tb1)) self.assertEqual(self.tb1, result)
def test_invalid_id(self): "Test that an invalid ID trips the validator" self.tb1["id"] = "abc" with self.assertRaises(TextbookValidationError): validate_textbook_json(json.dumps(self.tb1))
def test_happy_path_singular_1(self): "Test that the singular validator works properly" result = validate_textbook_json(json.dumps(self.tb1)) self.assertEqual(self.tb1, result)
def test_happy_path_singular_2(self): "Test that the singular validator works properly, with different data" result = validate_textbook_json(json.dumps(self.tb2)) self.assertEqual(self.tb2, result)
def test_wrong_json_singular(self): "Test that a JSON list trips the plural validators (requires an object)" with self.assertRaises(TextbookValidationError): validate_textbook_json('[{"tab_title": "Hi, mom!"}, {"tab_title": "Hi, dad!"}]')