예제 #1
0
    def create_testplan_from_test_unit_id(self, test_unit_id):
        testunit_data = TestUnitAPI().get_testunit_form_data(
            id=test_unit_id)[0]['testUnit']
        if testunit_data['materialTypesObject'][0]['name'] == 'All':
            response, _ = GeneralUtilitiesAPI().list_all_material_types()
            _formatted_material = random.choice(response['materialTypes'])
        else:
            _formatted_material = testunit_data['materialTypesObject'][0]

        formatted_material = {
            'id': _formatted_material['id'],
            'text': _formatted_material['name']
        }

        # tu_response, tu_payload = TestUnitAPI().create_qualitative_testunit()
        testunit_data = TestUnitAPI().get_testunit_form_data(
            id=test_unit_id)[0]['testUnit']
        formated_testunit = TstUnit().map_testunit_to_testplan_format(
            testunit=testunit_data)
        formatted_article = ArticleAPI(
        ).get_formatted_article_with_formatted_material_type(
            formatted_material)
        testplan, payload = self.create_testplan(
            testUnits=[formated_testunit],
            selectedArticles=[formatted_article],
            materialType=[formatted_material],
            materialTypeId=[formatted_material['id']])

        if testplan['message'] == 'operation_success':
            return self.get_testplan_form_data(id=payload['number'])
        else:
            self.info(testplan)
 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()
예제 #3
0
 def get_active_tst_unit_with_material_type(self,
                                            search,
                                            material_type='Raw Material'):
     self.test_unit_page = TstUnit()
     self.info('Get Test Unit with  type {} .'.format(search))
     self.test_unit_page.get_test_units_page()
     test_units = self.test_unit_page.search(search)
     test_units_dict = [
         self.base_selenium.get_row_cells_dict_related_to_header(
             row=test_unit) for test_unit in test_units[:-1]
     ]
     for test_unit_dict in test_units_dict:
         if test_unit_dict[
                 'Type'] == search and material_type in test_unit_dict[
                     'Material Type']:
             return test_unit_dict
     return {}
    def create_order_with_double_test_plans(self, only_test_plans=False):
        testplan1 = TestPlanAPI().create_completed_testplan_random_data()
        article = testplan1['selectedArticles'][0]['text']
        article_id = testplan1['selectedArticles'][0]['id']
        if article == 'all':
            article, article_id = ArticleAPI().get_random_article_articleID()
        material_type = testplan1['materialType'][0]

        tu_response1, tu_payload1 = TestUnitAPI().create_qualitative_testunit()
        testunit1 = TestUnitAPI().get_testunit_form_data(id=tu_response1['testUnit']['testUnitId'])[0]['testUnit']
        tu_response2, tu_payload2 = TestUnitAPI().create_qualitative_testunit()
        testunit2 = TestUnitAPI().get_testunit_form_data(id=tu_response2['testUnit']['testUnitId'])[0]['testUnit']
        if only_test_plans:
            testunit_list = []
        else:
            testunit_list = [testunit1, testunit2]
        formated_testunit = TstUnit().map_testunit_to_testplan_format(testunit=testunit2)
        formatted_article = {'id': article_id, 'text': article}
        testplan2, _ = TestPlanAPI().create_testplan(testUnits=[formated_testunit],
                                                     selectedArticles=[formatted_article],
                                                     materialTypes=material_type)
        first_testPlan_data = TestPlanAPI()._get_testplan_form_data(id=testplan1['testPlan']['id'])
        testPlan1 = {
            'testPlan': {'id': int(first_testPlan_data[0]['testPlan']['testPlanEntity']['id']),
                         'text': first_testPlan_data[0]['testPlan']['testPlanEntity']['name']},
            'number': int(first_testPlan_data[0]['testPlan']['number'])}

        second_testPlan_data = TestPlanAPI()._get_testplan_form_data(id=testplan2['testPlanDetails']['id'])
        testPlan2 = {
            'testPlan': {'id': int(second_testPlan_data[0]['testPlan']['testPlanEntity']['id']),
                         'text': second_testPlan_data[0]['testPlan']['testPlanEntity']['name']},
            'number': int(second_testPlan_data[0]['testPlan']['number'])}
        testplan_list = [testPlan1, testPlan2]

        payload = {
            'testPlans': testplan_list,
            'testUnits': testunit_list,
            'materialType': material_type,
            'materialTypeId': material_type['id'],
            'article': {'id': article_id, 'text': article},
            'articleId': article_id
        }
        return self.create_new_order(**payload)
