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 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
Esempio n. 3
0
    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 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)
Esempio n. 5
0
    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_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 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)
Esempio n. 10
0
 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)