def test019_filter_by_changed_by(self):
        """
        Header: Roles & Permissions Approach: Make sure that you can filter by role changed by

        LIMS-6507
        """
        self.login_page = Login()
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, response)
        self.login_page.logout()
        self.header_page.sleep_tiny()
        self.info('login with role & user {}:{}'.format(payload['username'], payload['password']))
        self.login_page.login(username=payload['username'], password=payload['password'])
        self.header_page.wait_until_page_is_loaded()
        self.header_page.sleep_medium()
        self.header_page.get_roles_page()
        self.header_page.sleep_small()
        random_role_name = self.generate_random_string()
        self.header_page.create_new_role(role_name=random_role_name)
        self.header_page.click_on_table_configuration_button()
        self.base_selenium.click(element='roles_and_permissions:checked_role_changed_by')
        self.base_selenium.click(element='roles_and_permissions:apply_btn')
        self.header_page.sleep_tiny()
        roles_results = self.header_page.filter_user_by(
            filter_element='roles_and_permissions:filter_changed_by',
            filter_text=payload['username'], field_type='drop_down')
        for roles_result in roles_results:
            self.assertIn(payload['username'], roles_result['Changed By'])
예제 #2
0
class LoginTestCases(BaseTest):
    def setUp(self):
        super().setUp()
        self.login_page = Login()

    def test001_login_correct_data(self):
        """
        Login with valid data
        :return:
        """
        self.login_page.login(username=self.base_selenium.username,
                              password=self.base_selenium.password)
        time.sleep(15)
        self.assertIn('dashboard', self.login_page.base_selenium.get_url())

    @parameterized.expand([('admin', ''), ('', 'admin'), ('', ''),
                           (147852963, 147852963), ('#!@#!@#', '#!@#!@#!@'),
                           ("' 1==1 &", "' 1==1 &")])
    def test002_login_incorrect_data(self, username, password):
        """
        Login with non-valid data
        :param username:
        :param password:
        :return:
        """
        self.login_page.login(username=username, password=password)
        time.sleep(5)
        self.assertIn('login', self.login_page.base_selenium.get_url())
    def test019_filter_by_testplan_changed_by(self):
        """
        User can filter with changed by field

        LIMS-6475
        """
        self.login_page = Login()
        self.info('Calling the users api to create a new user with username')
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, payload)
        self.test_plan.sleep_tiny()
        self.login_page.logout()
        self.test_plan.sleep_tiny()
        self.login_page.login(username=payload['username'],
                              password=payload['password'])
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.test_plan.get_test_plans_page()
        self.test_plan.sleep_tiny()
        testplan_name = self.test_plan.create_new_test_plan()

        self.info('New testplan is created successfully with name: {}'.format(
            testplan_name))
        self.test_plan.set_all_configure_table_columns_to_specific_value(
            value=True)

        testplan_found = self.test_plan.filter_by_element_and_get_results(
            'Changed By', 'test_plans:testplan_changed_by_filter',
            payload['username'], 'drop_down')
        self.assertEqual(len(testplan_found), 2)
        self.assertIn(payload['username'], testplan_found[0].text)
        self.assertIn(testplan_name, testplan_found[0].text)
    def test015_create_role_with_sample_management_permissions_then_create_user_by_it(self):
        """
        Roles & Permissions: when I create user with sample management permissions then create
        user wit it when I login with this user the master data only should appear in the menu

        LIMS-6441
        """
        self.login_page = Login()
        self.info("create role with random name with sample management permissions")
        random_role_name = self.generate_random_string()
        self.header_page.create_role_with_sample_management_permissions(role_name=random_role_name)

        self.info('go to the user section to create user with this role')
        self.header_page.get_users_page()
        random_user_name = self.generate_random_string()
        random_user_email = self.header_page.generate_random_email()
        random_user_password = self.generate_random_string()
        self.header_page.create_new_user(user_name=random_user_name,
                                         user_email=random_user_email,
                                         user_role=random_role_name,
                                         user_password=random_user_password,
                                         user_confirm_password=random_user_password)

        self.login_page.logout()

        self.info('login with role & user {}:{}'.format(random_user_name, random_user_password))
        self.login_page.login(username=random_user_name, password=random_user_password)
        self.header_page.sleep_medium()
        self.info('get the order url')
        self.assertTrue('Sample Management', Order().get_orders_page())
        self.info('get the analysis url')
        Orders().navigate_to_analysis_active_table()
        self.assertIn('sample/analysis', self.base_selenium.get_url())
예제 #5
0
 def setUp(self):
     super().setUp()
     self.login_page = Login()
     self.article_page = Article()
     self.test_plan = TstPlan()
     self.order = Order()
     self.login_page.login(username=self.base_selenium.username,
                           password=self.base_selenium.password)
     self.base_selenium.wait_until_page_url_has(text='dashboard')
     self.article_page.get_article_page()
예제 #6
0
    def setUp(self):
        super().setUp()
        self.login_page = Login()
        self.header_page = Header()
        self.roles_api = RolesAPI()
        self.login_page.base_selenium.refresh()
        self.login_page.logout()
        response, payload = UsersAPI().create_new_user()

        self.user_name = response['user']['username']
        self.info("login with new user {} and pw {}".format(self.user_name, payload['password']))

        self.login_page.login(username=self.user_name, password=payload['password'])
        self.header_page.wait_until_page_is_loaded()
        self.header_page.get_users_page()
예제 #7
0
class ArticlesTestCasesTrial(BaseTest):
    def setUp(self):
        super().setUp()
        self.login_page = Login()
        self.article_page = Article()
        self.test_plan = TstPlan()
        self.order = Order()
        self.login_page.login(username=self.base_selenium.username,
                              password=self.base_selenium.password)
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.article_page.get_article_page()

    @parameterized.expand(['save', 'cancel'])
    def test001_cancel_button_edit_unit(self, save):
        """
        New: Article: Save/Cancel button: After I edit unit field then press on cancel button,
        a pop up will appear that the data will be

        LIMS-3586
        LIMS-3576
        :return:
        """
        self.article_page.get_random_article()
        article_url = self.base_selenium.get_url()
        self.base_selenium.LOGGER.info(
            ' + article_url : {}'.format(article_url))
        current_unit = self.article_page.get_unit()
        new_unit = self.generate_random_string()
        self.article_page.set_unit(new_unit)
        if 'save' == save:
            self.article_page.save()
        else:
            self.article_page.cancel(force=True)

        self.base_selenium.get(url=article_url,
                               sleep=self.base_selenium.TIME_MEDIUM)

        article_unit = self.article_page.get_unit()
        if 'save' == save:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (new_unit) == {} (article_unit)'.format(
                    new_unit, article_unit))
            self.assertEqual(new_unit, article_unit)
        else:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (current_unit) == {} (article_unit)'.format(
                    current_unit, article_unit))
            self.assertEqual(current_unit, article_unit)
    def test049_filter_by_testunit_changed_by(self):
        """
        New: Test units: Filter Approach: Make sure you can filter by changed by

        LIMS-6428
        """
        self.login_page = Login()
        self.info('Calling the users api to create a new user with username')
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, payload)
        self.login_page.logout()
        self.login_page.login(username=payload['username'], password=payload['password'])
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.test_units_page.get_test_units_page()
        new_name = self.generate_random_string()
        method = self.generate_random_string()
        test_unit_no = self.test_unit_page.create_qualitative_testunit(name=new_name, method=method)
        self.test_unit_page.save_and_wait()
        self.assertTrue(test_unit_no, 'Test unit not created')
        self.info('New unit is created successfully with number: {}'.format(test_unit_no))
        self.test_units_page.sleep_tiny()
        test_unit_found = self.test_units_page.filter_by_user_get_result(payload['username'])
        self.assertTrue(test_unit_found)
    def test014_create_role_with_master_data_permissions_then_create_user_by_it(self):
        """
        Roles & Permissions: when I create user with master data permissions then create user wit it
        when I login with this user the master data only should appear in the menu

        LIMS-6440
        """
        self.login_page = Login()
        self.info('create role with random name with master data permissions')
        random_role_name = self.generate_random_string()
        self.header_page.create_role_with_mater_data_permissions(role_name=random_role_name)

        self.info('go to the user section to create user with this role')
        self.header_page.get_users_page()
        random_user_name = self.generate_random_string()
        random_user_email = self.header_page.generate_random_email()
        random_user_password = self.generate_random_string()
        self.header_page.create_new_user(user_name=random_user_name,
                                         user_email=random_user_email,
                                         user_role=random_role_name,
                                         user_password=random_user_password,
                                         user_confirm_password=random_user_password)

        self.login_page.logout()

        self.info('login with role & user {}:{}'.format(random_user_name, random_user_password))
        self.login_page.login(username=random_user_name, password=random_user_password)
        self.header_page.sleep_medium()
        # make sure that all the master data pages appear(articles & test units & test plans & contacts)
        self.info('get the test unit url')
        self.assertTrue('Test Units', TstUnit().get_test_units_page())
        self.info('get the articles url')
        self.assertTrue('Articles', Article().get_articles_page())
        self.info('get the test plan url')
        self.assertTrue('Test Plans', TstPlan().get_test_plans_page())
        self.info('get the contacts url')
        self.assertTrue('Contacts', Contacts().get_contacts_page())
예제 #10
0
class LoginRandomUser(BaseTest):
    def setUp(self):
        super().setUp()
        self.login_page = Login()
        self.header_page = Header()
        self.roles_api = RolesAPI()
        self.login_page.base_selenium.refresh()
        self.login_page.logout()
        response, payload = UsersAPI().create_new_user()

        self.user_name = response['user']['username']
        self.info("login with new user {} and pw {}".format(self.user_name, payload['password']))

        self.login_page.login(username=self.user_name, password=payload['password'])
        self.header_page.wait_until_page_is_loaded()
        self.header_page.get_users_page()

    def tearDown(self):
        self.set_authorization(auth=self.roles_api.AUTHORIZATION_RESPONSE)
        super().tearDown()

    @attr(series=True)
    def test016_delete_user_used_in_other_entity(self):
        """
        User management: Make sure that you can't delete any user record If this record used in other entity

        LIMS-6407
        """
        last_row = self.header_page.get_last_user_row()
        self.header_page.click_check_box(source=last_row)
        self.header_page.archive_entity(menu_element='user_management:right_menu',
                                        archive_element='user_management:archive')
        self.header_page.get_archived_entities(menu_element='user_management:right_menu',
                                               archived_element='user_management:archived')

        last_row = self.header_page.get_last_user_row()
        self.header_page.click_check_box(source=last_row)
        self.header_page.delete_entity()
        self.assertTrue(self.base_selenium.element_is_displayed(element='general:confirmation_pop_up'))

    @attr(series=True)
    def test017_filter_by_changed_by(self):
        """
        Header: Roles & Permissions Approach: Make sure that you can filter by role changed by

        LIMS-6507
        """
        new_user = self.generate_random_string()
        new_email = self.header_page.generate_random_email()
        self.header_page.create_new_user(user_name=new_user, user_email=new_email,
                                         user_role='Admin', user_password='******', user_confirm_password='******')

        self.header_page.click_on_user_config_btn()
        self.base_selenium.click(element='user_management:checked_changed_by')
        self.base_selenium.click(element='user_management:apply_btn')

        self.header_page.sleep_tiny()
        user_results = self.header_page.filter_user_by(filter_element='user_management:filter_changed_by',
                                                       filter_text=self.user_name, field_type='drop_down')

        self.assertEqual(self.user_name, user_results[0]['Changed By'])
