<commit_before>from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import unittest
import sys
import time
from base_test_class import BaseTestCase, on_exception_html_source_logger
from selenium.webdriver.common.by import By


class WaitForPageLoad(object):
    def __init__(self, browser, timeout):
        self.browser = browser
        self.timeout = time.time() + timeout

    def __enter__(self):
        self.old_page = self.browser.find_element_by_tag_name('html')

    def page_has_loaded(self):
        new_page = self.browser.find_element_by_tag_name('html')
        return new_page.id != self.old_page.id

    def __exit__(self, *_):
        while time.time() < self.timeout:
            if self.page_has_loaded():
                return True
            else:
                time.sleep(0.2)
        raise Exception(
            'Timeout waiting for {}s'.format(self.timeout)
        )


class ProductTest(BaseTestCase):

    @on_exception_html_source_logger
    def test_create_product(self):
        # make sure no left overs from previous runs are left behind
        self.delete_product_if_exists()

        driver = self.login_page()
        # Navigate to the product page
        self.goto_product_overview(driver)
        # "Click" the dropdown button to see options
        driver.find_element_by_id("dropdownMenu1").click()
        # "Click" the add prodcut button
        driver.find_element_by_link_text("Add Product").click()
        # Fill in th product name
        driver.find_element_by_id("id_name").clear()
        driver.find_element_by_id("id_name").send_keys("QA <PASSWORD>")
        # Tab into the description area to fill some text
        # Couldnt find a way to get into the box with selenium
        driver.find_element_by_id("id_name").send_keys("\tThis is just a test. Be very afraid.")
        # Select an option in the poroduct type
        # some wild guess to print some debug info
        Select(driver.find_element_by_id("id_prod_type")).select_by_visible_text("Research and Development")
        # "Click" the submit button to complete the transaction
        driver.find_element_by_css_selector("input.btn.btn-primary").click()
        # Query the site to determine if the product has been added

        # Assert ot the query to dtermine status of failure
        # Also confirm success even if Product is returned as already exists for test sake
        self.assertTrue(self.is_success_message_present(text='Product added successfully') or
            self.is_success_message_present(text='Product with this Name already exists.'))

    @on_exception_html_source_logger
    def test_list_products(self):
        driver = self.login_page()
        # Navigate to the product page
        self.goto_product_overview(driver)
        # list products which will make sure there are no javascript errors such as before in https://github.com/DefectDojo/django-DefectDojo/issues/2050

    @on_exception_html_source_logger
    def test_list_components(self):
        driver = self.login_page()
        self.goto_product_overview(driver)
        driver.find_element_by_link_text("QA Test").click()
        driver.find_element_by_link_text("Components").click()
        driver.find_element_by_id("product_component_view").click()
        self.assertTrue(self.is_element_by_css_selector_present("table"))



    # For product consistency sake, We won't be editting the product title
    # instead We can edit the product description
    @on_exception_html_source_logger
    def test_edit_product_description(self):
        # Login to the site. Password will have to be modified
        # to match an admin password in your own container
        driver = self.login_page()
        # Navigate to the product page
        self.goto_product_overview(driver)
        # Select and click on the particular product to edit
        driver.find_element_by_link_text("QA Test").click()
        # "Click" the dropdown option<commit_msg>fix linting (#3024)<commit_after>from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import unittest
import sys
import time
from base_test_class import BaseTestCase, on_exception_html_source_logger
from selenium.webdriver.common.by import By


class WaitForPageLoad(object):
    def __init__(self, browser, timeout):
        self.browser = browser
        self.timeout = time.time() + timeout

    def __enter__(self):
        self.old_page = self.browser.find_element_by_tag_name('html')

    def page_has_loaded(self):
        new_page = self.browser.find_element_by_tag_name('html')
        return new_page.id != self.old_page.id

    def __exit__(self, *_):
        while time.time() < self.timeout:
            if self.page_has_loaded():
                return True
            else:
                time.sleep(0.2)
        raise Exception(
            'Timeout waiting for {}s'.format(self.timeout)
        )


class ProductTest(BaseTestCase):

    @on_exception_html_source_logger
    def test_create_product(self):
        # make sure no left overs from previous runs are left behind
        self.delete_product_if_exists()

        driver = self.login_page()
        # Navigate to the product page
        self.goto_product_overview(driver)
        # "Click" the dropdown button to see options
        driver.find_element_by_id("dropdownMenu1").click()
        # "Click" the add prodcut button
        driver.find_element_by_link_text("Add Product").click()
        # Fill in th product name
        driver.find_element_by_id("id_name").clear()
        driver.find_element_by_id("id_name").send_keys("QA <PASSWORD>")
        # Tab into the description area to fill some text
        # Couldnt find a way to get into the box with selenium
        driver.find_element_by_id("id_name").send_keys("\tThis is just a test. Be very afraid.")
        # Select an option in the poroduct type
        # some wild guess to print some debug info
        Select(driver.find_element_by_id("id_prod_type")).select_by_visible_text("Research and Development")
        # "Click" the submit button to complete the transaction
        driver.find_element_by_css_selector("input.btn.btn-primary").click()
        # Query the site to determine if the product has been added

        # Assert ot the query to dtermine status of failure
        # Also confirm success even if Product is returned as already exists for test sake
        self.assertTrue(self.is_success_message_present(text='Product added successfully') or
            self.is_success_message_present(text='Product with this Name already exists.'))

    @on_exception_html_source_logger
    def test_list_products(self):
        driver = self.login_page()
        # Navigate to the product page
        self.goto_product_overview(driver)
        # list products which will make sure there are no javascript errors such as before in https://github.com/DefectDojo/django-DefectDojo/issues/2050

    @on_exception_html_source_logger
    def test_list_components(self):
        driver = self.login_page()
        self.goto_product_overview(driver)
        driver.find_element_by_link_text("QA Test").click()
        driver.find_element_by_link_text("Components").click()
        driver.find_element_by_id("product_component_view").click()
        self.assertTrue(self.is_element_by_css_selector_present("table"))

    # For product consistency sake, We won't be editting the product title
    # instead We can edit the product description
    @on_exception_html_source_logger
    def test_edit_product_description(self):
        # Login to the site. Password will have to be modified
        # to match an admin password in your own container
        driver = self.login_page()
        # Navigate to the product page
        self.goto_product_overview(driver)
        # Select and click on the particular product to edit
        driver.find_element_by_link_text("QA Test").click()
        # "Click" the dropdown option
{'fraction_non_alphanumeric': 0.07649114050411779, 'fraction_numerical': 0.002246069378587472, 'mean_word_length': 3.112365315546434, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7290186', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2168, 'n_words': 621}