def test_GIVEN_non_existant_user_in_list_WHEN_get_filtered_THEN_user_is_replaced_by_default_user(self):
        nobody_username = "******"
        config = ConfigMother.test_configuration_with_values(nobody_username=nobody_username)
        client = MajicWebserviceClient(config)
        client.get_properties_list = Mock(return_value={
            JSON_MODEL_RUNS: RunModelPropertiesMother.create_model_run_properties([1], owner="non_existant_user")})

        results = client.get_properties_list_with_filtered_users()

        assert_that(results, is_(RunModelPropertiesMother.create_model_run_properties([1], owner=nobody_username)))
    def test_GIVEN_user_in_list_WHEN_get_filtered_THEN_user_kept(self):
        expected_user = getpass.getuser()
        nobody_username = "******"
        config = ConfigMother.test_configuration_with_values(nobody_username=nobody_username)
        client = MajicWebserviceClient(config)
        client.get_properties_list = Mock(return_value={
            JSON_MODEL_RUNS: RunModelPropertiesMother.create_model_run_properties([1], owner=expected_user)})

        results = client.get_properties_list_with_filtered_users()

        assert_that(results, is_(RunModelPropertiesMother.create_model_run_properties([1], owner=expected_user)))
    def test_GIVEN_majic_is_up_WHEN_get_file_properties_THEN_data_returned(self):
        config = ConfigMother.test_configuration()
        client = MajicWebserviceClient(config)

        try:
            result = client.get_properties_list()
        except WebserviceClientError as ex:
            if ex.message.startswith("There is a connection error when contacting the Majic Web Service"):
                raise self.skipTest("Connection error talking with Majic Web service")
            else:
                raise ex

        assert_that(result, is_not(None))
Beispiel #4
0
    def __init__(self,
                 configuration,
                 majic_webservice_client=None,
                 file_system_comparer=None,
                 directory_synchroniser=None):
        """
        Constructor
        :param configuration: the configuration to use for the synchronisation
        :param majic_webservice_client: the majic web service to use
        :return: nothing
        """
        super(Synchroniser, self).__init__()
        self._config = configuration

        if majic_webservice_client is None:
            self._majic_webservice_client = MajicWebserviceClient(self._config)
        else:
            self._majic_webservice_client = majic_webservice_client

        if file_system_comparer is None:
            self._file_system_comparer = FileSystemComparer(self._config)
        else:
            self._file_system_comparer = file_system_comparer

        if directory_synchroniser is None:
            self._directory_synchroniser = DirectorySynchroniser(self._config)
        else:
            self._directory_synchroniser = directory_synchroniser
Beispiel #5
0
class Synchroniser(object):
    """
    Provides services to synchronisation file
    """

    def __init__(self,
                 configuration,
                 majic_webservice_client=None,
                 file_system_comparer=None,
                 directory_synchroniser=None):
        """
        Constructor
        :param configuration: the configuration to use for the synchronisation
        :param majic_webservice_client: the majic web service to use
        :return: nothing
        """
        super(Synchroniser, self).__init__()
        self._config = configuration

        if majic_webservice_client is None:
            self._majic_webservice_client = MajicWebserviceClient(self._config)
        else:
            self._majic_webservice_client = majic_webservice_client

        if file_system_comparer is None:
            self._file_system_comparer = FileSystemComparer(self._config)
        else:
            self._file_system_comparer = file_system_comparer

        if directory_synchroniser is None:
            self._directory_synchroniser = DirectorySynchroniser(self._config)
        else:
            self._directory_synchroniser = directory_synchroniser

    def synchronise(self):
        """
        Synchronise the files returned by the web service with those on the disc
        :return: error code to exit with
        """
        try:
            log.debug("Starting to sync")
            model_propeties = self._majic_webservice_client.get_properties_list_with_filtered_users()
            self._file_system_comparer.perform_analysis(model_propeties)
            self._file_system_comparer.add_extra_directories_to_sync()
            new_count, updated_count, deleted_count = \
                self._directory_synchroniser.synchronise_all(self._file_system_comparer)
            log.info("Finished Synchronisation:")
            log.info("  {}: Count of copied files and directories: ".format(new_count))
            log.info("  {}: Count of directory permissions updated".format(updated_count))
            log.info("  {}: Count of deleted directories".format(deleted_count))
            return 0
        except UserPrintableError as ex:
            log.error(str(ex))
            return 1
        except Exception:
            log.exception("Unknown error in synchronisation")
            log.error("An unknown error occurred so files are not synced")
            return 2