def test_download_file(self, driver, default_project, session, provider):
        current_browser = driver.desired_capabilities.get('browserName')
        node_id = default_project.id

        # Connect addon to node, upload a single test file
        node = osf_api.get_node(session, node_id=node_id)
        if provider != 'osfstorage':
            addon = osf_api.get_user_addon(session, provider)
            addon_account_id = list(addon['data']['links']['accounts'])[0]
            osf_api.connect_provider_root_to_node(session, provider, addon_account_id, node_id=node_id)

        file_name = 'download_' + current_browser + '_' + provider + '.txt'
        new_file, metadata = osf_api.upload_fake_file(session=session, node=node, name=file_name, provider=provider)

        try:
            files_page = FilesPage(driver, guid=node_id)
            files_page.goto()

            row = find_row_by_name(driver, provider, new_file)
            row.click()
            download_button = find_toolbar_button_by_name(driver, 'Download')
            download_button.click()
            # Wait to see if error message appears -- for negative test
            time.sleep(2)

            # Negative test
            assert 'Could not retrieve file or directory' not in driver.find_element_by_xpath('/html/body').text

        finally:
            osf_api.delete_addon_files(session, provider, current_browser, guid=node_id)
    def test_rename_file(self, driver, default_project, session, provider):
        current_browser = find_current_browser(driver)
        node_id = default_project.id

        # Connect addon to node, upload a single test file
        node = osf_api.get_node(session, node_id=node_id)
        if provider != 'osfstorage':
            addon = osf_api.get_user_addon(session, provider)
            addon_account_id = list(addon['data']['links']['accounts'])[0]
            osf_api.connect_provider_root_to_node(session,
                                                  provider,
                                                  addon_account_id,
                                                  node_id=node_id)

        file_name = 'rename_' + current_browser + '_' + provider + '.txt'
        new_file, metadata = osf_api.upload_fake_file(session=session,
                                                      node=node,
                                                      name=file_name,
                                                      provider=provider)

        try:
            files_page = FilesPage(driver, guid=node_id)
            files_page.goto()

            row = find_row_by_name(driver, provider, new_file)
            row.click()
            rename_button = find_toolbar_button_by_name(driver, 'Rename')
            rename_button.click()
            rename_text_box = driver.find_element_by_id('renameInput')

            for _ in range(len(new_file)):
                rename_text_box.send_keys(Keys.BACKSPACE)

            new_name = current_browser + '_' + provider + '_renamed.txt'
            rename_text_box.send_keys(new_name)
            rename_text_box.send_keys(Keys.RETURN)

            # Wait for 5 seconds for Rename message to show
            WebDriverWait(driver, 5).until(
                EC.visibility_of_element_located(
                    (By.CLASS_NAME, 'text-muted')))
            # Wait a maximum of 20 seconds for Rename message to resolve
            WebDriverWait(driver, 20).until(
                EC.invisibility_of_element_located(
                    (By.CLASS_NAME, 'text-muted')))

            files_page.goto()
            # Test old file name does not exist
            old_file = find_row_by_name(driver, provider, file_name)
            assert old_file is None

            # Test that new file name is present and visible
            renamed_file = find_row_by_name(driver, provider, new_name)
            assert new_name in renamed_file.text

        finally:
            osf_api.delete_addon_files(session,
                                       provider,
                                       current_browser,
                                       guid=node_id)
    def test_delete_file(self, driver, default_project, session, provider):
        current_browser = driver.desired_capabilities.get('browserName')
        node_id = default_project.id

        # Connect addon to node, upload a single test file
        node = osf_api.get_node(session, node_id=node_id)
        if provider != 'osfstorage':
            addon = osf_api.get_user_addon(session, provider)
            addon_account_id = list(addon['data']['links']['accounts'])[0]
            osf_api.connect_provider_root_to_node(session,
                                                  provider,
                                                  addon_account_id,
                                                  node_id=node_id)

        file_name = 'delete_' + current_browser + '_' + provider + '.txt'
        new_file, metadata = osf_api.upload_fake_file(session=session,
                                                      node=node,
                                                      name=file_name,
                                                      provider=provider)

        try:
            files_page = FilesPage(driver, guid=node_id)
            files_page.goto()

            row = find_row_by_name(driver, provider, new_file)
            row.click()
            delete_button = find_toolbar_button_by_name(driver, 'Delete')
            delete_button.click()

            # Wait for the delete confirmation
            files_page.delete_modal.present()

            # Front End will show 'delete failed' message - still works as expected
            driver.find_element_by_css_selector('.btn-danger').click()

            # Wait for delete modal to resolve
            WebDriverWait(driver, 5).until(
                EC.invisibility_of_element_located(
                    (By.CSS_SELECTOR, 'p[class="text-danger"]')))

            deleted_row = find_row_by_name(driver, provider, new_file)
            assert deleted_row is None

        finally:
            osf_api.delete_addon_files(session,
                                       provider,
                                       current_browser,
                                       guid=node_id)
    def test_dragon_drop(self, driver, default_project, session, provider, modifier_key, action):
        current_browser = driver.desired_capabilities.get('browserName')
        node_id = default_project.id

        # Connect addon to node, upload a single test file
        node = osf_api.get_node(session, node_id=node_id)
        if provider != 'osfstorage':
            addon = osf_api.get_user_addon(session, provider)
            addon_account_id = list(addon['data']['links']['accounts'])[0]
            osf_api.connect_provider_root_to_node(session, provider, addon_account_id, node_id=node_id)
        if modifier_key == 'alt':
            file_name = 'copy_' + find_current_browser(driver) + '_' + provider + '.txt'
            new_file, metadata = osf_api.upload_fake_file(session=session, node=node, name=file_name, provider=provider)
        else:
            file_name = 'move_' + current_browser + '_' + provider + '.txt'
            new_file, metadata = osf_api.upload_fake_file(session=session, node=node, name=file_name, provider=provider)

        try:
            files_page = FilesPage(driver, guid=node_id)
            files_page.goto()

            # Find the row that contains the new file
            source_row = find_row_by_name(driver, provider, new_file)

            # Find the row with the OSF storage
            for row in files_page.fangorn_addons:
                if row.text == 'OSF Storage (United States)':
                    target = row
                    break

            action_chains = ActionChains(driver)
            action_chains.reset_actions()
            if 'chrome' in current_browser:
                # The sleeps in the following code block are needed for
                # Chrome's virtual keyboard to work properly
                if modifier_key == 'alt':
                    action_chains.key_up(Keys.LEFT_ALT).perform()
                    action_chains.key_down(Keys.LEFT_ALT).perform()
                    action_chains.click_and_hold(source_row).perform()
                    time.sleep(1)

                    action_chains.reset_actions()
                    action_chains.move_to_element(target).perform()
                    time.sleep(1)

                    action_chains.reset_actions()
                    action_chains.key_up(Keys.LEFT_ALT).perform()
                    action_chains.key_down(Keys.LEFT_ALT).perform()
                    action_chains.key_up(Keys.ALT).perform()
                    action_chains.key_down(Keys.ALT).perform()
                    action_chains.release(target).perform()
                    time.sleep(1)

                    action_chains.reset_actions()
                    action_chains.key_up(Keys.LEFT_ALT).perform()
                    action_chains.key_up(Keys.ALT).perform()

                else:
                    action_chains.click_and_hold(source_row).perform()
                    # Chrome -> will highlight multiple rows if you do not sleep here
                    time.sleep(1)
                    action_chains.move_to_element(target).perform()

                    action_chains.reset_actions()
                    action_chains.release(target).perform()
            else:
                if modifier_key == 'alt':
                    action_chains.key_down(Keys.LEFT_ALT)
                    action_chains.click_and_hold(source_row)
                    action_chains.move_to_element(target)
                    action_chains.release(target)
                    action_chains.key_up(Keys.LEFT_ALT)
                    action_chains.perform()
                else:
                    action_chains.drag_and_drop(source_row, target).perform()

            # Wait for 5 seconds for Copying message to show
            WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CLASS_NAME, 'text-muted')))
            # Wait a maximum of 20 seconds for Copying message to resolve
            WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.CLASS_NAME, 'text-muted')))

            files_page.goto()
            origin_file = find_row_by_name(driver, provider, new_file)
            destination_file = find_row_by_name(driver, 'osf', new_file)

            if modifier_key == 'alt':
                # Test for copy
                assert 'copy' in origin_file.text
                assert 'copy' in destination_file.text

                osf_api.delete_file(session, metadata['data']['links']['delete'])

            else:
                # Test for move
                assert origin_file is None
                assert 'move' in destination_file.text

        finally:
            osf_api.delete_addon_files(session, provider, current_browser, guid=node_id)