def test_GIVEN_majic_timesout_WHEN_get_file_properties_THEN_exception_thrown(self):
        config = ConfigMother.test_configuration_with_values(majic_ws_timeout="0.002")
        client = MajicWebserviceClient(config)

        assert_that(
            calling(client.get_properties_list),
            raises(WebserviceClientError, "Timeout when contacting the Majic Web Service"))
    def test_GIVEN_majic_is_down_WHEN_get_file_properties_THEN_exception_thrown(self):
        config = ConfigMother.incorrect_webservice_configured()
        client = MajicWebserviceClient(config)

        assert_that(
            calling(client.get_properties_list),
            raises(WebserviceClientError, "There is a connection error when contacting the Majic Web Service"))
Exemple #3
0
    def test_GIVEN_majic_is_down_WHEN_sync_THEN_error_message_returned(self):
        config = ConfigMother.incorrect_webservice_configured()
        sync = Synchroniser(config)

        result = sync.synchronise()

        assert_that(result, is_not(0))
    def test_GIVEN_root_folder_WHEN_read_THEN_return_list_of_files(self):
        config = ConfigMother.test_configuration()
        client = ApacheClient(config)

        result = client.get_contents(config.get(CONFIG_DATA_PATH, CONFIG_DATA_SECTION))

        assert_that(result, has_length(greater_than(0)))
        assert_that(result, is_not(has_item("Parent Directory")))
    def setUp(self):
        self.expected_path = "path"
        self.config = ConfigMother.test_configuration_with_values(self.expected_path)
        self.mock_file_stats = {}
        self.model_owner = "model_owner"

        self.mock_file_system_client = Mock(FileSystemClient)
        self.mock_file_system_client.get_file_properties = self.get_file_properties_mock
    def test_GIVEN_server_not_available_WHEN_download_THEN_exception(self):
        config = ConfigMother.test_configuration_with_values(apache_root_path="http://rubbish.rubbish")
        client = ApacheClient(config)
        filehandle = Mock()

        assert_that(
            calling(client.download_file).with_args("", filehandle),
            raises(ApacheClientError, "There is a connection error when "),
        )
    def test_GIVEN_file_WHEN_download_THEN_file_saved_to_filehandle(self):
        config = ConfigMother.test_configuration()
        client = ApacheClient(config)
        filehandle = Mock()
        url = "http://localhost/public/jules_bd/data/WATCH_2D/driving/LWdown_WFD/LWdown_WFD_190101.nc"

        client.download_file(url, filehandle)

        assert_that(filehandle.write.called, is_(True), "Check that something is written to the file handle")
 def tearDown(self):
     try:
         shutil.rmtree(self.root_dir)
     except OSError as e:
         if e.errno != 2:  # file doesn't exist
             config = ConfigMother.test_configuration_with_values(file_root_path=self.root_dir)
             file_system_client = FileSystemClient(config)
             file_system_client.delete_directory("run1")
             shutil.rmtree(self.root_dir)
    def test_GIVEN_server_hit_timeout_WHEN_download_THEN_exception(self):
        config = ConfigMother.test_configuration_with_values(apache_timeout="0.00001")
        client = ApacheClient(config)
        filehandle = Mock()
        url = "data/WATCH_2D/driving/LWdown_WFD/LWdown_WFD_190101.nc"

        assert_that(
            calling(client.download_file).with_args(url, filehandle),
            raises(ApacheClientError, "Timeout when contacting "),
        )
    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_majic_client_throws_an_unknown_exception_WHEN_synch_THEN_error_code_returned(self):
        error_message = "error_message"
        config = ConfigMother.incorrect_webservice_configured()

        client = Mock(MajicWebserviceClient)
        client.get_properties_list_with_filtered_users = Mock(side_effect=Exception(error_message))
        sync = Synchroniser(config, client)

        result = sync.synchronise()

        assert_that(result, is_not(0), "error code")
    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_extra_directory_WHEN_add_extra_directories_to_sync_THEN_extra_directory_added(self):
        added_dir = "data"
        self.config = ConfigMother.test_configuration_with_values(extra_directories_to_sync=added_dir)
        expected_added_dir = [FileProperties("data", getuser(), True, True)]
        file_system_comparer = FileSystemComparer(self.config, self.mock_file_system_client)
        file_system_comparer.new_directories = []
        file_system_comparer.deleted_directories = []
        file_system_comparer.existing_non_deleted_directories = []
        file_system_comparer.changed_directories = []

        file_system_comparer.add_extra_directories_to_sync()

        assert_that_file_system_comparer(file_system_comparer, existing_non_deleted_directories=expected_added_dir)
    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))
    def setup_mocks(self, directory_contents_on_apache, reg_ex_to_ignore=""):
        self.contents = directory_contents_on_apache

        self.mock_apache_client = Mock(ApacheClient)
        self.mock_apache_client.get_contents = self._find_contents

        self.mock_file_handle = Mock()
        self.mock_file_system_client = Mock(FileSystemClient)
        self.mock_file_system_client.create_file = Mock(return_value=self.mock_file_handle)
        self.mock_file_system_client.create_dir = Mock(return_value=True)

        config = ConfigMother.test_configuration_with_values(reg_ex_to_ignore=reg_ex_to_ignore)
        self.files_synchronisation = DirectorySynchroniser(config, self.mock_apache_client, self.mock_file_system_client)
 def setUp(self):
     self.root_dir = "/tmp/majic_test"  # same as in delete_dir_test.sh
     try:
         os.mkdir(self.root_dir)
     except OSError as ex:
         if ex.errno != 17:
             raise ex
         else:
             self.tearDown()
             os.mkdir(self.root_dir)
     self.filename = os.path.join(self.root_dir, "test_file")
     f = open(self.filename, "w")
     f.write("testing")
     f.close()
     config = ConfigMother.test_configuration_with_values(file_root_path=self.root_dir)
     self.file_system_client = FileSystemClient(config)