Esempio n. 1
0
class TestDuplicateComment(unittest.TestCase):
    def setUp(self):
        self.app = Aplication()

    def tearDown(self):
        self.app.driver.close()

    def test_duplicate_comment(self):
        self.app.select_first_comment()
        self.app.duplicate_button()

        # data duplicate comment
        duplicate_number = self.app.driver.find_element_by_id("Number")
        duplicate_number.clear()
        duplicate_number.send_keys(*data_duplicate_comment[0])
        duplicate_text = self.app.driver.find_element_by_id("Text")
        duplicate_text.clear()
        duplicate_text.send_keys(*data_duplicate_comment[1])
        duplicate_selected_categories = \
            self.app.driver.find_element_by_id("selectedCategories").text
        duplicate_comment = Comment(*data_duplicate_comment[0],
                                    *data_duplicate_comment[1],
                                    duplicate_selected_categories)
        self.app.save_return()

        # check an element
        list_comments = self.app.all_comments()
        self.assertIn(duplicate_comment, list_comments)

    def test_duplicate_comment_without_changes(self):
        self.app.select_second_comment()
        self.app.duplicate_button()
        self.app.save_button()
        warning = self.app.driver.find_element_by_id("errorfield").text
        self.assertEqual(warning, expected_variables["unique_number_field"])

    def test_not_selected_duplicate_comment(self):
        self.app.duplicate_button()
        alert = self.app.driver.switch_to.alert
        warning = alert.text
        alert.accept()
        self.assertEqual(warning, expected_variables["select_one_category"])

    def test_two_items_selected(self):
        # select items for duplicate
        self.app.select_first_comment()
        self.app.select_second_comment()

        self.app.duplicate_button()
        alert = self.app.driver.switch_to.alert
        warning = alert.text
        alert.accept()
        self.assertEqual(warning, expected_variables["select_one_category"])
Esempio n. 2
0
class TestNewComment(unittest.TestCase):
    def setUp(self):
        self.app = Aplication()

    def tearDown(self):
        self.app.driver.close()

    def test_empty_field_comment(self):
        self.app.new_button()
        comment_text_field = self.app.driver.find_element_by_id("Text").text
        self.assertEqual(comment_text_field, "")

    def test_empty_field_number(self):
        self.app.new_button()
        comment_number_field = \
            self.app.driver.find_element_by_id("Number").text
        self.assertEqual(comment_number_field, "")

    def test_empty_field_categories(self):
        self.app.new_button()
        comment_selected_categories = \
            self.app.driver.find_element_by_id("selectedCategories").text
        self.assertEqual(comment_selected_categories, "")

    def test_new_comment(self):
        # check for entering a new comment with a choice of all categories
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[0]))
        self.app.button_all_categories()
        self.app.save_return()

        # check an element
        list_comments = self.app.all_comments()
        self.assertIn(expected_variables["first_comment"], list_comments)

    def test_new_comment_two_categories(self):
        # check for entering a new comment with two categories
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[1]))
        self.app.select_two_categories()
        self.app.save_return()

        # check an element
        list_comments = self.app.all_comments()
        self.assertIn(expected_variables["second_comment"], list_comments)

    def test_new_comment_without_categories(self):
        # check for entering a new comment with no categories
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[2]))
        self.app.save_button()
        warning = self.app.driver.find_element_by_id("errorfield").text
        self.assertEqual(warning, expected_variables["at_list_one_category"])

    def test_new_comment_text_comment(self):
        # check for entering a new comment with no text comment
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[3]))
        self.app.save_button()
        warning = self.app.driver.find_element_by_id("errorfield").text
        self.assertEqual(warning, expected_variables["text_field_is_required"])

    def test_refresh_button(self):
        # check for entering a new comment with refresh button
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[0]))
        self.app.refresh_button()
        comment_text_field = self.app.driver.find_element_by_id("Text").text
        comment_number_field = self.app.driver.find_element_by_id(
            "Number").text
        comment_selected_categories = \
            self.app.driver.find_element_by_id("selectedCategories").text
        empty_fields = [
            comment_text_field, comment_number_field,
            comment_selected_categories
        ]
        self.assertListEqual(empty_fields, expected_variables["empty_list"])

    def test_invalid_text_comment(self):
        # check for entering a new comment with invalid text comment
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[4]))
        block_warning = \
            self.app.driver.find_element_by_class_name("field-"
                                                       "validation-error")
        warning = block_warning.find_element_by_tag_name("span").text
        self.assertEqual(warning, expected_variables["max_text_field"])

    def test_negative_number_comment(self):
        # check for entering a new comment with negative number comment
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[5]))
        self.app.select_two_categories()
        self.app.save_button()
        warning = self.app.driver.find_element_by_id("errorfield").text
        self.assertEqual(warning, expected_variables["contains_only_digits"])

    def test_max_number_comment(self):
        # check for entering a new comment with max value number comment
        self.app.new_button()
        self.app.adding_data(Arguments(*new_comment_data[6]))
        self.app.select_two_categories()
        self.app.save_button()
        warning = self.app.driver.find_element_by_id("errorfield").text
        self.assertEqual(warning, expected_variables["unique_number_field"])