예제 #11
0
class ArticlesTestCases(BaseTest):
    def setUp(self):
        super().setUp()
        self.login_page = Login()
        self.article_page = Article()
        self.test_plan = TstPlan()
        self.order = Order()
        self.login_page.login(username=self.base_selenium.username,
                              password=self.base_selenium.password)
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.article_page.get_article_page()

    @parameterized.expand(['save', 'cancel'])
    def test001_cancel_button_edit_unit(self, save):
        """
        New: Article: Save/Cancel button: After I edit unit field then press on cancel button,
        a pop up will appear that the data will be

        LIMS-3586
        LIMS-3576
        :return:
        """
        self.article_page.get_random_article()
        article_url = self.base_selenium.get_url()
        self.base_selenium.LOGGER.info(
            ' + article_url : {}'.format(article_url))
        current_unit = self.article_page.get_unit()
        new_unit = self.generate_random_string()
        self.article_page.set_unit(new_unit)
        if 'save' == save:
            self.article_page.save()
        else:
            self.article_page.cancel(force=True)

        self.base_selenium.get(url=article_url,
                               sleep=self.base_selenium.TIME_MEDIUM)

        article_unit = self.article_page.get_unit()
        if 'save' == save:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (new_unit) == {} (article_unit)'.format(
                    new_unit, article_unit))
            self.assertEqual(new_unit, article_unit)
        else:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (current_unit) == {} (article_unit)'.format(
                    current_unit, article_unit))
            self.assertEqual(current_unit, article_unit)

    @parameterized.expand(['save', 'cancel'])
    def test002_cancel_button_edit_no(self, save):
        """
        New: Article: Save/Cancel button: After I edit no field then press on cancel button,
        a pop up will appear that the data will be

        LIMS-3586
        LIMS-3576
        :return:
        """
        self.article_page.get_random_article()
        article_url = self.base_selenium.get_url()
        self.base_selenium.LOGGER.info(
            ' + article_url : {}'.format(article_url))
        current_no = self.article_page.get_no()
        new_no = self.generate_random_string()
        self.article_page.set_no(new_no)
        if 'save' == save:
            self.article_page.save()
        else:
            self.article_page.cancel(force=True)

        self.base_selenium.get(url=article_url,
                               sleep=self.base_selenium.TIME_MEDIUM)

        article_no = self.article_page.get_no()
        if 'save' == save:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (new_no) == {} (article_no)'.format(
                    new_no, article_no))
            self.assertEqual(new_no, article_no)
        else:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (current_no) == {} (article_no)'.format(
                    current_no, article_no))
            self.assertEqual(current_no, article_no)

    @parameterized.expand(['save', 'cancel'])
    def test003_cancel_button_edit_name(self, save):
        """
        New: Article: Save/Cancel button: After I edit name then press on cancel button,
        a pop up will appear that the data will be

        LIMS-3586
        LIMS-3576
        :return:
        """
        self.article_page.get_random_article()
        article_url = self.base_selenium.get_url()
        self.base_selenium.LOGGER.info(
            ' + article_url : {}'.format(article_url))
        current_name = self.article_page.get_name()
        new_name = self.generate_random_string()
        self.article_page.set_name(new_name)

        if 'save' == save:
            self.article_page.save()
        else:
            self.article_page.cancel(force=True)

        self.base_selenium.get(url=article_url,
                               sleep=self.base_selenium.TIME_MEDIUM)

        article_name = self.article_page.get_name()
        if 'save' == save:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (new_name) == {} (article_name)'.format(
                    new_name, article_name))
            self.assertEqual(new_name, article_name)
        else:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (current_name) == {} (article_name)'.format(
                    current_name, article_name))
            self.assertEqual(current_name, article_name)

    @parameterized.expand(['save', 'cancel'])
    def test004_cancel_button_edit_comment(self, save):
        """
        New: Article: Save/Cancel button: After I edit comment then press on cancel button,
        a pop up will appear that the data will be

        LIMS-3586
        LIMS-3576
        :return:
        """
        self.article_page.get_random_article()
        article_url = self.base_selenium.get_url()
        self.base_selenium.LOGGER.info(
            ' + article_url : {}'.format(article_url))
        current_comment = self.article_page.get_comment()
        new_comment = self.generate_random_string()
        self.article_page.set_comment(new_comment)
        if 'save' == save:
            self.article_page.save()
        else:
            self.article_page.cancel(force=True)

        self.base_selenium.get(url=article_url,
                               sleep=self.base_selenium.TIME_MEDIUM)

        article_comment = self.article_page.get_comment()
        if 'save' == save:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (new_comment) == {} (article_comment)'.format(
                    new_comment, article_comment))
            self.assertEqual(new_comment, article_comment)
        else:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (current_comment) == {} (article_comment)'.
                format(current_comment, article_comment))
            self.assertEqual(current_comment, article_comment)

    @parameterized.expand(['save', 'cancel'])
    def test005_cancel_button_edit_material_type(self, save):
        """
        New: Article: Save/Cancel button: After I edit material_type then press on cancel button,
        a pop up will appear that the data will be

        LIMS-3586
        LIMS-3576
        :return:
        """
        self.article_page.get_random_article()
        article_url = self.base_selenium.get_url()
        self.base_selenium.LOGGER.info(
            ' + article_url : {}'.format(article_url))
        current_material_type = self.article_page.get_material_type()
        self.article_page.set_material_type(random=True)
        new_material_type = self.article_page.get_material_type()
        if 'save' == save:
            self.article_page.save()
        else:
            self.article_page.cancel(force=True)

        self.base_selenium.get(url=article_url, sleep=5)

        article_material = self.article_page.get_material_type()
        if 'save' == save:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (new_material_type) == {} (article_material_type)'
                .format(new_material_type, article_material))
            self.assertEqual(new_material_type,
                             self.article_page.get_material_type())
        else:
            self.base_selenium.LOGGER.info(
                ' + Assert {} (current_material_type) == {} (article_material_type)'
                .format(current_material_type, article_material))
            self.assertEqual(current_material_type,
                             self.article_page.get_material_type())

    def test006_archived_articles_shoudnt_dispaly_in_test_plan(self):
        """
        New: Article: In case I archived any article this article shouldn't display in the test plan module when
         I create test plan or edit it

         LIMS-3668
        :return:
        """
        self.article_page.create_new_article(material_type='Raw Material')
        self.base_selenium.LOGGER.info(' + Archive the article.')
        self.article_page.archive_article(name=self.article_page.article_name)
        self.test_plan.get_test_plans_page()
        self.base_selenium.LOGGER.info(
            ' + Create test plan with the same material type.')
        self.test_plan.click_create_test_plan_button()
        self.test_plan.set_material_type(
            material_type=self.article_page.article_material_type)
        self.article_page.sleep_tiny()
        self.base_selenium.LOGGER.info(
            ' + Assert article is not existing in the list.')
        self.assertFalse(
            self.test_plan.is_article_existing(
                article=self.article_page.article_name))

    def test007_archived_articles_shoudnt_dispaly_in_order(self):
        """
        New: Article: Archived any article this article shouldn't display in the order module

         LIMS-3668
        :return:
        """
        self.article_page.create_new_article(material_type='Raw Material')
        self.article_page.archive_article(name=self.article_page.article_name)
        self.order.get_orders_page()
        self.order.click_create_order_button()
        self.order.set_new_order()
        self.order.set_material_type(
            material_type=self.article_page.article_material_type)
        self.article_page.sleep_tiny()
        self.assertFalse(
            self.order.is_article_existing(
                article=self.article_page.article_name))

    def test008_created_article_appear_in_test_plan(self):
        """
            New: Article/Test plan: Any article I created should appear in the test plan according to the materiel type.

            LIMS-3581
        :return:
        """
        self.article_page.create_new_article(material_type='Raw Material')
        self.test_plan.get_test_plans_page()
        self.test_plan.click_create_test_plan_button()
        self.test_plan.set_material_type(
            material_type=self.article_page.article_material_type)
        self.article_page.sleep_tiny()
        self.assertTrue(
            self.test_plan.is_article_existing(
                article=self.article_page.article_name))

    def test009_create_article_with_test_plan_search_by_test_plan(self):
        """
        In case I create test plan with the article that I created, this test plan should display in the table view

        LIMS-3583
        :return:
        """
        self.article_page.create_new_article(material_type='Raw Material')
        self.test_plan.get_test_plans_page()
        self.test_plan.create_new_test_plan(
            material_type=self.article_page.article_material_type,
            article=self.article_page.article_name)
        self.article_page.get_article_page()
        self.article_page.sleep_small()
        article = self.article_page.search(
            value=self.test_plan.test_plan_name)[0]
        self.assertIn(self.test_plan.test_plan_name, article.text)

        self.test_plan.get_test_plans_page()
        self.test_plan.get_test_plan_edit_page(
            name=self.test_plan.test_plan_name)

        self.test_plan.clear_article()
        self.test_plan.set_article(article='All')
        self.test_plan.save()
        self.article_page.get_article_page()
        article = self.article_page.search(self.article_page.article_name)[0]
        self.assertNotIn(self.test_plan.test_plan_name, article.text)

    def test010_create_article_with_test_plan_filter_by_test_plan(self):
        """
        In case I create test plan with the article that I created, user could filter with test plan

        LIMS-3583
        :return:
        """
        self.article_page.create_new_article(material_type='Raw Material')
        self.test_plan.get_test_plans_page()
        self.test_plan.create_new_test_plan(
            material_type=self.article_page.article_material_type,
            article=self.article_page.article_name)
        self.article_page.get_article_page()
        self.article_page.sleep_small()

        self.article_page.filter_by_test_plan(
            filter_text=self.test_plan.test_plan_name)
        article = self.article_page.filter_result()[0]
        self.base_selenium.LOGGER.info(
            ' + Assert user could filter with test plan.')
        self.assertIn(self.test_plan.test_plan_name, article.text)

    def test011_archive_articles(self):
        """
        New: Article: Archive Approach: I can archive/restore any article successfully

        LIMS-3587
        :return:
        """
        selected_articles_data, _ = self.article_page.select_random_multiple_table_rows(
        )
        self.article_page.archive_selected_articles()
        self.article_page.get_archived_articles()
        for article in selected_articles_data:
            article_name = article['Article Name']
            self.base_selenium.LOGGER.info(
                ' + {} article should be activated.'.format(article_name))
            self.assertTrue(
                self.article_page.is_article_archived(value=article_name))

    def test012_restore_articles(self):
        """
        New: Article: Restore Approach: I can archive/restore any article successfully

        LIMS-3587
        :return:
        """
        article_names = []
        self.article_page.get_archived_articles()
        selected_articles_data, _ = self.article_page.select_random_multiple_table_rows(
        )
        for article in selected_articles_data:
            article_names.append(article['Article Name'])

        self.article_page.restore_selected_articles()
        self.article_page.get_active_articles()
        for article_name in article_names:
            self.assertTrue(
                self.article_page.is_article_archived(value=article_name))

    def test013_create_new_material_type(self):
        """
        Article: Materiel type Approach: make sure you can create new materiel type & this materiel type displayed correct according to this article.

        LIMS-3582
        :return:
        """
        material_type = self.generate_random_string()
        self.article_page.create_new_article(material_type=material_type)
        self.test_plan.get_test_plans_page()
        self.test_plan.click_create_test_plan_button()
        self.test_plan.set_material_type(
            material_type=self.article_page.article_material_type)
        self.article_page.sleep_tiny()
        self.assertTrue(
            self.test_plan.is_article_existing(
                article=self.article_page.article_name))

    def test014_article_search(self):
        """
        New: Articles: Search Approach: I can search by any field in the table view

        LIMS-3594
        :return:
        """
        row = self.article_page.get_random_article_row()
        row_data = self.base_selenium.get_row_cells_dict_related_to_header(
            row=row)
        for column in row_data:
            if re.findall(r'\d{1,}.\d{1,}.\d{4}',
                          row_data[column]) or row_data[column] == '':
                continue
            self.base_selenium.LOGGER.info(' + search for {} : {}'.format(
                column, row_data[column]))
            search_results = self.article_page.search(row_data[column])
            self.assertGreater(
                len(search_results), 1,
                " * There is no search results for it, Report a bug.")
            for search_result in search_results:
                search_data = self.base_selenium.get_row_cells_dict_related_to_header(
                    search_result)
                if search_data[column] == row_data[column]:
                    break
            self.assertEqual(row_data[column], search_data[column])

    def test015_green_border(self):
        """
        New: All modules: Creation Approach: Green border displayed when I create new record

        LIMS-3597
        :return:
        """
        self.article_page.create_new_article(sleep=False,
                                             material_type='Raw Material')
        self.assertEqual(
            self.base_selenium.get_text(element='articles:alert_confirmation'),
            'Successfully created')

    def test016_create_full_options_article(self):
        """
        New: Articles: Creation Approach: I can create new article successfully

        LIMS-3575
        :return:
        """
        self.article_page.create_new_article(full_options=True,
                                             material_type='Raw Material')
        article_text = self.article_page.search(
            value=self.article_page.article_name)[0].text
        self.assertIn(self.article_page.article_unit, article_text)
        self.assertIn(self.article_page.article_comment, article_text)
        self.assertIn(self.article_page.article_material_type, article_text)

    def test017_delete_article_with_test_plan(self):
        """
        New: Articles: Delete Approach; I can't delete any article if this article related to some data

        LIMS-3577
        :return:
        """
        self.article_page.create_new_article(material_type='Raw Material')
        self.test_plan.get_test_plans_page()
        self.test_plan.create_new_test_plan(
            material_type=self.article_page.article_material_type,
            article=self.article_page.article_name)
        self.article_page.get_article_page()
        self.article_page.sleep_small()
        article = self.article_page.search(
            value=self.test_plan.test_plan_name)[0]

        self.article_page.click_check_box(source=article)
        self.article_page.archive_selected_articles()

        self.article_page.get_archived_articles()
        archived_article = self.article_page.search(
            value=self.test_plan.test_plan_name)[0]
        self.article_page.click_check_box(source=archived_article)
        self.assertFalse(self.article_page.delete_selected_article())

    def test018_delete_article_with_order(self):
        """
        New: Articles: Delete Approach; I can't delete any article if this article related to some data

        LIMS-3577
        :return:
        """
        self.base_selenium.LOGGER.info(
            ' + Create new article with Raw Material.')
        self.article_page.create_new_article(material_type='Raw Material')
        self.test_plan.get_test_plans_page()
        self.base_selenium.LOGGER.info(
            ' + Create new test plan with {} article.'.format(
                self.article_page.article_name))
        self.test_plan.create_new_test_plan(
            material_type=self.article_page.article_material_type,
            article=self.article_page.article_name,
            test_unit='Qualitative')
        self.order.get_orders_page()
        self.order.click_create_order_button()
        self.base_selenium.LOGGER.info(
            ' + Create new order with {} article.'.format(
                self.article_page.article_name))
        self.order.create_new_order(
            article=self.article_page.article_name,
            material_type=self.article_page.article_material_type,
            test_plan=self.test_plan.test_plan_name)

        self.article_page.get_article_page()
        self.article_page.sleep_small()
        self.base_selenium.LOGGER.info(
            ' + Search for active article with {} test plan.'.format(
                self.test_plan.test_plan_name))
        search_results = self.article_page.search(
            value=self.test_plan.test_plan_name)
        self.assertGreater(
            len(search_results), 1,
            " * There is no search results for it, Report a bug.")
        for search_result in search_results:
            search_data = self.base_selenium.get_row_cells_dict_related_to_header(
                search_result)
            if self.test_plan.test_plan_name in search_data['Test Plans']:
                break
            self.base_selenium.LOGGER.debug(' Article test plan : {} '.format(
                search_data['Test Plans']))
        else:
            raise ValueError(
                " There is no active article with {} test plan".format(
                    self.test_plan.test_plan_name))
        self.base_selenium.LOGGER.info(' + Archive this article.')
        self.article_page.click_check_box(source=search_result)
        self.article_page.archive_selected_articles()

        self.article_page.get_archived_articles()
        self.base_selenium.LOGGER.info(
            ' + Search for archived article with {} test plan.'.format(
                self.test_plan.test_plan_name))
        search_results = self.article_page.search(
            value=self.test_plan.test_plan_name)
        self.assertGreater(
            len(search_results), 1,
            " * There is no search results for it, Report a bug.")
        for search_result in search_results:
            search_data = self.base_selenium.get_row_cells_dict_related_to_header(
                search_result)
            if self.test_plan.test_plan_name in search_data['Test Plans']:
                break
            self.base_selenium.LOGGER.debug(' Article test plan : {} '.format(
                search_data['Test Plans']))
        else:
            raise ValueError(
                " There is no archived article with {} test plan".format(
                    self.test_plan.test_plan_name))

        self.base_selenium.LOGGER.info(' + Delete this article, should fail.')
        self.article_page.click_check_box(source=search_result)
        self.assertFalse(self.article_page.delete_selected_article())

    def test019_download_article_sheet(self):
        """
        New: Articles: XSLX File: I can download all the data in the table view in the excel sheet

        LIMS:3589
        :return:
        """
        self.base_selenium.LOGGER.info(' * Download XSLX sheet')
        self.article_page.download_xslx_sheet()
        rows_data = self.article_page.get_articles_rows_data()
        for index in range(len(rows_data)):
            self.base_selenium.LOGGER.info(
                ' * Comparing the article no. {} '.format(index))
            fixed_row_data = self.fix_data_format(rows_data[index].split('\n'))
            values = self.article_page.article_sheet.iloc[index].values
            fixed_sheet_row_data = self.fix_data_format(values)
            for item in fixed_row_data:
                self.assertIn(item, fixed_sheet_row_data)
