def test_duplicate_ids(self): "Test that duplicate IDs in the plural validator trips the validator" textbooks = [ {"tab_title": "name one", "url": "one.pdf", "id": 1}, {"tab_title": "name two", "url": "two.pdf", "id": 1}, ] with self.assertRaises(TextbookValidationError): validate_textbooks_json(json.dumps(textbooks))
def test_duplicate_ids(self): "Test that duplicate IDs in the plural validator trips the validator" textbooks = [{ "tab_title": "name one", "url": "one.pdf", "id": 1, }, { "tab_title": "name two", "url": "two.pdf", "id": 1, }] with self.assertRaises(TextbookValidationError): validate_textbooks_json(json.dumps(textbooks))
def test_no_tab_title_plural(self): "Test that `tab_title` is required for the plural validator" with self.assertRaises(TextbookValidationError): validate_textbooks_json('[{"url": "/textbook.pdf"}]')
def test_wrong_json_plural(self): "Test that a JSON object trips the plural validators (requires a list)" with self.assertRaises(TextbookValidationError): validate_textbooks_json('{"tab_title": "Hi, mom!"}')
def test_invalid_json_plural(self): "Test that invalid JSON trips the plural validator" with self.assertRaises(TextbookValidationError): validate_textbooks_json("[{'abc'}]")
def test_happy_path_plural(self): "Test that the plural validator works properly" result = validate_textbooks_json(json.dumps(self.textbooks)) self.assertEqual(self.textbooks, result)