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"])
class TestDeleteComment(unittest.TestCase): def setUp(self): self.app = Aplication() def tearDown(self): self.app.driver.close() def test_delete_comment(self): # select item comment_for_delete = \ self.app.driver.find_element_by_css_selector("tbody > " "tr:nth-child(1)") text = comment_for_delete.find_element_by_class_name("textcolumn").text number = \ comment_for_delete.find_element_by_class_name("numbercolumn").text categories = \ comment_for_delete.find_element_by_class_name("categorycolumn").text delete_comment = Comment(number, text, categories) self.app.driver.find_element_by_name("SelectedId").click() self.app.delete_button() # check is comment delete list_comments = self.app.all_comments() self.assertNotIn(delete_comment, list_comments) def test_not_selected_delete_comment(self): self.app.driver.find_element_by_xpath("//input[@value = " "'Delete']").click() 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 self.app.select_first_comment() self.app.select_second_comment() self.app.delete_button() # check is comments delete actual_text = \ self.app.driver.find_element_by_xpath("// *[ @ id = " "'infoField']").text self.assertEqual(actual_text, expected_variables["deleted_successfull"])
class TestEditComment(unittest.TestCase): def setUp(self): self.app = Aplication() def tearDown(self): self.app.driver.close() def test_edit_comment(self): self.app.select_first_comment() self.app.edit_button() # data edit comment edit_text = self.app.driver.find_element_by_id("Text") edit_text.clear() edit_text.send_keys(new_data[0][0]) edit_number = self.app.driver.find_element_by_id("Number") edit_number.clear() edit_number.send_keys(new_data[0][1]) edit_selected_categories = \ self.app.driver.find_element_by_id("selectedCategories").text edit_comment = Comment(new_data[0][1], new_data[0][0], edit_selected_categories) self.app.save_return() # check is comment edit list_comments = self.app.all_comments() self.assertIn(edit_comment, list_comments) def test_is_old_comment_change(self): # select item comment_for_edit = \ self.app.driver.find_element_by_css_selector("tbody > " "tr:nth-child(1)") text = \ comment_for_edit.find_element_by_class_name("textcolumn").text number = \ comment_for_edit.find_element_by_class_name("numbercolumn").text categories = \ comment_for_edit.find_element_by_class_name("categorycolumn").text old_comment = Comment(number, text, categories) self.app.driver.find_element_by_name("SelectedId").click() self.app.edit_button() # data edit comment edit_text = self.app.driver.find_element_by_id("Text") edit_text.clear() edit_text.send_keys(new_data[1][0]) edit_number = self.app.driver.find_element_by_id("Number") edit_number.clear() edit_number.send_keys(new_data[1][1]) self.app.save_return() # check is no old comment list_comments = self.app.all_comments() self.assertNotIn(old_comment, list_comments) def test_not_selected_edit_comment(self): self.app.edit_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 edit self.app.select_first_comment() self.app.select_second_comment() self.app.edit_button() alert = self.app.driver.switch_to.alert warning = alert.text alert.accept() self.assertEqual(warning, expected_variables["select_one_category"])