def test_correct_content_of_flag_file(self, mock_exs, mock_isfile,
                                       mock_link):
     """ flag file should contain this 'type: test_type' information """
     sys.argv = [
         "", '-b', "2018-04-01", '-e', "2018-04-09", '-f', '-l', '-t',
         'test_type'
     ]
     temp_directory = tempfile.TemporaryDirectory()
     sys.argv.append('-d')
     sys.argv.append(temp_directory.name)
     cli_copy.main()
     with open(
             os.path.join(temp_directory.name,
                          'testing_file_or_folder.test.flag'), 'r') as fd:
         self.assertEqual(fd.read(), (
             "type: test_type\n"
             "entry_id: S3A_SL_1_RBT____20180405T004306_20180405T004606_20180406T060255_"
             "0179_029_344_5220_LN2_O_NT_003\n"
             "entry_title: S3A_SL_1_RBT____20180405T004306_20180405T004606_20180406T060255_"
             "0179_029_344_5220_LN2_O_NT_003\n"
             "source: SENTINEL-3A/SLSTR\n"
             "data_center: ESA/EO\n"
             "- url: https://scihub.copernicus.eu/apihub/odata/v1/"
             "Products('6127111d-c9bd-4689-bab5-412dd39e1e81')/$value\n"
             "- url: https://scihub.copernicus.eu/the_second_fakeurl\n"
             "summary: Date: 2018-04-05T00:43:05.826008Z, Instrument: SLSTR, Mode: EO, "
             "Satellite: Sentinel-3, Size: 415.29 MB\n"))
 def test_warning_for_copying_action(self, mock_del):
     #    self, mock_exs, mock_isdir, mock_del):
     sys.argv = [
         "",
         '-b',
         "2018-09-01",
         '-e',
         "2018-09-09",
         '-l',
         '-ttl',
         '200',
         '-d',
         "/dst_folder/",
     ]
     with self.assertLogs(level='WARNING') as warn:
         cli_copy.main()
     self.assertIn(
         'WARNING:geospaas_processing.copiers:For dataset with id = 5, there is no local '
         'file/folder address in the database.', warn.output)
 def test_correct_destination_folder_for_all_files_that_are_copied(
         self, mock_exs, mock_isfile, mock_del):
     """ the copied file(s) shall be copied at the destination folder. This test for the cases
     that we have one more addition local file address in the database in the case of data
     downloaded once again for a second time in a different address."""
     sys.argv = [
         "",
         '-b',
         "2018-06-01",
         '-e',
         "2018-06-09",
         '-d',
         "/dst_folder/",
     ]
     with mock.patch('shutil.copy') as mock_copy:
         cli_copy.main()
     self.assertCountEqual([
         call(dst='/dst_folder/', src='/tmp/testing_file_or_folder.test'),
         call(dst='/dst_folder/', src='/new_loc_add')
     ], mock_copy.call_args_list)
 def test_correct_destination_folder_for_all_folders_that_are_copied(
         self, mock_exs, mock_isdir, mock_del):
     """ Test that the folder which is stored at the database are correctly copied into the
     destination address. This test for the cases that we have one more addition local folder
     address in the database in the case of local folder address is stored for a second time
     in a different address."""
     sys.argv = [
         "",
         '-b',
         "2018-06-01",
         '-e',
         "2018-06-09",
         '-d',
         "/dst_folder/",
     ]
     with mock.patch('shutil.copytree') as mock_copy:
         cli_copy.main()
     self.assertCountEqual([
         call(dst='/dst_folder/testing_file_or_folder.test',
              src='/tmp/testing_file_or_folder.test'),
         call(dst='/dst_folder/new_loc_add', src='/new_loc_add')
     ], mock_copy.call_args_list)
 def test_lack_of_calling_json_deserializer_when_no_query_appears_for_copying(
         self, mock_del):
     """'json.loads' should not called when nothing comes after '-q' """
     sys.argv = [
         "",
         '-d',
         "/test_folder/",
         '-b',
         "200",
         '-e',
         "2018-11-18",
         '-r',
         '-f',
         '-l',
         '-g',
         "POLYGON ((-22 84, -22 74, 32 74, 32 84, -22 84))",
         '-t',
         'test_type',
     ]
     with mock.patch('json.loads') as mock_json:
         cli_copy.main()
     mock_json.assert_not_called()
 def test_correct_place_of_symlink_of_folders_after_creation_of_it(
         self, mock_exs, mock_isfile, mock_del):
     """ symlink must be placed at the address that is specified from the input arguments.
     This test for the cases that we have one more addition local FOLDER address in the database
     in the case of data downloaded once again for a second time in a different address. """
     sys.argv = [
         "",
         '-b',
         "2018-06-01",
         '-e',
         "2018-06-09",
         '-l',
         '-ttl',
         '200',
         '-d',
         "/dst_folder/",
     ]
     with mock.patch('os.symlink') as mock_symlink:
         cli_copy.main()
     self.assertEqual([
         call(dst='/dst_folder/testing_file_or_folder.test',
              src='/tmp/testing_file_or_folder.test'),
         call(dst='/dst_folder/new_loc_add', src='/new_loc_add')
     ], mock_symlink.call_args_list)