Esempio n. 1
0
 def test_illegal_text_inputs(self):
     self.assertFalse(
         validator.is_question_input({
             "type": "text",
             "enable_long_text": True,
         })[0], "Unrecognized field")
     self.assertFalse(
         validator.is_question_input({
             "type": "text",
             "enable-long-text": 1,
         })[0], "Enable long text field is not a boolean")
     self.assertFalse(
         validator.is_question_input({
             "type": "text",
             "min-length": 64,
             "max-length": 32,
         })[0], "Maximum length less than the minimum length")
     self.assertFalse(
         validator.is_question_input({
             "type": "text",
             "min-length": -32,
         })[0], "Minimum length is negative")
     self.assertFalse(
         validator.is_question_input({
             "type": "text",
             "max-length": -32,
         })[0], "Maximum length is negative")
 def test_valid_multiple_option_inputs(self):
     self.assertTrue(validator.is_question_input({
         "type": "multiple-option",
         "options": [
             {"label": "32", "value": "32"},
             {"label": "64", "value": "64"},
         ],
     })[0], "Basic multiple-option input")
     self.assertTrue(validator.is_question_input({
         "type": "multiple-option",
         "enable-multiple-choices": True,
         "enable-illustrations": False,
         "enable-other-option": True,
         "options": [
             {"label": "32", "value": "32"},
             {"label": "64", "value": "64"},
         ],
     })[0], "Complete multiple-option input")
     self.assertTrue(validator.is_question_input({
         "type": "multiple-option",
         "enable-illustrations": True,
         "options": [{
             "label": "32",
             "value": "32",
             "illustration": {
                 "image": "https://upload.wikimedia.org/wikipedia/commons/e/e1/Strawberries.jpg",
                 "page": "https://commons.wikimedia.org/wiki/File%3AStrawberries.jpg",
                 "attribution": "Brian Prechtel"
             }
         }],
     })[0], "Multiple-option input with illustrations")
 def test_valid_text_inputs(self):
     self.assertTrue(validator.is_question_input({"type": "text"})[0], "Text input")
     self.assertTrue(validator.is_question_input({
         "type": "text",
         "placeholder": "Please enter your name.",
         "enable-long-text": True,
         "min-length": 32,
         "max-length": 64,
     })[0], "Full text input")
 def test_valid_geotagging_inputs(self):
     self.assertTrue(validator.is_question_input({"type": "geotagging"})[0], "Geotagging input")
     self.assertTrue(validator.is_question_input({
         "type": "geotagging",
         "location": None
     })[0], "Geotagging input with explicitly unspecified location")
     self.assertTrue(validator.is_question_input({
         "type": "geotagging",
         "location": "Geneva"
     })[0], "Geotagging input with location")
Esempio n. 5
0
 def test_valid_multiple_option_inputs(self):
     self.assertTrue(
         validator.is_question_input({
             "type":
             "multiple-option",
             "options": [
                 {
                     "label": "32",
                     "value": "32"
                 },
                 {
                     "label": "64",
                     "value": "64"
                 },
             ],
         })[0], "Basic multiple-option input")
     self.assertTrue(
         validator.is_question_input({
             "type":
             "multiple-option",
             "enable-multiple-choices":
             True,
             "enable-illustrations":
             False,
             "enable-other-option":
             True,
             "options": [
                 {
                     "label": "32",
                     "value": "32"
                 },
                 {
                     "label": "64",
                     "value": "64"
                 },
             ],
         })[0], "Complete multiple-option input")
     self.assertTrue(
         validator.is_question_input({
             "type":
             "multiple-option",
             "enable-illustrations":
             True,
             "options": [{
                 "label": "32",
                 "value": "32",
                 "illustration": {
                     "image":
                     "https://upload.wikimedia.org/wikipedia/commons/e/e1/Strawberries.jpg",
                     "page":
                     "https://commons.wikimedia.org/wiki/File%3AStrawberries.jpg",
                     "attribution": "Brian Prechtel"
                 }
             }],
         })[0], "Multiple-option input with illustrations")