class HeaderTestCases(BaseTest):
    def setUp(self):
        super().setUp()
        self.header_page = Header()
        self.users_api = UsersAPI()
        self.roles_api = RolesAPI()
        self.set_authorization(auth=self.users_api.AUTHORIZATION_RESPONSE)
        self.header_page.get_roles_page()

    def test001_archive_roles_and_permissions(self):
        """
        Roles & Permissions: Make sure that you can archive any role record
        
        LIMS-6400
        """
        self.info('create multiple roles')
        roles_name = []
        for _ in range(3):
            re, payload = self.roles_api.create_role(self.roles_api.generate_random_string())
            roles_name.append(payload['name'])
        self.base_selenium.refresh()
        self.info("select rows to archive")
        self.base_selenium.select_multiple_table_rows_by_header_values(header='Name', list_of_value=roles_name)

        self.info("archive selected rows")
        self.header_page.archive_entity(menu_element='roles_and_permissions:right_menu',
                                        archive_element='roles_and_permissions:archive')
        self.info("navigate to archived roles table")
        self.header_page.get_archived_entities(menu_element='roles_and_permissions:right_menu',
                                               archived_element='roles_and_permissions:archived')
        for role_name in roles_name:
            self.info('{} role should be activated.'.format(role_name))
            self.assertTrue(self.header_page.is_role_in_table(value=role_name))

    def test002_restore_roles_and_permissions(self):
        """
        Roles & Permissions: Make sure that you can restore any role record
        
        LIMS-6104
        """
        role_names = []
        self.info("navigate to archived roles table")
        self.header_page.get_archived_entities(menu_element='roles_and_permissions:right_menu',
                                               archived_element='roles_and_permissions:archived')
        self.info("select random rows to restore")
        selected_role_data, _ = self.header_page.select_multiple_random_users_rows()
        if selected_role_data:
            for role in selected_role_data:
                role_names.append(role['Name'])
            self.info("restore selected roles")
            self.header_page.restore_entity(menu_element='roles_and_permissions:right_menu',
                                            restore_element='roles_and_permissions:restore')
            self.info("navigate to active roles table")
            self.header_page.get_active_entities(menu_element='roles_and_permissions:right_menu',
                                                 active_element='roles_and_permissions:active')
            for role_name in role_names:
                self.assertTrue(self.header_page.is_role_in_table(value=role_name))

    def test003_search_roles_and_permissions(self):
        """
        Header: Roles & Permissions: Search Approach: Make sure that you can search
        by any field in the active table successfully

        LIMS-6083
        """
        row = self.header_page.get_random_role_row()
        row_data = self.base_selenium.get_row_cells_dict_related_to_header(row=row)
        for column in row_data:
            if re.findall(r'\d{1,}.\d{1,}.\d{4}', row_data[column]) or row_data[column] == '':
                continue
            self.info('search for {} : {}'.format(column, row_data[column]))
            search_results = self.header_page.search(row_data[column])
            self.assertGreater(len(search_results), 1, " * There is no search results for it, Report a bug.")
            for search_result in search_results:
                search_data = self.base_selenium.get_row_cells_dict_related_to_header(search_result)
                if search_data[column] == row_data[column]:
                    break
            self.assertEqual(row_data[column], search_data[column])

    def test004_overview_btn_from_create_mode(self):
        """
        Roles & Permissions: Overview button Approach: Make sure after you press on the overview button,
        it will redirect me to the active table

        LIMS-6404- create approach
        """
        # from the create mode it will redirect me to the active table
        self.info('Press on create new role button')
        self.base_selenium.click(element='roles_and_permissions:new_role_btn')
        self.info('Press on the overview  button')
        self.base_selenium.click(element='roles_and_permissions:roles_overview_btn')
        self.header_page.confirm_popup()
        self.info('it will redirect me to the active table')
        self.header_page.get_roles_page()
        self.assertEqual(self.base_selenium.get_url(), '{}roles'.format(self.base_selenium.url))

    def test005_overview_btn_from_edit_mode(self):
        """
        Roles & Permissions: Overview button Approach: Make sure after you press on the overview button,
        it will redirect me to the active table

        LIMS-6404- edit approach
        """
        self.info("get random role edit page")
        response, payload = self.roles_api.get_all_roles()
        self.assertEqual(response['status'], 1, response)
        random_role_id = random.choice(response['roles'])['id']
        self.header_page.get_role_edit_page_by_id(random_role_id)
        self.info('Press on the overview  button')
        self.base_selenium.click(element='roles_and_permissions:roles_overview_btn')
        self.info('it will redirect me to the active table')
        self.header_page.get_roles_page()
        self.assertEqual(self.base_selenium.get_url(), '{}roles'.format(self.base_selenium.url))

    @parameterized.expand(['save_btn', 'cancel'])
    def test006_update_role_name_with_save_cancel_btn(self, save):
        """
        Roles & Permissions: Make sure that you can update role name with save & cancel button

        LIMS-6108
        """
        self.info('create role to be archived')
        random_name = self.roles_api.generate_random_string()
        re, pay = self.roles_api.create_role(random_name)
        role_id = self.roles_api.get_role_id_from_name(pay['name'])

        self.header_page.get_role_edit_page_by_id(role_id)
        new_name = self.generate_random_string()
        self.header_page.set_role_name(role_name=new_name)
        if 'save_btn' == save:
            self.header_page.save(save_btn='roles_and_permissions:save_btn')
        else:
            self.header_page.cancel(force=True)

        self.header_page.get_roles_page()
        found_role = self.header_page.filter_role_by_no(role_id)['Name']
        if 'save_btn' == save:
            self.assertEqual(found_role, new_name)
        else:
            self.assertEqual(found_role, random_name)

    def test007_delete_role_not_used_in_other_entity(self):
        """
        Roles & Permissions: Make sure that you can delete any role record,
        If this record not used in other entity

        LIMS-6401
        """
        role_name = self.generate_random_string()
        response, payload = self.roles_api.create_role(role_name=role_name)
        self.assertEqual(response['status'], 1)
        row = self.header_page.search(role_name)
        self.header_page.sleep_tiny()
        self.header_page.click_check_box(row[0])
        self.header_page.archive_selected_items()
        self.header_page.get_archived_entities(menu_element='roles_and_permissions:right_menu',
                                               archived_element='roles_and_permissions:archived')
        self.info('make sure that that the user record navigate to the archive table')
        archived_row = self.header_page.search(role_name)
        self.header_page.click_check_box(archived_row[0])
        self.info('Press on the right menu')
        self.base_selenium.click(element='roles_and_permissions:right_menu')
        self.info('Press on the delete button')
        self.base_selenium.click(element='roles_and_permissions:delete')
        self.header_page.confirm_popup()
        result = self.header_page.search(value=role_name)
        self.info('deleted successfully')
        self.assertTrue(result, 'No records found')

    def test008_validation_role_name_field(self):
        """
        Roles & Permissions: Make sure from the validation of all fields

        LIMS-6122
        """
        self.info("get random role edit page")
        random_role = random.choice(self.roles_api.get_random_role())
        self.header_page.get_role_edit_page_by_id(random_role['id'])
        self.header_page.clear_role_name()
        self.header_page.sleep_medium()
        self.header_page.save(save_btn='roles_and_permissions:save_btn')
        self.header_page.sleep_small()
        self.info('Waiting for error message')
        validation_result = self.base_selenium.wait_element(element='general:oh_snap_msg')
        self.info('Assert error msg')
        self.assertEqual(validation_result, True)

    @skip('https://modeso.atlassian.net/browse/LIMSA-220')
    def test009_download_role_sheet(self):
        """
        Roles & Permissions: Make sure you can export all the data in the active table
        & it should display in the same order

        LIMS-6107
        """
        self.info('download XSLX sheet')
        self.header_page.download_xslx_sheet()
        rows_data = list(filter(None, self.header_page.get_table_rows_data()))
        for index in range(len(rows_data)-1):
            self.info('comparing the role no. {} '.format(index))
            fixed_row_data = self.fix_data_format(rows_data[index].split('\n'))
            values = self.header_page.sheet.iloc[index].values
            fixed_sheet_row_data = self.fix_data_format(values)
            for item in fixed_row_data:
                self.assertIn(str(item).lower, fixed_sheet_row_data)

    @parameterized.expand(['10', '20', '25', '50', '100'])
    @attr(series=True)
    def test010_testing_table_pagination(self, pagination_limit):
        """
        Header: Active table: Pagination Approach; Make sure that I can set the pagination
        to display 10/20/25/50/100 records in each page

        LIMS-6103 
        """
        self.header_page.set_page_limit(limit=pagination_limit)
        table_info = self.header_page.get_table_info_data()

        self.info('get current table records count')
        table_records_count = str(len(self.header_page.result_table()) - 1)

        self.info('table records count is {}, and it should be {}'.
                  format(table_records_count, table_info['page_limit']))
        self.assertEqual(table_records_count, table_info['page_limit'])

        self.info('current page limit is {}, and it should be {}'.
                  format(table_info['pagination_limit'], pagination_limit))
        self.assertEqual(table_info['pagination_limit'], pagination_limit)

        if int(table_info['pagination_limit']) <= int(table_info['count']):
            self.assertEqual(table_info['pagination_limit'], table_records_count)

    @skip("There is no edit option in the user table [atlassian]")
    def test011_delete_role_used_in_other_entity(self):
        """
        Roles & Permissions: Make sure that you can't delete any role record If this record used in other entity

        LIMS-6437
        """
        self.info('create new role with random data')
        role_random_name = self.generate_random_string()
        response, payload = self.roles_api.create_role(role_name=role_random_name)
        self.assertEqual(response['status'], 1, response)
        self.info("Navigate to users page")
        self.header_page.get_users_page()
        self.info("get random user edit page and set role to {}".format(role_random_name))
        self.header_page.get_random_user()
        self.header_page.sleep_tiny()
        self.header_page.set_user_role(user_role=role_random_name)
        self.header_page.save(save_btn='roles_and_permissions:save_btn')
        self.info("navigate to the role page to delete it")
        self.header_page.get_roles_page()
        row = self.header_page.search(role_random_name)
        self.header_page.sleep_tiny()
        self.header_page.click_check_box(row[0])
        self.header_page.archive_selected_items()
        self.header_page.get_archived_entities(menu_element='roles_and_permissions:right_menu',
                                               archived_element='roles_and_permissions:archived')
        self.info('make sure that that the user record navigate to the archive table')
        archived_row = self.header_page.search(role_random_name)
        self.header_page.click_check_box(archived_row[0])
        self.info('Press on the right menu')
        self.base_selenium.click(element='roles_and_permissions:right_menu')
        self.info('Press on the delete button')
        self.base_selenium.click(element='roles_and_permissions:delete')
        self.header_page.confirm_popup()
        self.info('message will appear this user related to some data & cant delete it')
        self.header_page.confirm_popup()
        self.info('search to make sure this user found in the active table '.format(role_random_name))
        result = self.header_page.search(value=role_random_name)
        self.assertIn(role_random_name, result[0].text)

    @skip("There is no edit option in the user table [atlassian]")
    def test012_archived_role_not_displayed_in_the_user_role_drop_down(self):
        """
        Roles& Permissions: Archived roles shouldn't display in the user role drop down

        LIMS-6438
        """
        self.info('create role to be archived')
        random_name = self.roles_api.generate_random_string()
        re, pay = self.roles_api.create_role(random_name)
        role_id = self.roles_api.get_role_id_from_name(pay['name'])

        response, payload = self.roles_api.archive_roles([str(role_id)])
        self.assertEqual(response['status'], 1, response)

        self.info("archived role id {}".format(role_id))
        self.header_page.get_users_page()
        self.header_page.get_random_user()
        result = self.header_page.set_user_role(user_role=random_name)
        self.assertTrue(result)

    def test013_cant_create_two_roles_with_the_same_name(self):
        """
        Roles & Permissions: you can't create two roles with the same name

        LIMS-6439
        """
        self.info('create new role with random data')
        role_random_name = self.generate_random_string()
        response, payload = self.roles_api.create_role(role_name=role_random_name)
        self.assertEqual(response['status'], 1, response)
        self.info('create role with the same name')
        created_role = self.header_page.create_new_role(role_name=role_random_name)
        self.info('red border will display that the name already exit'.format(role_random_name))
        self.info('Waiting for error message')
        validation_result = self.base_selenium.wait_element(element='general:oh_snap_msg')
        self.info('Assert error msg')
        self.assertEqual(validation_result, True)
        self.assertEqual(created_role['role_name'], None)

    @attr(series=True)
    def test014_create_role_with_master_data_permissions_then_create_user_by_it(self):
        """
        Roles & Permissions: when I create user with master data permissions then create user wit it
        when I login with this user the master data only should appear in the menu

        LIMS-6440
        """
        self.login_page = Login()
        self.info('create role with random name with master data permissions')
        random_role_name = self.generate_random_string()
        self.header_page.create_role_with_mater_data_permissions(role_name=random_role_name)

        self.info('go to the user section to create user with this role')
        self.header_page.get_users_page()
        random_user_name = self.generate_random_string()
        random_user_email = self.header_page.generate_random_email()
        random_user_password = self.generate_random_string()
        self.header_page.create_new_user(user_name=random_user_name,
                                         user_email=random_user_email,
                                         user_role=random_role_name,
                                         user_password=random_user_password,
                                         user_confirm_password=random_user_password)

        self.login_page.logout()

        self.info('login with role & user {}:{}'.format(random_user_name, random_user_password))
        self.login_page.login(username=random_user_name, password=random_user_password)
        self.header_page.sleep_medium()
        # make sure that all the master data pages appear(articles & test units & test plans & contacts)
        self.info('get the test unit url')
        self.assertTrue('Test Units', TstUnit().get_test_units_page())
        self.info('get the articles url')
        self.assertTrue('Articles', Article().get_articles_page())
        self.info('get the test plan url')
        self.assertTrue('Test Plans', TstPlan().get_test_plans_page())
        self.info('get the contacts url')
        self.assertTrue('Contacts', Contacts().get_contacts_page())

    @attr(series=True)
    def test015_create_role_with_sample_management_permissions_then_create_user_by_it(self):
        """
        Roles & Permissions: when I create user with sample management permissions then create
        user wit it when I login with this user the master data only should appear in the menu

        LIMS-6441
        """
        self.login_page = Login()
        self.info("create role with random name with sample management permissions")
        random_role_name = self.generate_random_string()
        self.header_page.create_role_with_sample_management_permissions(role_name=random_role_name)

        self.info('go to the user section to create user with this role')
        self.header_page.get_users_page()
        random_user_name = self.generate_random_string()
        random_user_email = self.header_page.generate_random_email()
        random_user_password = self.generate_random_string()
        self.header_page.create_new_user(user_name=random_user_name,
                                         user_email=random_user_email,
                                         user_role=random_role_name,
                                         user_password=random_user_password,
                                         user_confirm_password=random_user_password)

        self.login_page.logout()

        self.info('login with role & user {}:{}'.format(random_user_name, random_user_password))
        self.login_page.login(username=random_user_name, password=random_user_password)
        self.header_page.sleep_medium()
        self.info('get the order url')
        self.assertTrue('Sample Management', Order().get_orders_page())
        self.info('get the analysis url')
        Orders().navigate_to_analysis_active_table()
        self.assertIn('sample/analysis', self.base_selenium.get_url())

    def test016_filter_by_role_name(self):
        """
        Roles & Permissions: Make sure that the user can filter by role name

        LIMS-6120
        """
        self.info("get random role name")
        random_role = random.choice(self.roles_api.get_random_role())
        roles_results = self.header_page.filter_user_by(
            filter_element='roles_and_permissions:role_name',
            filter_text=random_role['name'])
        for roles_result in roles_results:
            self.assertEqual(random_role['name'], roles_result['Name'])

    def test017_filter_by_no(self):
        """
        Header: Roles & Permissions Approach: Make sure that you can filter by role number

        LIMS-6003
        """
        self.info("get random role name")
        random_role = random.choice(self.roles_api.get_random_role())
        roles_result = self.header_page.filter_role_by_no(random_role['id'])
        self.assertEqual(str(random_role['id']), roles_result['No'])

    @skip('There is no created on in permission table')
    def test018_filter_created_on(self):
        """
        Header: Roles & Permissions Approach: Make sure that you can filter by role created on

        LIMS-6508
        """
        self.header_page.set_all_configure_table_columns_to_specific_value()
        role_data = self.header_page.get_role_data_from_fully_checked_headers_random_row()
        roles_results = self.header_page.filter_user_by(
            filter_element='roles_and_permissions:filter_created_on',
            filter_text=role_data['created_on'])
        for roles_result in roles_results:
            self.assertEqual(role_data['created_on'], roles_result['Created On'])

    @attr(series=True)
    def test019_filter_by_changed_by(self):
        """
        Header: Roles & Permissions Approach: Make sure that you can filter by role changed by

        LIMS-6507
        """
        self.login_page = Login()
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, response)
        self.login_page.logout()
        self.header_page.sleep_tiny()
        self.info('login with role & user {}:{}'.format(payload['username'], payload['password']))
        self.login_page.login(username=payload['username'], password=payload['password'])
        self.header_page.wait_until_page_is_loaded()
        self.header_page.sleep_medium()
        self.header_page.get_roles_page()
        self.header_page.sleep_small()
        random_role_name = self.generate_random_string()
        self.header_page.create_new_role(role_name=random_role_name)
        self.header_page.click_on_table_configuration_button()
        self.base_selenium.click(element='roles_and_permissions:checked_role_changed_by')
        self.base_selenium.click(element='roles_and_permissions:apply_btn')
        self.header_page.sleep_tiny()
        roles_results = self.header_page.filter_user_by(
            filter_element='roles_and_permissions:filter_changed_by',
            filter_text=payload['username'], field_type='drop_down')
        for roles_result in roles_results:
            self.assertIn(payload['username'], roles_result['Changed By'])
