Ejemplo n.º 1
0
 def test_filename_option_requires_a_valid_filename(self):
     option = Options.get('filename')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     dirname = os.path.dirname(__file__)
     with self.assertRaises(ValidationError):
         validator.validate(document('invalid-file'))
     with self.assertRaises(ValidationError):
         validator.validate(document(dirname))
Ejemplo n.º 2
0
    def setUp(self):
        super().setUp()
        cwd = os.getcwd()
        os.chdir('tests/core/fixtures/modes')
        self.addCleanup(os.chdir, cwd)

        self.fn = __file__
        self.size = os.path.getsize(self.fn)
        with open(self.fn, 'br') as fp:
            self.sha256sum = hashlib.sha256(fp.read()).hexdigest()

        self.mode_class = Modes.get(self.mode)
        self.mode_schema = '{}-object.json'.format(self.mode)
        self.default_string_file = '{}_default.txt'.format(self.mode)
        self.full_string_file = '{}_full.txt'.format(self.mode)

        self.default_options = None
        self.default_template = None
        self.default_metadata = None
        self.full_options = None
        self.full_template = None
        self.full_metadata = None
Ejemplo n.º 3
0
 def test_raises_when_invalid_choice(self):
     option = Options.get('filesystem')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     with self.assertRaises(ValidationError):
         validator.validate(document('invalid-filesystem'))
Ejemplo n.º 4
0
 def test_invalid_value_raises_error(self):
     option = Options.get('truncate')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     with self.assertRaises(ValidationError):
         validator.validate(document('not-an-absolut-path'))
Ejemplo n.º 5
0
 def test_empty_value_raises_error_if_required_and_has_no_default(self):
     option = Options.get('target')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     with self.assertRaises(ValidationError):
         validator.validate(document(''))
Ejemplo n.º 6
0
 def test_empty_value_returns_None_if_option_has_default(self):
     option = Options.get('format?')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     self.assertIsNone(validator.validate(document('')))
Ejemplo n.º 7
0
 def test_valid_value_returns_None(self):
     option = Options.get('format?')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     for value in ['y', 'yes', 'n', 'no']:
         self.assertIsNone(validator.validate(document(value)))
Ejemplo n.º 8
0
 def test_raises_when_invalid_target_type(self):
     option = Options.get('target-type')
     validator = validators.ObjectOptionValueValidator(
         option, Modes.get('copy'))
     with self.assertRaises(ValidationError):
         validator.validate(document('invalid-target-type'))