예제 #5
0
    def create_completed_testplan(self, material_type, formatted_article):
        material_type_id = GeneralUtilitiesAPI().get_material_id(material_type)
        formatted_material = {'id': material_type_id, 'text': material_type}
        tu_response, tu_payload = TestUnitAPI().create_qualitative_testunit()
        testunit_data = TestUnitAPI().get_testunit_form_data(
            id=tu_response['testUnit']['testUnitId'])[0]['testUnit']
        formated_testunit = TstUnit().map_testunit_to_testplan_format(
            testunit=testunit_data)
        testplan, payload = self.create_testplan(
            testUnits=[formated_testunit],
            selectedArticles=[formatted_article],
            materialType=[formatted_material],
            material_type_id=material_type_id)

        if testplan['message'] == 'operation_success':
            return self.get_testplan_form_data(
                id=int(testplan['testPlanDetails']['id']))
        else:
            self.info(testplan)
예제 #6
0
    def create_double_completed_testplan_same_name_diff_material(
            self, **kwargs):
        self.info("create completed test plan with random data")
        testplan1 = self.create_completed_testplan_random_data()
        test_plan_name_dict = {
            'id': 'new',
            'text': testplan1['testPlan']['text']
        }
        new_material = random.choice(
            GeneralUtilitiesAPI().get_material_types_without_duplicate(
                testplan1['materialType'][0]['text']))
        new_material_id = GeneralUtilitiesAPI().get_material_id(new_material)
        formatted_material = {'id': new_material_id, 'text': new_material}
        tu_response, _ = TestUnitAPI().create_qualitative_testunit(
            selectedMaterialTypes=[formatted_material])
        testunit_data = TestUnitAPI().get_testunit_form_data(
            id=tu_response['testUnit']['testUnitId'])[0]['testUnit']
        formated_testunit = TstUnit().map_testunit_to_testplan_format(
            testunit=testunit_data)
        self.info(
            "create completed test plan with same name {} and new material {}".
            format(testplan1['testPlan']['text'], new_material))
        formatted_article = ArticleAPI(
        ).get_formatted_article_with_formatted_material_type(
            material_type=formatted_material)
        response, testplan2 = self.create_testplan(
            selectedTestPlan=test_plan_name_dict,
            testPlan=test_plan_name_dict,
            testUnits=[formated_testunit],
            selectedArticles=[formatted_article],
            materialType=[formatted_material],
            materialTypeId=[new_material_id])

        if response['message'] == 'name_already_exist':
            testplan2['testPlan']['id'] = response['testPlanDetails'][
                'testPlanId']
            testplan2['selectedTestPlan']['id'] = response['testPlanDetails'][
                'testPlanId']
            return [testplan1, testplan2]
        else:
            raise Exception(
                f'cant create the test plan with payload {testplan2}')
예제 #7
0
 def create_testplan_with_multiple_materials(self, no_materials=3):
     all_material_types = GeneralUtilitiesAPI().list_all_material_types(
     )[0]['materialTypes']
     formatted_materials = random.sample(all_material_types, no_materials)
     material_type_ids = [
         material['id'] for material in formatted_materials
     ]
     selected_material_types = [
         material['name'] for material in formatted_materials
     ]
     tu_response, _ = TestUnitAPI().create_quantitative_testunit(
         selectedMaterialTypes=formatted_materials[0])
     testunit_data = TestUnitAPI().get_testunit_form_data(
         id=tu_response['testUnit']['testUnitId'])[0]['testUnit']
     formatted_testunit = TstUnit().map_testunit_to_testplan_format(
         testunit=testunit_data)
     testplan = self.create_testplan(testUnits=[formatted_testunit],
                                     materialType=formatted_materials,
                                     materialTypeId=material_type_ids)
     return testplan[1]['testPlan']['text'], selected_material_types
예제 #8
0
    def create_completed_testplan_random_data(self, no_testunits=1):
        random_article = random.choice(ArticleAPI().get_all_articles_json())
        formatted_article = {
            'id': random_article['id'],
            'text': random_article['name']
        }
        material_type_id = GeneralUtilitiesAPI().get_material_id(
            random_article['materialType'])
        formatted_material = {
            'id': material_type_id,
            'text': random_article['materialType']
        }
        # creates test unit with values in it
        formatted_testunits = []
        for testunit in range(no_testunits):
            tu_response, _ = TestUnitAPI().create_quantitative_testunit(
                selectedMaterialTypes=[formatted_material])
            testunit_data = TestUnitAPI().get_testunit_form_data(
                id=tu_response['testUnit']['testUnitId'])[0]['testUnit']
            formatted_testunit = TstUnit().map_testunit_to_testplan_format(
                testunit=testunit_data)
            formatted_testunits.append(formatted_testunit)

        testplan, payload = self.create_testplan(
            testUnits=formatted_testunits,
            selectedArticles=[formatted_article],
            materialType=[formatted_material],
            materialTypeId=[material_type_id])

        if testplan['message'] == 'operation_success':
            payload['testPlan']['id'] = testplan['testPlanDetails'][
                'testPlanId']
            payload['selectedTestPlan']['id'] = testplan['testPlanDetails'][
                'testPlanId']
            return payload
        else:
            return None
    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())
    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)