예제 #13
0
 def setUp(self):
     super().setUp()
     self.login_page = Login()
class TestPlansTestCases(BaseTest):
    def setUp(self):
        super().setUp()
        self.test_plan = TstPlan()
        self.test_plan_api = TestPlanAPI()
        self.article_api = ArticleAPI()
        self.test_plan.get_test_plans_page()
        self.test_plan_api.set_configuration()

    def test001_test_plan_delete_testunit(self):
        """
        Testing deleting a test unit from test-plan create or update step two
        It deletes the first test unit in the chosen test plan and saves this,
        then refreshes the page and checks if the deletion was done correctly.

        LIMS-3504
        """
        self.info("get random completed test plan")
        random_completed_test_plan = random.choice(
            self.test_plan_api.get_completed_testplans())
        self.info("navigate to the test-plan No. {} edit page".format(
            random_completed_test_plan['number']))
        self.test_plan.get_test_plan_edit_page_by_id(
            random_completed_test_plan['id'])
        old_testunits = self.test_plan.get_all_testunits_in_testplan()
        self.assertTrue(old_testunits,
                        "There's no test units in this test plan")
        deleted_test_unit = (old_testunits[0])[0]
        self.info("delete the first test unit with name {}".format(
            deleted_test_unit))
        self.test_plan.delete_the_first_testunit_from_the_tableview()
        self.info(
            "save the changes and refresh to make sure test unit deleted")
        self.test_plan.save_and_confirm_popup()
        all_testunits = self.test_plan.get_all_testunits_in_testplan()
        self.info('Checking if the changes were saved successfully')
        deleted_test_unit_found = self.test_plan.check_if_deleted_testunit_is_available(
            all_testunits=all_testunits, deleted_test_unit=deleted_test_unit)
        self.assertFalse(deleted_test_unit_found)

    @parameterized.expand(['InProgress', 'Completed'])
    def test002_test_plan_edit_status(self, status):
        """
        Creation Approach: when the status converted from completed to completed, new version created
        when the status converted from In-Progress to completed, no new version created

        LIMS-3502
        LIMS-3501
        """
        self.info(
            "create test unit of  material type  = All  to complete test plan")
        response, test_unit = TestUnitAPI().create_qualitative_testunit()
        self.assertEqual(response['status'], 1, 'can not create test unit')
        testplan = random.choice(
            self.test_plan_api.get_testplans_with_status(status=status))
        self.assertTrue(testplan, 'No test plan selected')
        self.info(
            'Navigate to edit page of test plan: {} with version: {}'.format(
                testplan['testPlanName'], testplan['version']))
        self.test_plan.get_test_plan_edit_page_by_id(testplan['id'])
        self.info('Going to step 2 to add test unit to this test plan')
        self.test_plan.sleep_tiny()
        self.test_plan.set_test_unit(test_unit=test_unit['name'])
        if status == 'InProgress':
            self.info('Saving and completing the test plan')
            self.test_plan.save(save_btn='test_plan:save_and_complete',
                                sleep=True)
        else:
            self.info('Saving and confirm pop up')
            self.test_plan.save_and_confirm_popup()

        self.info(
            "go back to the active table and get test plan to check its version and status"
        )
        self.test_plan.get_test_plans_page()
        new_test_plan_version, test_plan_row_data_status = \
            self.test_plan.get_testplan_version_and_status(search_text=testplan['testPlanName'])

        if status == 'InProgress':
            self.assertEqual(int(new_test_plan_version), testplan['version'])
        else:
            self.assertGreater(int(new_test_plan_version),
                               int(testplan['version']))

        self.assertEqual(test_plan_row_data_status, 'Completed')

    def test003_archive_test_plan_one_record(self):
        """
        Archive one record

        LIMS-3506 Case 1
        """
        self.info('choosing a random test plan table row')
        selected_test_plan = self.test_plan.select_random_table_row()
        self.assertTrue(selected_test_plan)
        self.info(f'selected_test_plan : {selected_test_plan}')
        testplan_number = selected_test_plan['Test Plan No.']
        self.info(
            'Archive the selected item and navigating to the archived items table'
        )
        self.test_plan.archive_selected_items()
        self.test_plan.get_archived_items()
        archived_row = self.test_plan.search(testplan_number)
        self.info(
            'Checking if test plan number: {} is archived correctly'.format(
                testplan_number))
        self.assertIn(selected_test_plan['Test Plan Name'],
                      archived_row[0].text)
        self.info('Test plan number: {} is archived correctly'.format(
            testplan_number))

    def test004_restore_test_plan_one_record(self):
        """
         Restore one record

         LIMS-3506 Case 1
        """
        self.info("Navigate to archived test plan table")
        self.test_plan.get_archived_items()
        self.info('Choosing a random testplan table row')
        self.test_plan.sleep_tiny()
        selected_test_plan = self.test_plan.select_random_table_row()
        self.info(f"selected_test_plan : {selected_test_plan}")
        self.assertTrue(selected_test_plan)
        testplan_number = selected_test_plan['Test Plan No.']
        self.info('select Testplan number: {} to be restored'.format(
            testplan_number))
        self.info(
            'Restoring the selected item then navigating to the active items table'
        )
        self.test_plan.restore_selected_items()
        self.test_plan.get_active_items()
        self.test_plan.filter_by_testplan_number(filter_text=testplan_number)
        restored_row = self.test_plan.result_table()
        self.info(
            'Checking if testplan number: {} is restored correctly'.format(
                testplan_number))
        self.assertIn(selected_test_plan['Test Plan Name'],
                      restored_row[0].text)
        self.info('Testplan number: {} is restored correctly'.format(
            testplan_number))

    def test005_archive_test_plan_multiple_records(self):
        """
        Archive multiple records

        LIMS-3506 Case 2
        """
        self.info('Choosing random multiple test plans table rows')
        self.test_plan.sleep_small()
        rows_data, rows = self.test_plan.select_random_multiple_table_rows()
        self.assertTrue(rows_data)
        testplans_numbers = [row['Test Plan No.'] for row in rows_data]
        self.info(
            'Testplan numbers: {} will be archived'.format(testplans_numbers))
        self.info(
            'Archiving the selected items and navigating to the archived items table'
        )
        self.test_plan.archive_selected_items()
        self.test_plan.sleep_small()
        self.info('Checking if testplans are archived correctly')
        self.test_plan.get_archived_items()
        archived_rows = self.test_plan.filter_multiple_rows_by_testplans_numbers(
            testplans_numbers)
        self.assertIsNotNone(archived_rows)
        self.assertEqual(len(archived_rows), len(testplans_numbers))
        self.info('Testplan numbers: {} are archived correctly'.format(
            testplans_numbers))

    def test006_restore_test_plan_multiple_records(self):
        """
        Rstore multiple records

        LIMS-3506 Case 2
        """
        self.info("Navigate to archived test plan table")
        self.test_plan.sleep_tiny()
        self.test_plan.get_archived_items()
        self.info('Choosing random multiple test plans table rows')
        self.test_plan.sleep_tiny()
        rows_data, rows = self.test_plan.select_random_multiple_table_rows()
        self.assertTrue(rows_data)
        testplans_numbers = [row['Test Plan No.'] for row in rows_data]
        self.info(
            'Restore Test plans with numbers: {}'.format(testplans_numbers))
        self.test_plan.restore_selected_items()
        self.test_plan.sleep_small()
        self.info('Navigate to active table and make sure test plans restored')
        self.test_plan.get_active_items()
        restored_rows = self.test_plan.filter_multiple_rows_by_testplans_numbers(
            testplans_numbers)
        self.assertIsNotNone(restored_rows)
        self.assertEqual(len(restored_rows), len(testplans_numbers))
        self.info('Test plans numbers: {} are restored correctly'.format(
            testplans_numbers))

    @skip('https://modeso.atlassian.net/browse/LIMS-6403')
    def test007_exporting_test_plan_one_record(self):
        """
        Exporting one record

        LIMS-3508 Case 1
        """
        self.info('choosing a random testplan table row')
        row = self.test_plan.get_random_table_row('general:table')
        row_data = self.base_selenium.get_row_cells_dict_related_to_header(
            row=row)
        testplan_number = row_data['Test Plan No.']
        self.info(
            'testplan number: {} will be exported'.format(testplan_number))
        self.info('Selecting the test plan row')
        self.test_plan.click_check_box(source=row)
        self.info('download XSLX sheet of selected test plan')
        self.test_plan.download_xslx_sheet()
        row_data_list = list(row_data.values())
        self.info('comparing the testplan no. {} '.format(testplan_number))
        values = self.test_plan.sheet.iloc[0].values
        fixed_sheet_row_data = self.fix_data_format(values)
        fixed_row_data_list = self.fix_data_format(row_data_list)
        for item in fixed_row_data_list:
            self.assertIn(item, fixed_sheet_row_data)

    @skip('https://modeso.atlassian.net/browse/LIMS-6403')
    def test008_exporting_test_plan_multiple_records(self):
        """
        Exporting multiple records

        LIMS-3508 Case 2
        """
        self.info('choosing random multiple testplans table rows')
        row_data_list = self.test_plan.select_random_multiple_table_rows(
            element='general:table')[0]
        self.test_plan.download_xslx_sheet()

        row_data = []
        sheet_data = []
        for index in range(len(row_data_list)):
            row_data.append(self.fix_data_format(
                row_data_list[index].values()))
            sheet_data.append(
                self.fix_data_format(self.test_plan.sheet.iloc[index].values))

        row_data = sorted(row_data)
        sheet_data = sorted(sheet_data)
        for index in range(len(row_data)):
            for item in row_data[index]:
                self.assertIn(item, sheet_data[index])

    def test009_test_plan_duplicate(self):
        """
        Duplicate a test plan

        LIMS-3679
        """
        self.info('Choosing a random testplan table row')
        testPlan = random.choice(self.test_plan_api.get_completed_testplans())
        self.assertTrue(testPlan, "No completed test plan selected")
        testunits = self.test_plan_api.get_testunits_in_testplan(
            id=testPlan['id'])
        self.assertTrue(
            testunits,
            "Completed test plan with id {} has no testunits!!".format(
                testPlan['id']))
        self.info("select test plan {}".format(testPlan['testPlanName']))
        self.test_plan.filter_by_testplan_number(testPlan['number'])
        row = self.test_plan.result_table()[0]
        self.test_plan.click_check_box(source=row)
        self.info('Duplicating testplan number: {}'.format(testPlan['number']))
        self.test_plan.duplicate_selected_item()
        duplicated_test_plan_number = self.test_plan.duplicate_testplan(
            change=['name'])
        self.info('testplan duplicated with number: {}'.format(
            duplicated_test_plan_number))
        self.info('get duplicated test plan data and child table data')
        duplicated_testplan_data, duplicated_testplan_childtable_data = \
            self.test_plan.get_specific_testplan_data_and_childtable_data(
                filter_by='number', filter_text=duplicated_test_plan_number)
        duplicated_test_units = []
        for testunit in duplicated_testplan_childtable_data:
            duplicated_test_units.append(testunit['Test Unit Name'])

        self.info('Asserting that the data is duplicated correctly')
        self.assertEqual(testPlan['materialTypes'][0],
                         duplicated_testplan_data['Material Type'])
        self.assertEqual(testPlan['article'][0],
                         duplicated_testplan_data['Article Name'])
        self.assertEqual(testPlan['articleNo'][0],
                         duplicated_testplan_data['Article No.'])
        for testunit in testunits:
            self.assertIn(testunit['name'], duplicated_test_units)

    def test010_test_plan_completed_to_inprogress(self):
        """
        When the test plan status is converted from completed to in progress a new version is created

        LIMS-3503
        """
        self.info('get random completed test plan')
        completed_testplan = random.choice(
            self.test_plan_api.get_completed_testplans())
        self.assertTrue(completed_testplan, "There's no completed test plans!")
        self.info(
            'Navigating to edit page of testplan: {} with version: {}'.format(
                completed_testplan['testPlanName'],
                completed_testplan['version']))
        self.test_plan.get_test_plan_edit_page_by_id(completed_testplan['id'])
        self.info('Going to step 2 to remove all the test units from it')
        self.test_plan.navigate_to_testunits_selection_page()
        self.test_plan.sleep_tiny()
        self.test_plan.delete_all_testunits()
        self.test_plan.save_and_confirm_popup()

        self.info("go back to active table")
        self.test_plan.get_test_plans_page()

        self.info(
            'Getting the currently changed testplan to check its status and version'
        )
        inprogress_testplan_version, testplan_row_data_status = \
            self.test_plan.get_testplan_version_and_status(search_text=completed_testplan['testPlanName'])

        self.assertEqual(completed_testplan['version'] + 1,
                         int(inprogress_testplan_version))
        self.assertEqual(testplan_row_data_status, 'In Progress')

    @parameterized.expand(['same', 'All'])
    def test011_create_testplans_same_name_article_materialtype(self, same):
        """
        Testing the creation of two testplans with the same name, material type
        and article, this shouldn't happen

        LIMS-3499

        New: Test plan: Creation Approach: I can't create two test plans
        with the same name & same materiel type & one with any article
        and the other one all

        LIMS-3500
        """
        payload = self.test_plan_api.create_completed_testplan_random_data()
        self.test_plan.click_create_test_plan_button()
        self.test_plan.set_test_plan(name=payload['testPlan']['text'])
        self.assertFalse(
            self.test_plan.is_material_type_existing(
                material_type=payload['materialType'][0]['text']))

    def test012_create_testplans_same_name_different_materialtype(self):
        """
        Testing the creation of two testplans with the same name, but different material type
        and article. It should be created successfully.

        LIMS-3498
        """
        self.info('create complete test plan')
        payload = self.test_plan_api.create_completed_testplan_random_data()
        self.assertTrue(payload, 'can not create a tesplan')
        articles = self.article_api.get_all_articles_json()
        for article in articles:
            if article['name'] != payload['selectedArticles'][0]['text'] and article['materialType'] != \
                    payload['materialType'][0]['text']:
                self.info(
                    'create another testplan with the same name, but with different material type and article name'
                )
                second_testplan_name = self.test_plan.create_new_test_plan(
                    name=payload['testPlan']['text'],
                    material_type=article['materialType'],
                    article=article['name'])
                self.info(
                    'new testplan is created successfully with name: {}, article name: {} and material type: {}'
                    .format(second_testplan_name, self.test_plan.article,
                            self.test_plan.material_type))

                self.assertEqual(payload['testPlan']['text'],
                                 second_testplan_name)
                data = self.test_plan.search(second_testplan_name)
                self.assertGreaterEqual(len(data), 2)
                break

    def test013_delete_used_testplan(self):
        """
        If a test plan is used, it can't be deleted

        LIMS-3509
        """
        self.info("create order with test plan")
        response, payolad = OrdersAPI().create_new_order()
        self.assertEqual(response['status'], 1, payolad)
        self.info("created order no {} has testplan name {}".format(
            payolad[0]['orderNo'], payolad[0]['testPlans'][0]['name']))
        self.info('testplan name: {} will be archived'.format(
            payolad[0]['testPlans'][0]['name']))
        self.test_plan.base_selenium.refresh()
        testplan_deleted = self.test_plan.delete_selected_item_from_active_table_and_from_archived_table(
            item_name=payolad[0]['testPlans'][0]['name'])

        self.info(
            "check for the error popup that this testplan is used and can't be deleted"
        )
        self.assertFalse(testplan_deleted)

    def test014_archived_testplan_shouldnot_appear_in_order(self):
        """
        In case a testplan is archived, it shouldn't appear when creating a new order

        LIMS-3708
        """
        self.info("navigate to orders page")
        self.order_page = Order()
        self.info("get random archived testplan")
        response, payload = self.test_plan_api.get_all_test_plans()
        self.assertEqual(response['status'], 1, payload)
        archived_test_plan = random.choice(response['testPlans'])
        self.test_plan_api.archive_testplans(
            ids=[str(archived_test_plan['id'])])
        self.order_page.get_orders_page()

        self.info("archived test plan data {}".format(archived_test_plan))
        self.info(
            "create a new order with material type and article of archived testplan"
        )
        if archived_test_plan['article'] != ['all']:
            self.order_page.create_new_order(
                material_type=archived_test_plan['materialTypes'][0],
                article=archived_test_plan['article'][0],
                test_plans=[archived_test_plan['testPlanName']])
        else:
            self.order_page.create_new_order(
                material_type=archived_test_plan['materialTypes'][0],
                test_plans=[archived_test_plan['testPlanName']])
        order_data = self.order_page.get_suborder_data()
        self.info(
            "get the first suborder's testplan and make sure it's an empty string"
        )
        self.assertCountEqual(order_data['suborders'][0]['testplans'], [''])

    def test015_testunit_sub_super_scripts(self):
        """
        Create a testunit with sub/super scripts, use this testunit to create a testplan
        and check the sub/super scripts in the card view

        LIMS-5796
        """
        self.info("create test unit with sub and super scripts")
        response, payload = TestUnitAPI().create_qualitative_testunit(
            unit='mg[2]{o}')
        self.assertEqual(response['status'], 1, payload)
        self.info("created test unit data {}".format(payload))
        self.info("create test plan with same created test unit data")
        if payload['selectedMaterialTypes'][0]['text'] == 'All':
            self.test_plan.create_new_test_plan(test_unit=payload['name'],
                                                save=False)
        else:
            self.test_plan.create_new_test_plan(
                material_type=payload['selectedMaterialTypes'][0]['text'],
                test_unit=payload['name'],
                save=False)

        unit = self.base_selenium.find_element('test_plan:testunit_unit').text
        self.assertEqual(unit, 'mg2o')

    def test016_filter_by_testplan_number(self):
        """
        User can filter with testplan number

        LIMS-6473
        """
        self.info("select random test plan")
        random_testplan = random.choice(
            self.test_plan_api.get_all_test_plans_json())
        self.info("selected_test_plan No {}".format(random_testplan['number']))
        self.test_plan.filter_by_testplan_number(random_testplan['number'])
        testplan_found = self.test_plan.result_table()
        self.assertIn(str(random_testplan['number']),
                      (testplan_found[0].text).replace("'", ""))
        self.info('Filtering by number was done successfully')

    def test017_filter_by_testplan_name(self):
        """
        User can filter with testplan name

        LIMS-6470
        """
        random_testplan = random.choice(
            self.test_plan_api.get_all_test_plans_json())
        self.assertTrue(random_testplan, "can't select random test plan !")
        testplans_found_text = self.test_plan.filter_by_element_and_get_text(
            'Testplan Name', 'test_plans:testplan_name_filter',
            random_testplan['testPlanName'], 'drop_down')

        for tp_text in testplans_found_text:
            self.assertIn(str(random_testplan['testPlanName']),
                          tp_text.replace("'", ""))

    @parameterized.expand(['Completed', 'In Progress'])
    def test018_filter_by_testplan_status(self, status):
        """
        User can filter with status

        LIMS-6474
        """
        testplans_found_text = \
            self.test_plan.filter_by_element_and_get_text('Status', 'test_plans:testplan_status_filter',
                                                          status, 'drop_down')
        for tp_text in testplans_found_text:
            self.assertIn(status, tp_text)
            if status == "In Progress":
                self.assertNotIn('Completed', tp_text)
            else:
                self.assertNotIn('In Progress', tp_text)

    def test019_filter_by_testplan_changed_by(self):
        """
        User can filter with changed by field

        LIMS-6475
        """
        self.login_page = Login()
        self.info('Calling the users api to create a new user with username')
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, payload)
        self.test_plan.sleep_tiny()
        self.login_page.logout()
        self.test_plan.sleep_tiny()
        self.login_page.login(username=payload['username'],
                              password=payload['password'])
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.test_plan.get_test_plans_page()
        self.test_plan.sleep_tiny()
        testplan_name = self.test_plan.create_new_test_plan()

        self.info('New testplan is created successfully with name: {}'.format(
            testplan_name))
        self.test_plan.set_all_configure_table_columns_to_specific_value(
            value=True)

        testplan_found = self.test_plan.filter_by_element_and_get_results(
            'Changed By', 'test_plans:testplan_changed_by_filter',
            payload['username'], 'drop_down')
        self.assertEqual(len(testplan_found), 2)
        self.assertIn(payload['username'], testplan_found[0].text)
        self.assertIn(testplan_name, testplan_found[0].text)

    def test020_filter_by_testplan_material_type(self):
        """
        User can filter with material type field

        LIMS-6471
        """
        random_testplan = random.choice(
            self.test_plan_api.get_all_test_plans_json())
        testplans_found_text = self.test_plan.filter_by_element_and_get_text(
            'Material Type', 'test_plans:testplan_material_type_filter',
            random_testplan['materialTypes'][0], 'drop_down')

        for tp_text in testplans_found_text:
            self.assertIn(str(random_testplan['materialTypes'][0]), tp_text)

    def test021_filter_by_testplan_article(self):
        """
        User can filter with article field

        LIMS-6472
        """
        random_testplan = random.choice(
            self.test_plan_api.get_all_test_plans_json())
        if random_testplan['article'][0] == 'all':
            testplans_found_text = self.test_plan.filter_by_element_and_get_text(
                'Article', 'test_plans:testplan_article_filter', 'All',
                'drop_down')
        else:
            testplans_found_text = self.test_plan.filter_by_element_and_get_text(
                'Article', 'test_plans:testplan_article_filter',
                random_testplan['articleNo'][0], 'drop_down')

        for tp_text in testplans_found_text:
            self.assertIn(str(random_testplan['article'][0]), tp_text)

    def test022_filter_by_testplan_created_on(self):
        """
        User can filter with created on field

        LIMS-6476
        """
        random_testplan = random.choice(
            self.test_plan_api.get_all_test_plans_json())
        date = datetime.datetime.strptime(random_testplan['createdAt'],
                                          "%Y-%m-%dT%H:%M:%S.%fZ")
        date_formatted = datetime.datetime.strftime(date, '%d.%m.%Y')

        testplans_found_text = self.test_plan.filter_by_element_and_get_text(
            'Created On', 'test_plans:testplan_created_on_filter',
            date_formatted, 'date')

        for tp_text in testplans_found_text:
            self.assertIn(date_formatted, tp_text)

    @parameterized.expand(['ok', 'cancel'])
    def test023_create_approach_overview_button(self, ok):
        """
        Master data: Create: Overview button Approach: Make sure
        after I press on the overview button, it redirects me to the active table

        LIMS-6203
        """
        self.info("click on create test plan button")
        self.test_plan.click_create_test_plan_button()
        self.info("click on Overview, this will display an alert to the user")
        self.test_plan.click_overview()
        # switch to the alert
        if 'ok' == ok:
            self.info("confirm pop-up")
            self.test_plan.confirm_overview_pop_up()
            self.assertEqual(self.base_selenium.get_url(),
                             '{}testPlans'.format(self.base_selenium.url))
            self.info('clicking on Overview confirmed')
        else:
            self.info("cancel pop-up")
            self.test_plan.cancel_overview_pop_up()
            self.assertEqual(self.base_selenium.get_url(),
                             '{}testPlans/add'.format(self.base_selenium.url))
            self.info('clicking on Overview cancelled')

    def test024_edit_approach_overview_button(self):
        """
        Edit: Overview Approach: Make sure after I press on
        the overview button, it redirects me to the active table

        LIMS-6202
        """
        testplan = random.choice(self.test_plan_api.get_all_test_plans_json())
        self.info('Navigate to edit page of test plan: {} '.format(
            testplan['testPlanName']))
        self.test_plan.get_test_plan_edit_page_by_id(testplan['id'])
        testplans_url = self.base_selenium.get_url()
        self.info('testplans_url : {}'.format(testplans_url))
        self.info('click on Overview, it will redirect you to test plans page')
        self.test_plan.click_overview()
        self.test_plan.sleep_tiny()
        self.assertEqual(self.base_selenium.get_url(),
                         '{}testPlans'.format(self.base_selenium.url))
        self.info('clicking on Overview confirmed')

    def test025_testplans_search_then_navigate(self):
        """
        Search Approach: Make sure that you can search then navigate to any other page

        LIMS-6201
        """
        testplan = random.choice(self.test_plan_api.get_all_test_plans_json())
        search_results = self.test_plan.search(testplan['testPlanName'])
        self.assertGreater(
            len(search_results), 1,
            " * There is no search results for it, Report a bug.")
        # Navigate to articles page
        self.info('navigate to articles page')
        Articles().get_articles_page()
        self.assertEqual(self.base_selenium.get_url(),
                         '{}articles'.format(self.base_selenium.url))

    def test026_hide_all_table_configurations(self):
        """
        Table configuration: Make sure that you can't hide all the fields from the table configuration

        LIMS-6288
        """
        self.assertFalse(self.test_plan.deselect_all_configurations())

    def test027_test_unit_update_version_in_testplan(self):
        """
        Test plan: Test unit Approach: In case I update category & iteration of
        test unit that used in test plan with new version, when  go to test plan
        to add the same test unit , I found category & iteration updated

        LIMS-3703
        """
        self.test_unit_page = TstUnit()
        self.info("select random test unit to create the test plan with it")
        testunit = random.choice(TestUnitAPI().get_testplan_valid_test_unit())

        self.info(
            'A random test unit is chosen, its name: {}, category: {} and number of iterations: {}'
            .format(testunit['name'], testunit['categoryName'],
                    testunit['iterations']))

        self.info("create the first testplan")
        first_testplan_name, payload1 = self.test_plan_api.create_testplan()
        self.info('First test plan create with name: {}'.format(
            payload1['testPlan']['text']))

        self.info(
            "go to testplan edit to get the number of iterations and test unit category"
        )
        first_testplan_testunit_category, first_testplan_testunit_iteration = \
            self.test_plan.get_testunit_category_iterations(payload1['testPlan']['text'], testunit['name'])

        self.info(
            "go to test units' active table and search for this test unit")
        self.test_unit_page.get_test_units_page()
        self.info('Navigating to test unit {} edit page'.format(
            testunit['name']))
        self.test_unit_page.open_test_unit_edit_page_by_id(testunit['id'])
        self.test_unit_page.sleep_small()
        new_iteration = str(int(first_testplan_testunit_iteration) + 1)
        new_category = self.generate_random_string()
        self.info("update the iteration to {} and category to {}".format(
            new_iteration, new_category))
        self.test_unit_page.set_category(new_category)
        self.test_unit_page.set_testunit_iteration(new_iteration)
        self.info("press save and complete to create a new version")
        self.test_unit_page.save_and_create_new_version()

        self.info(" go back to test plans active table")
        self.test_plan.get_test_plans_page()
        self.info(
            " create new testplan with this testunit after creating the new version"
        )
        response, payload2 = self.test_plan_api.create_testplan()
        self.assertEqual(response["status"], 1)
        second_testplan_name = payload2['testPlan']['text']
        self.info('Second test plan create with name: {}'.format(
            second_testplan_name))

        self.info(
            "check the iteration and category to be the same as the new version"
        )
        self.info(
            "go to testplan edit to get the number of iterations and testunit category"
        )
        second_testplan_testunit_category, second_testplan_testunit_iteration = \
            self.test_plan.get_testunit_category_iterations(second_testplan_name, testunit['name'])

        self.info(
            'Asserting that the category of the test unit in the first test plan is not updated'
        )
        self.assertNotEqual(first_testplan_testunit_category, new_category)
        self.info(
            'Asserting that the iterations of the test unit in the first test plan is not updated'
        )
        self.assertNotEqual(first_testplan_testunit_iteration,
                            second_testplan_testunit_iteration)
        self.info(
            'Asserting that the category of the test unit in the second new_iteration is the '
            'same as the updated category')
        self.assertEqual(second_testplan_testunit_category, new_category)
        self.info(
            'Asserting that the iterations of the test unit in the second testplan is the '
            'same as the updated iterations')
        self.assertEqual(second_testplan_testunit_iteration, new_iteration)

    def test028_childtable_limits_of_quantification(self):
        """
        Limits of quantification should be viewed in the testplan's child table

        LIMS-4179

        New: Test plan: Limits of quantification Approach: In case I update the limits
        of quantification this will trigger new version in the active table & version table

        LIMS-4426
        """
        self.info(
            "Create new quantitative test unit with quantification limits")
        self.test_unit_api = TestUnitAPI()
        oldUpperLimit = self.generate_random_number(lower=50, upper=100)
        oldLowerLimit = self.generate_random_number(lower=1, upper=49)
        tu_response, tu_payload = self.test_unit_api.create_quantitative_testunit(
            quantificationUpperLimit=oldUpperLimit,
            quantificationLowerLimit=oldLowerLimit,
            useQuantification=True,
            useSpec=False)
        self.assertEqual(tu_response['status'], 1, tu_payload)
        testunit_display_old_quantification_limit = '{}-{}'.format(
            tu_payload['quantificationLowerLimit'],
            tu_payload['quantificationUpperLimit'])

        test_plan = self.test_plan_api.create_testplan_from_test_unit_id(
            tu_response['testUnit']['testUnitId'])
        self.assertTrue(test_plan, "failed to create test plan")
        testplan_childtable_data = self.test_plan.search_and_get_childtable_data_for_testplan(
            test_plan['testPlanEntity']['name'])
        self.info('Asserting the limits of quantification viewed correctly')
        self.assertIn(testunit_display_old_quantification_limit,
                      testplan_childtable_data[0].values())

        new_quantification_lower_limit, new_quantification_upper_limit = \
            self.test_plan.update_upper_lower_limits_of_testunit(test_plan['id'])

        testunit_display_new_quantification_limit = '{}-{}'.format(
            new_quantification_lower_limit, new_quantification_upper_limit)

        self.test_plan.get_test_plans_page()
        testplan_childtable_data = self.test_plan.search_and_get_childtable_data_for_testplan(
            test_plan['testPlanEntity']['name'])
        self.info('Asserting the limits of quantification viewed correctly')
        self.assertIn(testunit_display_new_quantification_limit,
                      testplan_childtable_data[0].values())
        test_plan_data = self.test_plan.get_the_latest_row_data()
        self.info('Asserting that new version created')
        self.assertEqual(test_plan_data['Version'], '2')
