Exemplo n.º 1
0
    def test_to_json(self):
        """
        Test the ability to serialize a `Validation` instance.
        """
        validation = Validation("id")
        expected = {"xblock_id": "id", "messages": [], "empty": True}
        self.assertEqual(expected, validation.to_json())

        validation.add(
            ValidationMessage(ValidationMessage.ERROR, "Error message"))
        validation.add(
            ValidationMessage(ValidationMessage.WARNING, "Warning message"))

        expected = {
            "xblock_id":
            "id",
            "messages": [{
                "type": ValidationMessage.ERROR,
                "text": "Error message"
            }, {
                "type": ValidationMessage.WARNING,
                "text": "Warning message"
            }],
            "empty":
            False
        }
        self.assertEqual(expected, validation.to_json())
Exemplo n.º 2
0
    def test_empty(self):
        """
        Test that `empty` return True iff there are no messages.
        Also test the "bool" property of `Validation`.
        """
        validation = Validation("id")
        self.assertTrue(validation.empty)
        self.assertTrue(validation)

        validation.add(ValidationMessage(ValidationMessage.ERROR, "Error message"))
        self.assertFalse(validation.empty)
        self.assertFalse(validation)
Exemplo n.º 3
0
    def test_empty(self):
        """
        Test that `empty` return True iff there are no messages.
        Also test the "bool" property of `Validation`.
        """
        validation = Validation("id")
        self.assertTrue(validation.empty)
        self.assertTrue(validation)

        validation.add(ValidationMessage(ValidationMessage.ERROR, "Error message"))
        self.assertFalse(validation.empty)
        self.assertFalse(validation)
Exemplo n.º 4
0
    def test_copy(self):
        validation = Validation("id")
        validation.add(ValidationMessage(ValidationMessage.ERROR, u"Error message"))

        studio_validation = StudioValidation.copy(validation)
        self.assertIsInstance(studio_validation, StudioValidation)
        self.assertFalse(studio_validation)
        self.assertEqual(1, len(studio_validation.messages))
        expected = {
            "type": StudioValidationMessage.ERROR,
            "text": u"Error message"
        }
        self.assertEqual(expected, studio_validation.messages[0].to_json())
        self.assertIsNone(studio_validation.summary)
Exemplo n.º 5
0
    def test_copy(self):
        validation = Validation("id")
        validation.add(ValidationMessage(ValidationMessage.ERROR, u"Error message"))

        studio_validation = StudioValidation.copy(validation)
        self.assertIsInstance(studio_validation, StudioValidation)
        self.assertFalse(studio_validation)
        self.assertEqual(1, len(studio_validation.messages))
        expected = {
            "type": StudioValidationMessage.ERROR,
            "text": u"Error message"
        }
        self.assertEqual(expected, studio_validation.messages[0].to_json())
        self.assertIsNone(studio_validation.summary)
Exemplo n.º 6
0
    def test_copy(self):
        validation = Validation("id")
        validation.add(
            ValidationMessage(ValidationMessage.ERROR, "Error message"))

        studio_validation = StudioValidation.copy(validation)
        assert isinstance(studio_validation, StudioValidation)
        assert not studio_validation
        assert 1 == len(studio_validation.messages)
        expected = {
            "type": StudioValidationMessage.ERROR,
            "text": "Error message"
        }
        assert expected == studio_validation.messages[0].to_json()
        assert studio_validation.summary is None
Exemplo n.º 7
0
    def test_add_messages(self):
        """
        Test the behavior of adding the messages from another `Validation` object to this instance.
        """
        validation_1 = Validation("id")
        validation_1.add(ValidationMessage(ValidationMessage.ERROR, "Error message"))

        validation_2 = Validation("id")
        validation_2.add(ValidationMessage(ValidationMessage.WARNING, "Warning message"))

        validation_1.add_messages(validation_2)
        self.assertEqual(2, len(validation_1.messages))

        self.assertEqual(ValidationMessage.ERROR, validation_1.messages[0].type)
        self.assertEqual("Error message", validation_1.messages[0].text)

        self.assertEqual(ValidationMessage.WARNING, validation_1.messages[1].type)
        self.assertEqual("Warning message", validation_1.messages[1].text)
Exemplo n.º 8
0
    def test_add_messages(self):
        """
        Test the behavior of adding the messages from another `Validation` object to this instance.
        """
        validation_1 = Validation("id")
        validation_1.add(ValidationMessage(ValidationMessage.ERROR, "Error message"))

        validation_2 = Validation("id")
        validation_2.add(ValidationMessage(ValidationMessage.WARNING, "Warning message"))

        validation_1.add_messages(validation_2)
        self.assertEqual(2, len(validation_1.messages))

        self.assertEqual(ValidationMessage.ERROR, validation_1.messages[0].type)
        self.assertEqual("Error message", validation_1.messages[0].text)

        self.assertEqual(ValidationMessage.WARNING, validation_1.messages[1].type)
        self.assertEqual("Warning message", validation_1.messages[1].text)
Exemplo n.º 9
0
    def test_to_json(self):
        """
        Test the ability to serialize a `Validation` instance.
        """
        validation = Validation("id")
        expected = {
            "xblock_id": "id",
            "messages": [],
            "empty": True
        }
        self.assertEqual(expected, validation.to_json())

        validation.add(ValidationMessage(ValidationMessage.ERROR, "Error message"))
        validation.add(ValidationMessage(ValidationMessage.WARNING, "Warning message"))

        expected = {
            "xblock_id": "id",
            "messages": [
                {"type": ValidationMessage.ERROR, "text": "Error message"},
                {"type": ValidationMessage.WARNING, "text": "Warning message"}
            ],
            "empty": False
        }
        self.assertEqual(expected, validation.to_json())