def test_configuration_with_the_all_available_fields( self, mocker, temppath: pathlib.Path): config_yml = temppath / 'config.yml' config_yml.write_text(""" root-dir: ./asdf connections: - name: mytest-plugin plugin: smb hostname: example.com port: 1234 share: my-share domain: my-domain username: myuser sign_options: never use_ntlm_v2: true is_direct_tcp: false subjects: - name: test-subject sources: - connection: mytest-plugin remote-dir: /test/dir """, encoding='utf-8') syncing.validate_config(config_yml)
def test_valid_configuration(self, temppath: pathlib.Path): config_yml = temppath / 'config.yml' config_yml.write_text(f""" root-dir: ./asdf connections: - name: mytest-plugin plugin: smb username: myuser - name: another-plugin plugin: smb username: otheruser subjects: - name: sync-1 sources: - connection: mytest-plugin remote-dir: Some/Test/Dir1 - connection: another-plugin remote-dir: Another/Test/Dir1 - name: sync-2 sources: - connection: mytest-plugin remote-dir: Some/Test/Dir2 - connection: another-plugin remote-dir: Another/Test/Dir2 """, encoding='utf-8') syncing.validate_config(config_yml)
def save(self, close: bool) -> None: text: str = self._edit.toPlainText() self._conf_file.write_text(text, encoding='utf-8') try: syncing.validate_config(self._conf_file) except (utils.InvalidSettingsError, yaml.YAMLError) as ex: QMessageBox.critical(self, "Failed to validate config", str(ex)) return if close: self.close_requested.emit()
def test_validate_config(self, temppath): config_yml = temppath / 'config.yml' config_yml.write_text(""" root-dir: ./testkitovu connections: - name: mytest-moodle plugin: moodle subjects: - name: Wi2 sources: - connection: mytest-moodle remote-dir: "Wirtschaftsinformatik 2 FS2018" """) syncing.validate_config(config_yml)
def test_configuration_with_the_minimum_required_fields(self, mocker, temppath: pathlib.Path): config_yml = temppath / 'config.yml' config_yml.write_text(""" root-dir: ./asdf connections: - name: mytest-plugin plugin: smb username: myuser subjects: - name: test-subject sources: - connection: mytest-plugin remote-dir: /test/dir """, encoding='utf-8') syncing.validate_config(config_yml)
def test_config_with_unexpected_connection_fields(self, temppath): # bogus setting: connection: 42 config_yml = temppath / 'config.yml' config_yml.write_text(""" root-dir: ./testkitovu connections: - name: mytest-moodle plugin: moodle connection: 42 subjects: - name: Wi2 sources: - connection: mytest-moodle remote-dir: "Wirtschaftsinformatik 2 FS2018" """) with pytest.raises(utils.InvalidSettingsError): syncing.validate_config(config_yml)
def _get_config_errors(self, config_yml): with pytest.raises(utils.InvalidSettingsError) as excinfo: syncing.validate_config(config_yml) return [error.message for error in excinfo.value.errors]
def test_configuration_without_a_file(self, temppath: pathlib.Path): config_yml = temppath / 'config.yml' with pytest.raises(utils.UsageError) as excinfo: syncing.validate_config(pathlib.Path(config_yml)) assert str(excinfo.value) == f'Could not find the file {config_yml}'
def validate(config: typing.Optional[pathlib.Path] = None) -> None: """Validate the configuration file.""" try: syncing.validate_config(config) except utils.UsageError as ex: raise click.ClickException(str(ex))