class OrdersExtendedTestCases(BaseTest):
    def setUp(self):
        super().setUp()
        self.order_page = Order()
        self.suborder_table = SubOrders()
        self.orders_api = OrdersAPI()
        self.orders_page = Orders()
        self.analyses_page = AllAnalysesPage()
        self.test_unit_api = TestUnitAPI()
        self.test_units_page = TstUnits()
        self.my_profile_page = MyProfile()
        self.set_authorization(auth=BaseAPI().AUTHORIZATION_RESPONSE)
        self.test_unit_api.set_name_configuration_name_only()
        self.orders_api.set_configuration()
        self.order_page.get_orders_page()
        self.selected_language = 'EN'

    def tearDown(self):
        if self.selected_language == 'DE':
            self.my_profile_page.get_my_profile_page()
            self.my_profile_page.chang_lang(lang='EN')
        return super().tearDown()

    @parameterized.expand(['EN', 'DE'])
    @attr(series=True)
    def test001_new_fields_are_displayed_in_order_child_table(self, lang):
        """
        Orders : child table: check that new fields of "Forwarding" , "Report sent by", "validation date" and
        "validation by"have been added to order's child table in both EN and DE

        LIMS-7714
        LIMS-7715
        """
        if lang == 'EN':
            required_headers = [
                'Forwarding', 'Report sent by', 'Validation by',
                'Validation date'
            ]
        else:
            self.selected_language = 'DE'
            self.my_profile_page.get_my_profile_page()
            self.my_profile_page.chang_lang(lang='DE')
            self.orders_page.get_orders_page()
            required_headers = [
                'Versand', 'Bericht Versand duch', 'Probenfreigabe Datum',
                'Probenfreigabe durch'
            ]

        self.orders_page.open_child_table(self.orders_page.result_table()[0])
        header_row = self.base_selenium.get_table_head_elements(
            element='general:table_child')
        displayed_child_headers = [h.text for h in header_row]
        displayed_Configuration_headers = self.orders_page.navigate_to_child_table_configuration(
        )
        for header in required_headers:
            self.info('asserting {} is displayed '.format(header))
            self.assertIn(header, displayed_child_headers)
            self.assertIn(header, displayed_Configuration_headers)

    @attr(series=True)
    def test002_check_validation_date_validation_by(self):
        """
         Orders: Validation date & Validation by : check that when user update the validation date &
         the validation by, the update should reflect on order's child table

         LIMS-7729
        """
        today = date.today()
        current_date = today.strftime("%d.%m.%Y")
        self.info('Calling the users api to create a new user with username')
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, payload)
        self.single_analysis_page = SingleAnalysisPage()
        self.login_page = Login()
        self.info(
            "create new order and update its validation option to be conform")
        order_response, order_payload = self.orders_api.create_new_order()
        self.assertEqual(order_response['status'], 1, order_payload)
        order_no = order_payload[0]['orderNo']
        self.info('edit order with No {}'.format(order_no))
        self.orders_page.get_order_edit_page_by_id(
            order_response['order']['mainOrderId'])
        self.order_page.sleep_small()
        self.info('navigate to analysis tab')
        self.order_page.navigate_to_analysis_tab()
        self.order_page.sleep_tiny()
        self.single_analysis_page.set_testunit_values()
        self.order_page.sleep_tiny()
        self.info('change validation options to conform')
        self.single_analysis_page.change_validation_options(text='Conform')
        self.order_page.get_orders_page()
        self.order_page.sleep_tiny()
        self.orders_page.filter_by_order_no(filter_text=order_no)
        self.assertEqual(len(self.orders_page.result_table()) - 1, 1)
        suborders_data = self.order_page.get_child_table_data(index=0)
        self.info('assert validation by is set correctly')
        self.assertEqual(suborders_data[0]['Validation by'],
                         self.base_selenium.username)
        self.assertEqual(suborders_data[0]['Validation date'], current_date)
        self.info(
            'go to analysis table and assert validation by and validation options'
            ' are set correctly as in order active table')
        self.orders_page.navigate_to_analysis_active_table()
        self.analyses_page.filter_by_analysis_number(
            suborders_data[0]['Analysis No.'])
        analysis_data = self.analyses_page.get_the_latest_row_data()
        self.assertEqual(suborders_data[0]['Validation by'],
                         analysis_data['Validation by'])
        self.assertEqual(suborders_data[0]['Validation date'],
                         analysis_data['Validation date'])
        self.info("Logout then login again using new user {}".format(
            payload['username']))
        self.login_page.logout()
        self.login_page.login(username=payload['username'],
                              password=payload['password'])
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.orders_page.get_order_edit_page_by_id(
            order_response['order']['mainOrderId'])
        self.info(
            'change validation options so validation by is changed to {}',
            payload['username'])
        self.order_page.navigate_to_analysis_tab()
        self.single_analysis_page.change_validation_options(text='Approved')
        self.orders_page.get_orders_page()
        self.orders_page.filter_by_order_no(filter_text=order_no)
        suborders_after = self.order_page.get_child_table_data(index=0)
        self.assertEqual(suborders_after[0]['Validation by'],
                         payload['username'])
        self.assertEqual(suborders_after[0]['Validation date'], current_date)

    @attr(series=True)
    def test003_enter_long_method_should_be_in_multiple_lines_in_order_form(
            self):
        """
        In case you select the method to display and you entered long text in it,
        the method should display into multiple lines in the order form

        LIMS-6663
        """
        self.orders_page.sleep_tiny()
        self.test_units_page.get_test_units_page()
        self.orders_page.sleep_tiny()
        self.test_units_page.open_configurations()
        self.orders_page.sleep_tiny()
        self.test_units_page.open_testunit_name_configurations_options()
        self.test_units_page.select_option_to_view_search_with(
            view_search_options=['Method'])
        self.info(' create test unit with long method text ')
        api, payload = self.test_unit_api.create_test_unit_with_long_text()
        self.assertEqual(api['status'], 1, payload)
        self.info('go to orders page')
        self.order_page.get_orders_page()
        self.info('create new order with the test unit of long method text')
        self.suborder_table.create_new_order(save=False,
                                             material_type='Raw Material')
        self.suborder_table.set_test_units(test_units=[payload['method']],
                                           remove_old=True)
        self.orders_page.save(save_btn='order:save_btn')
        self.info('assert method text appears in multiple lines')
        self.order_page.get_table_with_add()
        multiple_lines_properties = self.suborder_table.get_testunit_multiple_line_properties(
        )
        self.assertEquals(multiple_lines_properties['textOverflow'], 'clip')
        self.assertEquals(multiple_lines_properties['lineBreak'], 'auto')

    @parameterized.expand(['Name', 'Method', 'Unit', 'No'])
    @attr(series=True)
    def test004_search_with_test_unit_name_method(self, search_by):
        """
        Orders:Test unit search approach
        allow user to search with test unit name in the drop down list of the order form
        LIMS-6664
        allow user to search with test unit method in the drop down list of order form
        LIMS-6666
        allow user to search with test unit type in the drop down list of order form
        LIMS-6668
        allow user to search with test unit number in the drop down list of order form
        LIMS-6665

        """
        response, payload = self.test_unit_api.create_quantitative_testunit(
            unit="RandomUnit")
        self.assertEqual(response['status'], 1)
        self.test_units_page.get_test_units_page()
        self.orders_page.sleep_tiny()
        self.test_units_page.open_configurations()
        self.orders_page.sleep_tiny()
        self.test_units_page.open_testunit_name_configurations_options()
        self.test_units_page.select_option_to_view_search_with(
            view_search_options=[search_by])
        self.order_page.get_orders_page()

        if search_by == 'Name':
            testunit_search = payload['name']
        elif search_by == 'Method':
            testunit_search = payload['method']
        elif search_by == 'Unit':
            testunit_search = payload['unit']
        elif search_by == 'No':
            testunit_search = str(payload['number'])

        testunits = self.suborder_table.create_new_order_get_test_unit_suggetion_list(
            test_unit_name=testunit_search)

        self.info('checking {} field only is displayed'.format(search_by))
        self.assertGreater(len(testunits), 0)

    @parameterized.expand([('Name', 'Type'), ('Unit', 'No'),
                           ('Quantification Limit', '')])
    @attr(series=True)
    def test005_test_unit_name_allow_user_to_filter_with_selected_two_options_order(
            self, search_view_option1, search_view_option2):
        """
         Orders: Filter test unit Approach: Allow the search criteria in
         the drop down list in the filter section to be same as in the form

         LIMS-7411
        """
        self.test_units_page.get_test_units_page()
        self.test_units_page.open_configurations()
        self.test_units_page.open_testunit_name_configurations_options()
        self.test_units_page.select_option_to_view_search_with(
            view_search_options=[search_view_option1, search_view_option2])

        upperLimit = self.generate_random_number(lower=50, upper=100)
        lowerLimit = self.generate_random_number(lower=1, upper=49)
        self.info(
            'Create new quantitative test unit with unit and quantification')
        response, payload = self.test_unit_api.create_quantitative_testunit(
            useSpec=False,
            useQuantification=True,
            quantificationUpperLimit=upperLimit,
            quantificationLowerLimit=lowerLimit,
            unit='m[g]{o}')
        self.assertEqual(response['status'], 1, payload)
        formated_tu, _ = self.test_unit_api.get_testunit_form_data(
            response['testUnit']['testUnitId'])
        test_unit = [{
            'id': formated_tu['testUnit']['id'],
            'name': formated_tu['testUnit']['name']
        }]
        self.info('create new order created test unit number'.format(payload))
        res, order = self.orders_api.create_new_order(testUnits=test_unit)
        self.assertEqual(res['status'], 1,
                         'order not created with {}'.format(order))
        if search_view_option1 == 'Name' and search_view_option2 == 'Type':
            filter_text = payload['name']
        elif search_view_option1 == 'Unit' and search_view_option2 == 'No':
            filter_text = str(payload['number'])
        else:
            filter_text = str(payload['quantificationLowerLimit']) + '-' + str(
                payload['quantificationUpperLimit'])

        self.orders_page.get_orders_page()
        self.orders_page.sleep_tiny()
        self.orders_page.open_filter_menu()
        self.base_selenium.wait_element(element='orders:test_units_filter')
        self.orders_page.filter_by(filter_element='orders:test_units_filter',
                                   filter_text=filter_text)
        found_filter_text = self.base_selenium.get_text(
            'orders:test_units_filter').replace("\n×", "")
        if search_view_option1 == 'Name' and search_view_option2 == 'Type':
            self.assertEqual(found_filter_text,
                             payload['name'] + ': Quantitative')
        elif search_view_option1 == 'Unit' and search_view_option2 == 'No':
            self.assertEqual(found_filter_text,
                             'm[g]{o}: ' + str(payload['number']))
        else:
            self.assertEqual(found_filter_text, filter_text)

        self.orders_page.filter_apply()
        self.orders_page.sleep_tiny()
        results = self.order_page.result_table()
        self.assertGreaterEqual(len(results), 1)
        for i in range(len(results) - 1):
            suborders = self.orders_page.get_child_table_data(index=i)
            key_found = False
            for suborder in suborders:
                if payload['name'] == suborder['Test Units']:
                    key_found = True
                    break
            self.assertTrue(key_found)
            # close child table
            self.orders_page.close_child_table(source=results[i])

    @parameterized.expand(['Quantitative', 'Qualitative', 'Quantitative MiBi'])
    @attr(series=True)
    def test006_test_unit_with_sub_and_super_unit_name_appears_in_unit_field_drop_down(
            self, type):
        """
        New: Test unit: Export: In case the unit field with sub & super,
        allow this to display in the unit field drop down list in the analysis form

        LIMS-6675
        """
        self.test_unit_api.set_name_configuration_unit_only()
        if type == 'Quantitative':
            self.info('Create new Quantitative testunit')
            response, payload = self.test_unit_api.create_quantitative_testunit(
                unit='m[g]{o}')
        elif type == 'Qualitative':
            self.info('Create new Qualitative testunit')
            response, payload = self.test_unit_api.create_qualitative_testunit(
                unit='m[g]{o}')
        else:
            self.info('Create new Quantitative MiBi testunit')
            response, payload = self.test_unit_api.create_mibi_testunit(
                unit='m[g]{o}')

        self.assertEqual(response['status'], 1,
                         'test unit not created {}'.format(payload))
        self.info('go to orders page')
        self.order_page.get_orders_page()
        unit = self.suborder_table.create_new_order_get_test_unit_suggetion_list(
            material_type='', test_unit_name='m[g]{o}')
        self.assertIn("m[g]{o}", unit)

    @parameterized.expand(['sub_script', 'super_script'])
    @attr(series=True)
    def test007_filter_testunit_by_scripts(self, value):
        """
         Make sure that user can filter by sub & super scripts in the filter drop down list

         LIMS-7447
         LIMS-7444
        """
        self.test_unit_api.set_name_configuration_unit_only()
        if value == 'sub_script':
            api, testunit = self.test_unit_api.create_qualitative_testunit(
                unit='14[158]')
        else:
            api, testunit = self.test_unit_api.create_qualitative_testunit(
                unit='15{158}')
        self.assertEqual(api['status'], 1)
        unit = testunit['unit']
        self.orders_page.get_orders_page()
        self.order_page.sleep_small()
        self.base_selenium.scroll(False)
        self.orders_page.apply_filter_scenario(
            filter_element='orders:test_units_filter',
            filter_text=unit,
            field_type='drop_down')
        self.assertIsNotNone(
            self.base_selenium.is_text_included_in_drop_down_items(
                element='orders:test_units_filter', item_text=unit))

        results = self.order_page.result_table()
        self.assertGreaterEqual(len(results), 1)
        for i in range(len(results) - 1):
            suborders = self.orders_page.get_child_table_data(index=i)
            key_found = False
            for suborder in suborders:
                if unit in suborder['Test Units']:
                    key_found = True
                    break
            self.assertTrue(key_found)
            # close child table
            self.orders_page.open_child_table(source=results[i])

    @parameterized.expand(['Name', 'No', 'Name:No'])
    @attr(series=True)
    def test008_change_contact_config(self, search_by):
        """
         Orders: Contact configuration approach: In case the user
         configures the contact field to display name & number this action
         should reflect on the order active table
         LIMS-6632
        """
        self.contacts_page = Contacts()
        self.info('get random contact')
        contacts_response, _ = ContactsAPI().get_all_contacts(limit=10)
        self.assertEqual(contacts_response['status'], 1)
        payload = random.choice(contacts_response['contacts'])
        self.orders_page.open_order_config()
        self.info('change contact view by options')
        self.contacts_page.open_contact_configurations_options()
        if search_by == 'Name':
            search_text = payload['name']
            result = payload['name']
            search_by = [search_by]
        elif search_by == 'No':
            search_text = 'No: ' + str(payload['companyNo'])
            result = str(payload['companyNo'])
            search_by = [search_by]
        elif search_by == 'Name:No':
            search_text = payload['name'] + ' No: ' + str(payload['companyNo'])
            search_by = search_by.split(':')
            result = payload['name']

        self.contacts_page.select_option_to_view_search_with(
            view_search_options=search_by)
        self.info('go to order active table')
        self.orders_page.get_orders_page()
        self.orders_page.filter_by_contact(filter_text=result)
        rows = self.orders_page.result_table()
        order_data = self.base_selenium.get_row_cells_dict_related_to_header(
            row=rows[0])
        self.info('assert contact appear in format {}'.format(search_by))
        self.assertEqual(order_data['Contact Name'], search_text)

    @attr(series=True)
    def test009_update_contact_config_to_number_create_form(self):
        """
        Sample Management: Contact configuration approach: In case the user configures the
        contact field to display number this action should reflect on the order form step one

        LIMS-6626
        """
        self.info("set contact configuration to be searchable by number only")
        self.orders_api.set_contact_configuration_to_number_only()
        response, _ = ContactsAPI().get_all_contacts()
        self.assertEqual(response['status'], 1)
        self.assertGreaterEqual(response['count'], 1)
        random_contact = random.choice(response['contacts'])
        contact_no = random_contact['companyNo']
        contact_name = random_contact['name']
        testplan = TestPlanAPI().create_completed_testplan_random_data()
        self.info("create new order with contact no {}".format(contact_no))
        self.suborder_table.create_new_order(
            contacts=[contact_no],
            save=False,
            material_type=testplan['materialType'][0]['text'],
            article=testplan['selectedArticles'][0]['text'],
            test_plans=[testplan['testPlan']['text']])
        self.info("assert that contact set to {}".format(
            str('No: ' + contact_no)))
        self.assertCountEqual(self.order_page.get_contacts(),
                              [str('No: ' + contact_no)])
        self.order_page.clear_contact()
        contact_name_result = self.base_selenium.get_drop_down_suggestion_list(
            element='order:contact', item_text=contact_name)
        self.info(
            "assert that suggestion list of contact name {} is {}".format(
                contact_name, str('No: ' + contact_no)))

        self.assertEqual(contact_name_result[0], str('No: ' + contact_no))
    def test002_check_validation_date_validation_by(self):
        """
         Orders: Validation date & Validation by : check that when user update the validation date &
         the validation by, the update should reflect on order's child table

         LIMS-7729
        """
        today = date.today()
        current_date = today.strftime("%d.%m.%Y")
        self.info('Calling the users api to create a new user with username')
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, payload)
        self.single_analysis_page = SingleAnalysisPage()
        self.login_page = Login()
        self.info(
            "create new order and update its validation option to be conform")
        order_response, order_payload = self.orders_api.create_new_order()
        self.assertEqual(order_response['status'], 1, order_payload)
        order_no = order_payload[0]['orderNo']
        self.info('edit order with No {}'.format(order_no))
        self.orders_page.get_order_edit_page_by_id(
            order_response['order']['mainOrderId'])
        self.order_page.sleep_small()
        self.info('navigate to analysis tab')
        self.order_page.navigate_to_analysis_tab()
        self.order_page.sleep_tiny()
        self.single_analysis_page.set_testunit_values()
        self.order_page.sleep_tiny()
        self.info('change validation options to conform')
        self.single_analysis_page.change_validation_options(text='Conform')
        self.order_page.get_orders_page()
        self.order_page.sleep_tiny()
        self.orders_page.filter_by_order_no(filter_text=order_no)
        self.assertEqual(len(self.orders_page.result_table()) - 1, 1)
        suborders_data = self.order_page.get_child_table_data(index=0)
        self.info('assert validation by is set correctly')
        self.assertEqual(suborders_data[0]['Validation by'],
                         self.base_selenium.username)
        self.assertEqual(suborders_data[0]['Validation date'], current_date)
        self.info(
            'go to analysis table and assert validation by and validation options'
            ' are set correctly as in order active table')
        self.orders_page.navigate_to_analysis_active_table()
        self.analyses_page.filter_by_analysis_number(
            suborders_data[0]['Analysis No.'])
        analysis_data = self.analyses_page.get_the_latest_row_data()
        self.assertEqual(suborders_data[0]['Validation by'],
                         analysis_data['Validation by'])
        self.assertEqual(suborders_data[0]['Validation date'],
                         analysis_data['Validation date'])
        self.info("Logout then login again using new user {}".format(
            payload['username']))
        self.login_page.logout()
        self.login_page.login(username=payload['username'],
                              password=payload['password'])
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.orders_page.get_order_edit_page_by_id(
            order_response['order']['mainOrderId'])
        self.info(
            'change validation options so validation by is changed to {}',
            payload['username'])
        self.order_page.navigate_to_analysis_tab()
        self.single_analysis_page.change_validation_options(text='Approved')
        self.orders_page.get_orders_page()
        self.orders_page.filter_by_order_no(filter_text=order_no)
        suborders_after = self.order_page.get_child_table_data(index=0)
        self.assertEqual(suborders_after[0]['Validation by'],
                         payload['username'])
        self.assertEqual(suborders_after[0]['Validation date'], current_date)
