示例#1
0
class test_Datastore_File(TestCase):
    def setUp(self) -> None:
        ds_folder = ''
        ds_file = f"test_Datastore_File-{random_string()}.txt"
        self.datastore_file = Datastore_File(ds_folder=ds_folder,
                                             ds_file=ds_file)

    # def test_download(self):
    #     tmp_file = self.datastore_file.download()
    #     print(file_contents(tmp_file))

    def test_upload__download(self):
        local_file = temp_file(file_contents="This is a local file - " +
                               random_string())  # create local temp file

        self.datastore_file.upload(local_file)  # upload file to server
        tmp_file = self.datastore_file.download()  # download file from server

        assert file_exists(tmp_file)  # confirm it exists
        assert file_contents(local_file) == file_contents(
            tmp_file
        )  # confirm content matches the randomly generated temp content

        assert self.datastore_file.delete(
        ) is True  # delete temp file from data_store
        file_delete(local_file)  # delete local temp file
示例#2
0
 def download_screenshot_from_datastore(self):
     datastore_file = Datastore_File().set_file_from_path_datastore(self.ds_screenshot)
     local_temp_file = datastore_file.download()
     if (self.path_screenshot):
         file_copy(local_temp_file, self.path_screenshot)
     else:
         self.path_screenshot = local_temp_file
     if self.ds_delete_on_download:
         datastore_file.delete()
     return self.path_screenshot
示例#3
0
    def test_save_screnshot_to_datastore(self):
        path_screenshot = self.screenshot.save_screnshot_to_datastore()
        datastore_file = Datastore_File().set_file_from_path_datastore(
            path_screenshot)

        assert datastore_file.datastore.name == datastore_file.datastore.name
        assert datastore_file.ds_folder == self.vm.name()
        assert datastore_file.ds_file == self.vm.name() + "-1.png"

        assert self.screenshot.ds_screenshot == path_screenshot  # confirm save_screnshot_to_datastore saves the path of the downloaded file to the ds_screenshot variable
示例#4
0
    def test__init__(self):
        print('------')
        assert self.datastore_file.datastore.name == 'datastore1'
        assert self.datastore_file.ds_folder == self.ds_folder
        assert self.datastore_file.ds_file == self.ds_file

        #test other __init__ modes

        datastore_file = Datastore_File()
        assert datastore_file.datastore.name == 'datastore1'
        assert datastore_file.ds_folder == ''
        assert datastore_file.ds_file == ''
示例#5
0
class test_Datastore_File(TestCase):
    def setUp(self) -> None:
        self.ds_folder = ''
        self.ds_file = f"test_Datastore_File-{random_string()}.txt"
        self.datastore_file = Datastore_File(ds_folder=self.ds_folder,
                                             ds_file=self.ds_file)
        print()

    def test__init__(self):
        print('------')
        assert self.datastore_file.datastore.name == 'datastore1'
        assert self.datastore_file.ds_folder == self.ds_folder
        assert self.datastore_file.ds_file == self.ds_file

        #test other __init__ modes

        datastore_file = Datastore_File()
        assert datastore_file.datastore.name == 'datastore1'
        assert datastore_file.ds_folder == ''
        assert datastore_file.ds_file == ''

    def test_set_file_from_path_datastore(self):
        def confirm_values_are_set_correctly(ds_name, ds_folder,
                                             ds_file):  # help method
            path_datastore = self.datastore_file.create_path_datastore(
                ds_name, ds_folder, ds_file)
            self.datastore_file.set_file_from_path_datastore(path_datastore)
            assert self.datastore_file.datastore.name == ds_name
            assert self.datastore_file.ds_folder == ds_folder
            assert self.datastore_file.ds_file == ds_file

        confirm_values_are_set_correctly("another datastore",
                                         "an folder/an subfolder", "an file")
        confirm_values_are_set_correctly(
            "another datastore", "", "an file")  # when ds_folder is not set
        confirm_values_are_set_correctly("another datastore", "",
                                         "")  # when ds_file is not set
        confirm_values_are_set_correctly("", "", "")  # when ds_name is not set

    def test_upload__download(self):
        local_file = temp_file(file_contents="This is a local file - " +
                               random_string())  # create local temp file

        self.datastore_file.upload(local_file)  # upload file to server
        tmp_file = self.datastore_file.download()  # download file from server

        assert file_exists(tmp_file)  # confirm it exists
        assert file_contents(local_file) == file_contents(
            tmp_file
        )  # confirm content matches the randomly generated temp content

        assert self.datastore_file.delete(
        ) is True  # delete temp file from data_store
        file_delete(local_file)  # delete local temp file
示例#6
0
 def setUp(self) -> None:
     self.ds_folder = ''
     self.ds_file = f"test_Datastore_File-{random_string()}.txt"
     self.datastore_file = Datastore_File(ds_folder=self.ds_folder,
                                          ds_file=self.ds_file)
     print()