diff --git a/projects/Check_website_connectivity/test_CheckConnectivityMain.py b/projects/Check_website_connectivity/test_CheckConnectivityMain.py new file mode 100644 index 000000000..b7a8ca0eb --- /dev/null +++ b/projects/Check_website_connectivity/test_CheckConnectivityMain.py @@ -0,0 +1,125 @@ +# ********RoostGPT******** +""" +Test generated by RoostGPT for test python-testing using AI Type AWS Bedrock Runtime AI and AI Model mistral.mixtral-8x7b-instruct-v0:1 + +ROOST_METHOD_HASH=main_636ec99367 +ROOST_METHOD_SIG_HASH=main_105191a9d8 + + + Scenario 1: Test if the function correctly reads the websites from the text file +Details: + TestName: test\_read\_websites + Description: Verify that the function correctly reads the list of websites from the "websites.txt" file and stores them in a dictionary. +Execution: + Arrange: Ensure the "websites.txt" file exists with some website URLs. + Act: Call the main function. + Assert: Check if the status\_dict contains the correct number of websites and their corresponding statuses. +Validation: + Ensuring the correct reading of websites from the text file is crucial for the function to process and check the status of each website. + +Scenario 2: Test if the function correctly retrieves the HTTP status code for a given website +Details: + TestName: test\_get\_status\_code + Description: Verify that the function correctly retrieves the HTTP status code for a given website using the requests.get() method. +Execution: + Arrange: Prepare a test website URL. + Act: Call the main function with the test website URL added to the "websites.txt" file. + Assert: Check if the status\_dict contains the correct status for the test website URL. +Validation: + Retrieving the correct HTTP status code for each website is essential to determine if the website is working or not. + +Scenario 3: Test if the function correctly sets the status of a website as "working" or "not working" +Details: + TestName: test\_set\_status + Description: Verify that the function correctly sets the status of a website as "working" if the HTTP status code is 200, or "not working" otherwise. +Execution: + Arrange: Prepare a test website URL and its corresponding HTTP status code (200 or non-200). + Act: Call the main function with the test website URL added to the "websites.txt" file. + Assert: Check if the status\_dict contains the correct status for the test website URL. +Validation: + Properly setting the status of a website is necessary for accurate reporting and further processing. + +Scenario 4: Test if the function correctly writes the website statuses to a CSV file +Details: + TestName: test\_write\_to\_csv + Description: Verify that the function correctly writes the website statuses to a CSV file named "website\_status.csv". +Execution: + Arrange: Call the main function. + Act: Inspect the "website\_status.csv" file. + Assert: Check if the CSV file contains the correct number of rows and columns, with the correct website URLs and their corresponding statuses. +Validation: + Writing the website statuses to a CSV file is important for further processing and reporting purposes. +""" + +# ********RoostGPT******** +import csv +import requests +from projects.Check_website_connectivity.check_connectivity import main + +class Test_CheckConnectivityMain: + + def test_read_websites(self): + # TODO: Arrange - Ensure the "websites.txt" file exists with some website URLs. + main() + # Act + actual_websites = list(status_dict.keys()) + expected_websites = ["example.com", "google.com"] # TODO: Update this with actual values from the "websites.txt" file + + # Assert + assert len(actual_websites) == len(expected_websites), \ + f"Expected {len(expected_websites)} websites, but got {len(actual_websites)}" + for website in expected_websites: + assert website in actual_websites, f"Missing website: {website}" + + def test_get_status_code(self): + # Arrange + test_website = "example.com" # TODO: Update this with an actual website URL + + with open("websites.txt", "a") as fw: + fw.write(test_website + "\n") + + # Act + main() + + # Assert + actual_status = status_dict[test_website] + expected_status = requests.get(test_website).status_code + + assert actual_status == "working" if expected_status == 200 else "not working", \ + f"Expected status {expected_status}, but got {actual_status}" + + def test_set_status(self): + # Arrange + test_website = "example.com" # TODO: Update this with an actual website URL + test_status_code = 200 # TODO: Update this with an actual status code + + with open("websites.txt", "a") as fw: + fw.write(test_website + "\n") + + # Act + main() + + # Assert + actual_status = status_dict[test_website] + expected_status = "working" if test_status_code == 200 else "not working" + + assert actual_status == expected_status, \ + f"Expected status {expected_status}, but got {actual_status}" + + def test_write_to_csv(self): + # Act + main() + + # Assert + with open("website_status.csv", "r") as fr: + csv_reader = csv.reader(fr) + actual_rows = list(csv_reader) + + expected_rows = [["Website", "Status"]] # TODO: Update this with actual values + + assert len(actual_rows) == len(expected_rows), \ + f"Expected {len(expected_rows)} rows, but got {len(actual_rows)}" + + for actual_row, expected_row in zip(actual_rows, expected_rows): + assert actual_row == expected_row, \ + f"Expected row {expected_row}, but got {actual_row}" diff --git a/requirements-roost.txt b/requirements-roost.txt new file mode 100644 index 000000000..bb593598b --- /dev/null +++ b/requirements-roost.txt @@ -0,0 +1,3 @@ + +-r /var/tmp/Roost/RoostGPT/python-testing/f64729a4-e7d7-40bb-aae8-81b8f20af988/source/python-mini-projects/projects/Check_website_connectivity/requirements.txtprojects +Requests \ No newline at end of file