class TestUnitsTestCases(BaseTest):
    def setUp(self):
        super().setUp()
        self.test_unit_page = TstUnit()
        self.test_units_page = TstUnits()
        self.test_plan = TstPlan()
        self.article_api = ArticleAPI()
        self.test_unit_api = TestUnitAPI()
        self.set_authorization(auth=self.article_api.AUTHORIZATION_RESPONSE)
        self.test_unit_api.set_configuration()
        self.test_unit_page.get_test_units_page()

    @attr(series=True)
    #@skip('waiting for API deleting')
    def test036_archive_quantifications_limit_field(self):
        """
        User can archive the quantification limits field from the configuration section if not used.
        "Archive-allowed"
        LIMS-4164
        """
        self.test_unit_page.open_configurations()
        self.test_unit_page.archive_quantification_limit_field()
        if not self.test_unit_page.is_field_in_use():
            self.assertFalse(
                self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification'))
            self.test_unit_page.get_archived_fields_tab()

            self.assertTrue(self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification'))
            self.test_unit_page.get_test_units_page()
            self.test_unit_page.click_create_new_testunit()
            self.test_unit_page.set_testunit_type(testunit_type='Quantitative')
            self.assertFalse(self.base_selenium.check_element_is_exist(element='test_unit:use_quantification'))

    @attr(series=True)
    def test037_restore_quantifications_limit_field(self):
        """
        User can archive the quantification limits field from the configuration section if not used.

        "Restore"
        LIMS-4164
        """
        self.test_unit_page.open_configurations()
        self.test_unit_page.archive_quantification_limit_field()
        if not self.test_unit_page.is_field_in_use():
            self.test_unit_page.restore_quantification_limit_field()
            self.assertFalse(
                self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification'))
            self.test_unit_page.get_active_fields_tab()
            self.assertTrue(self.base_selenium.check_element_is_exist('test_unit:configuration_testunit_useQuantification'))
            self.test_unit_page.get_test_units_page()
            self.test_unit_page.click_create_new_testunit()
            self.test_unit_page.set_testunit_type(testunit_type='Quantitative')
            self.assertTrue(self.base_selenium.check_element_is_exist(element='test_unit:use_quantification'))

    @attr(series=True)
    def test038_test_unit_name_is_mandatory(self):
        """
        New: Test unit: Configuration: Test unit Name Approach: Make the test units field
        as as mandatory field (This mean you can't remove it )

        LIMS- 5651
        """
        self.test_unit_page.open_configurations()
        self.test_unit_page.open_testunit_name_configurations_options()
        self.assertTrue(self.test_unit_page.check_all_options_of_search_view_menu())

    @parameterized.expand(['Name', 'Method', 'Type', 'No'])
    @attr(series=True)
    @skip('https://modeso.atlassian.net/browse/LIMSA-382')
    def test039_test_unit_name_allow_user_to_search_with_selected_options_testplan(self, search_view_option):
        """
        New: Test Unit: Configuration: Test unit Name Approach: Allow user to search with
        (name, number, type, method) in the drop down list of the test plan for.

        LIMS- 6422
        """
        self.test_unit_page.open_configurations()
        self.test_unit_page.open_testunit_name_configurations_options()
        old_values = self.test_unit_page.select_option_to_view_search_with(view_search_options=[search_view_option])
        self.info('Create new testunit with qualitative and random generated data')
        response, payload = self.test_unit_api.create_qualitative_testunit()
        self.assertEqual(response['status'], 1, payload)
        self.info('new testunit created with number  {}'.format(payload['number']))
        self.info('get random In Progrees test plan')
        test_plan = random.choice(TestPlanAPI().get_inprogress_testplans())
        self.assertTrue(test_plan, 'No test plan selected')
        self.info('Navigate to test plan edit page')
        self.test_plan.get_test_plan_edit_page_by_id(test_plan['id'])
        is_name_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['name'])
        is_number_exist = self.test_plan.search_test_unit_not_set(test_unit=str(payload['number']))
        is_type_exist = self.test_plan.search_test_unit_not_set(test_unit='Qualitative')
        is_method_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['method'])

        if search_view_option == 'Name':
            self.assertTrue(is_name_exist)
            self.assertFalse(is_number_exist)
            self.assertFalse(is_type_exist)
            self.assertFalse(is_method_exist)
        elif search_view_option == 'Type':
            self.assertFalse(is_name_exist)
            self.assertFalse(is_number_exist)
            self.assertTrue(is_type_exist)
            self.assertFalse(is_method_exist)
        elif search_view_option == 'Method':
            self.assertFalse(is_name_exist)
            self.assertFalse(is_number_exist)
            self.assertFalse(is_type_exist)
            self.assertTrue(is_method_exist)
        elif search_view_option == 'No':
            self.assertFalse(is_name_exist)
            self.assertTrue(is_number_exist)
            self.assertFalse(is_type_exist)
            self.assertFalse(is_method_exist)

    @attr(series=True)
    @skip('https://modeso.atlassian.net/browse/LIMSA-382')
    def test040_test_unit_name_search_default_options_name_type_in_testplan(self):
        """
        New: Test unit: Configuration: Test units field Approach: Allow name & type
        to display by default in the test plan form In case I select them from the
        test unit configuration

        LIMS-6423
        """
        # in set_configuration() I set search to be by name and type so I don't need to add this steps here
        self.info('Create new test unit with qualitative and random generated data')
        response, payload = self.test_unit_api.create_qualitative_testunit()
        self.assertEqual(response['status'], 1, payload)
        self.info('new test unit created with number  {}'.format(payload['number']))
        self.info('get random In Progress test plan')
        test_plan = random.choice(TestPlanAPI().get_inprogress_testplans())
        self.assertTrue(test_plan, 'No test plan selected')
        self.info('Navigate to test plan edit page')
        self.test_plan.get_test_plan_edit_page_by_id(test_plan['id'])
        self.test_plan.sleep_small()
        is_name_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['name'])
        is_number_exist = self.test_plan.search_test_unit_not_set(test_unit=str(payload['number']))
        is_type_exist = self.test_plan.search_test_unit_not_set(test_unit='Qualitative')
        is_method_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['method'])
        self.assertTrue(is_name_exist)
        self.assertFalse(is_number_exist)
        self.assertTrue(is_type_exist)
        self.assertFalse(is_method_exist)

    @attr(series=True)
    @skip('https://modeso.atlassian.net/browse/LIMSA-382')
    def test041_test_unit_name_view_method_option_multiple_line_in_testplan(self):
        """
        New: Test Unit: Configuration: Test unit Name Approach: In case you select
        the method to display and you entered long text in it, the method should
        display into multiple lines (test plan)

        LIMS-6424
        """
        self.info('Generate random data for update')
        new_random_method = self.generate_random_string() + \
                            self.generate_random_string() + \
                            self.generate_random_string()

        self.test_unit_page.open_configurations()
        self.test_unit_page.open_testunit_name_configurations_options()
        self.test_unit_page.select_option_to_view_search_with(view_search_options=['Method'])
        self.info('Create new testunit with qualitative and random generated data')
        response, payload = self.test_unit_api.create_qualitative_testunit(method=new_random_method)
        self.assertEqual(response['status'], 1, payload)
        self.info('new testunit created with number  {}'.format(payload['number']))
        self.info('get random In Progrees test plan')
        test_plan = random.choice(TestPlanAPI().get_inprogress_testplans())
        self.assertTrue(test_plan, 'No test plan selected')
        self.info('Navigate to test plan edit page')
        self.test_plan.get_test_plan_edit_page_by_id(test_plan['id'])
        self.test_plan.set_test_unit(test_unit=new_random_method)
        multiple_lines_properties = self.test_plan.get_testunit_in_testplan_title_multiple_line_properties()
        self.assertEquals(multiple_lines_properties['textOverflow'], 'clip')
        self.assertEquals(multiple_lines_properties['lineBreak'], 'auto')

    @parameterized.expand([('Name', 'Type'),
                           ('Name', 'Method'),
                           ('Name', 'No'),
                           ('Type', 'Method'),
                           ('Type', 'No'),
                           ('Method', 'No')])
    @attr(series=True)
    @skip('https://modeso.atlassian.net/browse/LIMSA-382')
    def test042_test_unit_name_allow_user_to_search_with_selected_two_options_testplan(self, search_view_option1,
                                                                                       search_view_option2):
        """
        New: Test Unit: Configuration: Test unit Name Approach: Allow user to search with
        (name, number, type, method) in the drop down list of the analysis for

        LIMS- 6426
        """
        self.test_unit_page.open_configurations()
        self.test_unit_page.open_testunit_name_configurations_options()
        self.test_unit_page.select_option_to_view_search_with(
            view_search_options=[search_view_option1, search_view_option2])
        self.info('Create new test unit with qualitative and random generated data')
        response, payload = self.test_unit_api.create_qualitative_testunit()
        self.assertEqual(response['status'], 1, payload)
        self.info('new test unit created with number  {}'.format(payload['number']))
        self.info('get random In Progress test plan')
        test_plan = random.choice(TestPlanAPI().get_inprogress_testplans())
        self.assertTrue(test_plan, 'No test plan selected')
        self.info('Navigate to test plan edit page')
        self.test_plan.get_test_plan_edit_page_by_id(test_plan['id'])
        self.test_plan.sleep_small()
        is_name_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['name'])
        is_number_exist = self.test_plan.search_test_unit_not_set(test_unit=str(payload['number']))
        is_type_exist = self.test_plan.search_test_unit_not_set(test_unit='Qualitative')
        is_method_exist = self.test_plan.search_test_unit_not_set(test_unit=payload['method'])

        if search_view_option1 == 'Name' and search_view_option2 == 'Type':
            self.assertTrue(is_name_exist)
            self.assertFalse(is_number_exist)
            self.assertTrue(is_type_exist)
            self.assertFalse(is_method_exist)
        elif search_view_option1 == 'Name' and search_view_option2 == 'Method':
            self.assertTrue(is_name_exist)
            self.assertFalse(is_number_exist)
            self.assertFalse(is_type_exist)
            self.assertTrue(is_method_exist)
        elif search_view_option1 == 'Name' and search_view_option2 == 'No':
            self.assertTrue(is_name_exist)
            self.assertTrue(is_number_exist)
            self.assertFalse(is_type_exist)
            self.assertFalse(is_method_exist)
        elif search_view_option1 == 'Type' and search_view_option2 == 'Method':
            self.assertFalse(is_name_exist)
            self.assertFalse(is_number_exist)
            self.assertTrue(is_type_exist)
            self.assertTrue(is_method_exist)
        elif search_view_option1 == 'Type' and search_view_option2 == 'No':
            self.assertFalse(is_name_exist)
            self.assertTrue(is_number_exist)
            self.assertTrue(is_type_exist)
            self.assertFalse(is_method_exist)
        elif search_view_option1 == 'Method' and search_view_option2 == 'No':
            self.assertFalse(is_name_exist)
            self.assertTrue(is_number_exist)
            self.assertFalse(is_type_exist)
            self.assertTrue(is_method_exist)

    @attr(series=True)
    def test049_filter_by_testunit_changed_by(self):
        """
        New: Test units: Filter Approach: Make sure you can filter by changed by

        LIMS-6428
        """
        self.login_page = Login()
        self.info('Calling the users api to create a new user with username')
        response, payload = UsersAPI().create_new_user()
        self.assertEqual(response['status'], 1, payload)
        self.login_page.logout()
        self.login_page.login(username=payload['username'], password=payload['password'])
        self.base_selenium.wait_until_page_url_has(text='dashboard')
        self.test_units_page.get_test_units_page()
        new_name = self.generate_random_string()
        method = self.generate_random_string()
        test_unit_no = self.test_unit_page.create_qualitative_testunit(name=new_name, method=method)
        self.test_unit_page.save_and_wait()
        self.assertTrue(test_unit_no, 'Test unit not created')
        self.info('New unit is created successfully with number: {}'.format(test_unit_no))
        self.test_units_page.sleep_tiny()
        test_unit_found = self.test_units_page.filter_by_user_get_result(payload['username'])
        self.assertTrue(test_unit_found)

    @parameterized.expand([('Name', 'Type'),
                           ('Name', 'Method'),
                           ('Name', 'No'),
                           ('Type', 'Method'),
                           ('Type', 'No'),
                           ('No', 'Method'),
                           ('Unit', 'No'),
                           ('Quantification Limit', '')
                           ])
    @attr(series=True)
    def test051_test_unit_name_allow_user_to_search_with_selected_two_options_order(self, first_search_option,
                                                                                    second_search_option):
        """
        Test Unit: Configuration: Test units Name Approach: When the user select any two options
        from the test unit configuration, this action should reflect on the order form

        LIMS-6672

        Orders: Default filter test unit Approach: Allow the search criteria in the drop down list
        in the filter section to be same as in the form

        LIMS-7414
        """
        options_exist = {}
        order_page = Order()
        self.test_unit_page.open_configurations()
        self.test_unit_page.open_testunit_name_configurations_options()
        self.test_unit_page.select_option_to_view_search_with(
            view_search_options=[first_search_option, second_search_option])

        self.info('create new quantitative test unit with unit and quantification')
        response, payload = self.test_unit_api.create_quantitative_testunit(
            useSpec=False, useQuantification=True, unit='m[g]{o}',
            quantificationUpperLimit=self.generate_random_number(lower=50, upper=100),
            quantificationLowerLimit=self.generate_random_number(lower=1, upper=49))
        self.assertEqual(response['status'], 1, payload)
        quantification_limit = '{}-{}'.format(payload['quantificationLowerLimit'],
                                              payload['quantificationUpperLimit'])
        self.info('new test unit created with number  {}'.format(payload['number']))

        self.info('get random order')
        radndom_order = random.choice(OrdersAPI().get_all_orders_json())
        self.assertTrue(radndom_order, 'No order selected')
        self.info('navigate to order edit page')
        order_page.get_order_edit_page_by_id(radndom_order['orderId'])
        order_page.sleep_small()

        if first_search_option == "Type":
            if second_search_option == "Method":
                checked_text = f'Quantitative: {payload["method"]}'
            elif second_search_option == "No":
                checked_text = f'Quantitative: {payload["number"]}'
        else:
            checked_text = f'{payload["name"]}: Quantitative'

        self.info("is test unit options existing?")
        options_exist['is_name_exist'] = order_page.is_test_unit_option_exist(search_field=payload['name'])
        options_exist['is_no_exist'] = order_page.is_test_unit_option_exist(search_field=str(payload['number']))
        options_exist['is_type_exist'] = order_page.is_test_unit_option_exist(search_field='Quantitative',
                                                                              checked_text=checked_text)
        options_exist['is_method_exist'] = order_page.is_test_unit_option_exist(search_field=payload['method'])
        options_exist['is_unit_exist'] = order_page.is_test_unit_option_exist(search_field=payload['unit'])
        options_exist['is_quantification_limit_exist'] = order_page.is_test_unit_option_exist(
            search_field=quantification_limit)

        for key, value in options_exist.items():
            if (first_search_option.lower().replace(' ', '_') in key) or (len(second_search_option.lower()) > 0 and second_search_option.lower() in key):
                self.assertTrue(value, f'{key} value should be True')
            else:
                self.assertFalse(value, f'{key} value should be False')