Esempio n. 1
0
    def test_config_file_when_yaml_is_invalid(self):
        def err_on_done(res):
            res = res.__dict__
            self.assertEqual(res['status'], 500)
            self.assertIn("YAML syntax error", res['body'])
            self.assertEqual(res['headers']['Content-Type'],
                             'application/json')
            sys.exit(1)

        self.p.on_done = err_on_done
        with self.assertRaises(SystemExit):
            config.read_conf('tests/files/invalid_yaml.yaml', self.p)
Esempio n. 2
0
    def test_config_file_does_not_exist(self):
        def err_on_done(res):
            res = res.__dict__
            self.assertEqual(res['status'], 500)
            self.assertIn("Configuration file does not exist", res['body'])
            self.assertEqual(res['headers']['Content-Type'],
                             'application/json')
            sys.exit(1)

        self.p.on_done = err_on_done
        with self.assertRaises(SystemExit):
            config.read_conf('not/a/real/path', self.p)
Esempio n. 3
0
    def test_config_500_when_missing_target_vm(self):
        def err_on_done(res):
            res = res.__dict__
            self.assertEqual(res['status'], 500)
            self.assertIn("missing `target_vm` key", res['body'])
            self.assertEqual(res['headers']['Content-Type'],
                             'application/json')
            sys.exit(1)

        self.p.on_done = err_on_done

        with self.assertRaises(SystemExit):
            config.read_conf('tests/files/missing-target-vm.yaml', self.p)
Esempio n. 4
0
    def test_config_file_open_generic_exception(self):
        def err_on_done(res):
            res = res.__dict__
            self.assertEqual(res['status'], 500)
            self.assertEqual(res['headers']['Content-Type'],
                             'application/json')
            sys.exit(1)

        self.p.on_done = err_on_done

        with self.assertRaises(SystemExit):
            # Patching open so that we can simulate a non-YAML error
            # (e.g. permissions)
            with patch("builtins.open", side_effect=IOError):
                config.read_conf('tests/files/valid-config.yaml', self.p)
Esempio n. 5
0
    def test_config_has_valid_keys(self):
        c = config.read_conf('tests/files/valid-config.yaml', self.p)

        # Verify we have a valid Conf object
        self.assertEqual(c.host, 'jsonplaceholder.typicode.com')
        self.assertEqual(c.port, 443)
        self.assertFalse(c.dev)
        self.assertEqual(c.scheme, 'https')
        self.assertEqual(c.target_vm, 'compost')