def test_missing_required_field(self):
     test_body = {
         "optional_field": "Some value"
     }
     valid, message = sanitize_fields(test_body)
     self.assertFalse(valid)
     self.assertEqual("Field required_field is required", message)
 def test_valid_body(self):
     test_body = {
         "required_field": "Value 1",
         "optional_field": "Value 2"
     }
     valid, message = sanitize_fields(test_body)
     self.assertTrue(valid)
 def test_field_too_long(self):
     test_body = {
         "required_field": "Value that exceeds 10 chars",
     }
     valid, message = sanitize_fields(test_body)
     self.assertFalse(valid)
     self.assertEqual("Field required_field exceeds maximum length of 10",
                      message)
 def test_extra_field(self):
     test_body = {
         "required_field": "Value 1",
         "extra_field": "Value 2"
     }
     valid, message = sanitize_fields(test_body)
     self.assertTrue(valid)
     self.assertTrue("extra_field" not in test_body, "extra_field removed")
 def test_field_too_long(self):
     test_body = {
         "required_field": "Value that exceeds 10 chars",
     }
     valid, message = sanitize_fields(test_body)
     self.assertFalse(valid)
     self.assertEqual("Field required_field exceeds maximum length of 10",
                      message)
    def validate(self, comments, form_data):
        valid, message = docket.sanitize_fields(form_data)
        if not valid:
            logger.error(message)
            return valid, message

        files = tasks.extract_files(comments)
        # Account for the main comment itself submitted as an attachment
        if len(files) > settings.MAX_ATTACHMENT_COUNT - 1:
            message = "Too many attachments"
            logger.error(message)
            return False, message

        return True, ''
Exemple #7
0
    def validate(self, comments, form_data):
        valid, message = docket.sanitize_fields(form_data)
        if not valid:
            logger.error(message)
            return valid, message

        files = tasks.extract_files(comments)
        # Account for the main comment itself submitted as an attachment
        if len(files) > settings.MAX_ATTACHMENT_COUNT - 1:
            message = "Too many attachments"
            logger.error(message)
            return False, message

        return True, ''
 def test_timeout(self, get):
     get.side_effect = requests.Timeout
     with self.settings(REGS_GOV_API_URL='http://example.com'):
         valid, message = sanitize_fields({'something': 'else'})
     self.assertTrue(valid)
 def test_503(self):
     httpretty.register_uri(httpretty.GET, 'http://example.com', status=503)
     with self.settings(REGS_GOV_API_URL='http://example.com'):
         valid, message = sanitize_fields({'something': 'else'})
     self.assertTrue(valid)
 def test_missing_optional_field(self):
     test_body = {
         "required_field": "Value 1"
     }
     valid, message = sanitize_fields(test_body)
     self.assertTrue(valid)
 def test_timeout(self, get):
     get.side_effect = requests.Timeout
     with self.settings(REGS_GOV_API_URL='http://example.com'):
         valid, message = sanitize_fields({'something': 'else'})
     self.assertTrue(valid)
 def test_503(self):
     httpretty.register_uri(httpretty.GET, 'http://example.com', status=503)
     with self.settings(REGS_GOV_API_URL='http://example.com'):
         valid, message = sanitize_fields({'something': 'else'})
     self.assertTrue(valid)
 def test_extra_field(self):
     test_body = {"required_field": "Value 1", "extra_field": "Value 2"}
     valid, message = sanitize_fields(test_body)
     self.assertTrue(valid)
     self.assertTrue("extra_field" not in test_body, "extra_field removed")
 def test_missing_required_field(self):
     test_body = {"optional_field": "Some value"}
     valid, message = sanitize_fields(test_body)
     self.assertFalse(valid)
     self.assertEqual("Field required_field is required", message)
 def test_missing_optional_field(self):
     test_body = {"required_field": "Value 1"}
     valid, message = sanitize_fields(test_body)
     self.assertTrue(valid)
 def test_valid_body(self):
     test_body = {"required_field": "Value 1", "optional_field": "Value 2"}
     valid, message = sanitize_fields(test_body)
     self.assertTrue(valid)