Skip to content

Commit

Permalink
add csv tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ifdjhxh committed Jul 3, 2024
1 parent fa7a7bf commit 230a567
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@
from test_single_card_check import SingleCheckTestSelenium
from test_version import VersionTestSelenium
from test_file_load import FileLoadTestSelenium
from test_csv_load import CsvDownloadTestSelenium


def parse_arguments():
parser = argparse.ArgumentParser(description='Run Selenium tests with specified data')
parser.add_argument('--host', type=str, default='http://127.0.0.1:8080', help='Host address for testing')
parser.add_argument('--login', type=str, required=True, help='insert Username')
parser.add_argument('--password', type=str, required=True, help='insert Password')
script_dir = os.path.dirname(os.path.abspath(__file__))
parser.add_argument('--pres', type=str, default=os.path.join(script_dir, 'tests_data/example_of_pres.pptx'), help='your path to press for testing')
parser.add_argument('--report', type=str, default=os.path.join(script_dir, 'tests_data/example_of_report.docx'), help='your path to report in .docx')
parser.add_argument('--report_doc', type=str, default=os.path.join(script_dir, 'tests_data/example_of_report.doc'), help='your path to report in .doc')


parser.add_argument('--pres', type=str, default=os.path.join(script_dir, 'tests_data/example_of_pres.pptx'),
help='your path to press for testing')
parser.add_argument('--report', type=str, default=os.path.join(script_dir, 'tests_data/example_of_report.docx'),
help='your path to report in .docx')
parser.add_argument('--report_doc', type=str, default=os.path.join(script_dir, 'tests_data/example_of_report.doc'),
help='your path to report in .doc')

return parser.parse_args()


def main():
args = parse_arguments()

suite = unittest.TestSuite()
tests = (AuthTestSelenium, StatisticTestSelenium, FileLoadTestSelenium, SingleCheckTestSelenium, VersionTestSelenium)
tests = (
AuthTestSelenium, StatisticTestSelenium, FileLoadTestSelenium, SingleCheckTestSelenium, VersionTestSelenium, CsvDownloadTestSelenium)
param = (args.host, args.login, args.password, args.report, args.report_doc, args.pres)
for test in tests:
suite.addTest(BasicSeleniumTest.parametrize(test, param=param))
Expand All @@ -36,5 +42,6 @@ def main():
BasicSeleniumTest.close_driver()
sys.exit(returncode)


if __name__ == '__main__':
main()
75 changes: 75 additions & 0 deletions tests/test_csv_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os
import time
import pandas as pd
import requests
from basic_selenium_test import BasicSeleniumTest
from selenium.webdriver.common.by import By


def get_downloads_path():
if os.name == 'nt':
return os.path.join(os.environ['USERPROFILE'], 'Downloads')
else:
return os.path.join(os.environ['HOME'], 'Downloads')

def get_latest_csv(dir):
files = [os.path.join(dir, f) for f in os.listdir(dir)]
latest_file = max(files, key=os.path.getmtime)
return latest_file


class CsvDownloadTestSelenium(BasicSeleniumTest):

def test_http_connection(self):
csv_url = 'http://localhost:8080/get_csv'

response = requests.get(csv_url)
self.assertEqual(response.status_code, 200, f"Ошибка при скачивании CSV файла. Статус: {response.status_code}")


def test_csv_add_download(self):
self.authorization()
URL = self.get_url('/check_list')
self.get_driver().get(URL)
self.get_driver().implicitly_wait(30)

csv_button = self.driver.find_element(By.XPATH, '//button[text()="CSV"]')
csv_button.click()

time.sleep(10)

download_dir = get_downloads_path()

csv_file = get_latest_csv(download_dir)
self.assertTrue(csv_file.endswith('.csv'), "Скачанный файл не является CSV файлом.")



def test_csv_content(self):
download_dir = get_downloads_path()
csv_file = get_latest_csv(download_dir)
df = pd.read_csv(csv_file)
expected_columns =['_id', 'filename', 'criteria', 'user', 'upload-date', 'score']
for column in expected_columns:
self.assertIn(column, df.columns, f"Столбец '{column}' не найден в файле CSV.")

def test_csv_download_and_filter(self):
file_name_input = self.driver.find_element(By.CSS_SELECTOR, 'input.form-control.bootstrap-table-filter-control-filename.search-input')

file_name_input.send_keys('example_of_report.docx')
file_name_sort_button = self.driver.find_element(By.XPATH, '//div[contains(@class, "th-inner") and contains(@class, "sortable") and text()="File name"]')
file_name_sort_button.click()

time.sleep(5)

csv_button = self.driver.find_element(By.XPATH, '//button[text()="CSV"]')
csv_button.click()

time.sleep(10)

download_dir = get_downloads_path()
latest_file = get_latest_csv(download_dir)

df = pd.read_csv(latest_file)
filtered_by_name = df[df['filename'] == 'example_of_report.docx']
self.assertTrue(len(filtered_by_name) > 0, "Нет данных, отфильтрованных по имени файла.")

0 comments on commit 230a567

Please sign in to comment.