Esempio n. 6
0
 def test_valid_text_inputs(self):
     self.assertTrue(
         validator.is_question_input({"type": "text"})[0], "Text input")
     self.assertTrue(
         validator.is_question_input({
             "type": "text",
             "placeholder": "Please enter your name.",
             "enable-long-text": True,
             "min-length": 32,
             "max-length": 64,
         })[0], "Full text input")
Esempio n. 7
0
 def test_valid_geotagging_inputs(self):
     self.assertTrue(
         validator.is_question_input({"type": "geotagging"})[0],
         "Geotagging input")
     self.assertTrue(
         validator.is_question_input({
             "type": "geotagging",
             "location": None
         })[0], "Geotagging input with explicitly unspecified location")
     self.assertTrue(
         validator.is_question_input({
             "type": "geotagging",
             "location": "Geneva"
         })[0], "Geotagging input with location")
 def test_illegal_question_input(self):
     self.assertRaises(TypeError, validator.is_question_input, None)
     self.assertRaises(TypeError, validator.is_question_input, 42)
     self.assertRaises(TypeError, validator.is_question_input, "")
     self.assertRaises(TypeError, validator.is_question_input, [])
     self.assertRaises(TypeError, validator.is_question_input, {}, 42)
     self.assertRaises(TypeError, validator.is_question_input, {}, "")
     self.assertRaises(TypeError, validator.is_question_input, {}, {})
     self.assertRaises(TypeError, validator.is_question_input, {"type": 42})
     self.assertRaises(TypeError, validator.is_question_input, {"type": []})
     self.assertRaises(TypeError, validator.is_question_input, {"type": {}})
     self.assertFalse(validator.is_question_input({})[0], "Empty dictionary")
     self.assertFalse(validator.is_question_input({"type": None})[0], "Undefined input type")
     self.assertFalse(validator.is_question_input({"type": ""})[0], "Empty input type")
     self.assertFalse(validator.is_question_input({"type": "xyz"})[0], "Unrecognized input type")
 def test_illegal_geotagging_inputs(self):
     self.assertFalse(validator.is_question_input({
         "type": "geotagging",
         "location": ""
     })[0], "Geotagging input with empty location value")
     self.assertFalse(validator.is_question_input({
         "type": "geotagging",
         "location": 42
     })[0], "Geotagging input with invalid location value type (numerical value)")
     self.assertFalse(validator.is_question_input({
         "type": "geotagging",
         "location": ["Geneva"]
     })[0], "Geotagging input with invalid location value type (list)")
     self.assertFalse(validator.is_question_input({
         "type": "geotagging",
         "location": {}
     })[0], "Geotagging input with invalid location value type (dictionary)")
 def test_illegal_multiple_option_inputs(self):
     self.assertFalse(validator.is_question_input({"type": "multiple-option"})[0], "Missing options")
     self.assertFalse(validator.is_question_input({
         "type": "multiple-option",
         "options": [],
     })[0], "Empty list of options")
     self.assertFalse(validator.is_question_input({
         "type": "multiple-option",
         "options": [{"label": "32"}],
     })[0], "Missing option value")
     self.assertFalse(validator.is_question_input({
         "type": "multiple-option",
         "options": [{"value": "32"}],
     })[0], "Missing option label")
     self.assertFalse(validator.is_question_input({
         "type": "multiple-option",
         "options": [{"label": 32, "value": "32"}],
     })[0], "Option label is not a string")
     self.assertFalse(validator.is_question_input({
         "type": "multiple-option",
         "options": [{"label": "32", "value": 32}],
     })[0], "Option value is not a string")
     self.assertFalse(validator.is_question_input({
         "type": "multiple-option",
         "options": [{"label": "32", "value": "32"}],
         "illustration": "image.png",
     })[0], "Unrecognized field")
Esempio n. 11
0
 def test_illegal_question_input(self):
     self.assertRaises(TypeError, validator.is_question_input, None)
     self.assertRaises(TypeError, validator.is_question_input, 42)
     self.assertRaises(TypeError, validator.is_question_input, "")
     self.assertRaises(TypeError, validator.is_question_input, [])
     self.assertRaises(TypeError, validator.is_question_input, {}, 42)
     self.assertRaises(TypeError, validator.is_question_input, {}, "")
     self.assertRaises(TypeError, validator.is_question_input, {}, {})
     self.assertRaises(TypeError, validator.is_question_input, {"type": 42})
     self.assertRaises(TypeError, validator.is_question_input, {"type": []})
     self.assertRaises(TypeError, validator.is_question_input, {"type": {}})
     self.assertFalse(
         validator.is_question_input({})[0], "Empty dictionary")
     self.assertFalse(
         validator.is_question_input({"type": None})[0],
         "Undefined input type")
     self.assertFalse(
         validator.is_question_input({"type": ""})[0], "Empty input type")
     self.assertFalse(
         validator.is_question_input({"type": "xyz"})[0],
         "Unrecognized input type")
 def test_illegal_text_inputs(self):
     self.assertFalse(validator.is_question_input({
         "type": "text",
         "enable_long_text": True,
     })[0], "Unrecognized field")
     self.assertFalse(validator.is_question_input({
         "type": "text",
         "enable-long-text": 1,
     })[0], "Enable long text field is not a boolean")
     self.assertFalse(validator.is_question_input({
         "type": "text",
         "min-length": 64,
         "max-length": 32,
     })[0], "Maximum length less than the minimum length")
     self.assertFalse(validator.is_question_input({
         "type": "text",
         "min-length": -32,
     })[0], "Minimum length is negative")
     self.assertFalse(validator.is_question_input({
         "type": "text",
         "max-length": -32,
     })[0], "Maximum length is negative")
Esempio n. 13
0
 def test_illegal_multiple_option_inputs(self):
     self.assertFalse(
         validator.is_question_input({"type": "multiple-option"})[0],
         "Missing options")
     self.assertFalse(
         validator.is_question_input({
             "type": "multiple-option",
             "options": [],
         })[0], "Empty list of options")
     self.assertFalse(
         validator.is_question_input({
             "type": "multiple-option",
             "options": [{
                 "label": "32"
             }],
         })[0], "Missing option value")
     self.assertFalse(
         validator.is_question_input({
             "type": "multiple-option",
             "options": [{
                 "value": "32"
             }],
         })[0], "Missing option label")
     self.assertFalse(
         validator.is_question_input({
             "type":
             "multiple-option",
             "options": [{
                 "label": 32,
                 "value": "32"
             }],
         })[0], "Option label is not a string")
     self.assertFalse(
         validator.is_question_input({
             "type":
             "multiple-option",
             "options": [{
                 "label": "32",
                 "value": 32
             }],
         })[0], "Option value is not a string")
     self.assertFalse(
         validator.is_question_input({
             "type":
             "multiple-option",
             "options": [{
                 "label": "32",
                 "value": "32"
             }],
             "illustration":
             "image.png",
         })[0], "Unrecognized field")
Esempio n. 14
0
 def test_illegal_geotagging_inputs(self):
     self.assertFalse(
         validator.is_question_input({
             "type": "geotagging",
             "location": ""
         })[0], "Geotagging input with empty location value")
     self.assertFalse(
         validator.is_question_input({
             "type": "geotagging",
             "location": 42
         })[0],
         "Geotagging input with invalid location value type (numerical value)"
     )
     self.assertFalse(
         validator.is_question_input({
             "type": "geotagging",
             "location": ["Geneva"]
         })[0], "Geotagging input with invalid location value type (list)")
     self.assertFalse(
         validator.is_question_input({
             "type": "geotagging",
             "location": {}
         })[0],
         "Geotagging input with invalid location value type (dictionary)")
 def test_valid_polar_inputs(self):
     self.assertTrue(validator.is_question_input({"type": "polar"})[0], "Polar input")
Esempio n. 16
0
 def test_valid_polar_inputs(self):
     self.assertTrue(
         validator.is_question_input({"type": "polar"})[0], "Polar input")