Ejemplo n.º 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)
Ejemplo n.º 2
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}')
 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.contacts_api = ContactsAPI()
     self.test_unit_api = TestUnitAPI()
     self.test_plan_api = TestPlanAPI()
     self.general_utilities = GeneralUtilitiesAPI()
     self.set_authorization(auth=BaseAPI().AUTHORIZATION_RESPONSE)
     self.test_unit_api.set_name_configuration_name_only()
     self.orders_api.set_configuration()
     self.header_page = Header()
     article_enabled = self.general_utilities.is_article_enabled()
     if article_enabled:
         self.info('go to Modules Configurations')
         self.header_page.get_modules_config_page()
         self.header_page.disable_article_option()
     self.header_page.sleep_tiny()
     self.order_page.get_orders_page()
Ejemplo n.º 4
0
    def create_testplan_with_article_not_all(self):
        response, _ = GeneralUtilitiesAPI().list_all_material_types()
        formatted_material = random.choice(response['materialTypes'])

        formatted_article = ArticleAPI(
        ).get_formatted_article_with_formatted_material_type(
            formatted_material)
        testplan, payload = self.create_testplan(
            selectedArticles=[formatted_article],
            materialType=[formatted_material])
        if testplan['message'] == 'operation_success':
            return (self.get_testplan_form_data(id=payload['number']))
        else:
            raise Exception(
                f'cant create the test plan with payload {payload}')
Ejemplo n.º 5
0
    def get_article_with_material_type(self, material_type):
        material_type_id = GeneralUtilitiesAPI().get_material_id(material_type)
        articles, payload = self.get_all_articles(limit=500)
        self.info(
            "search for article with material type {}".format(material_type))
        for article in articles['articles']:
            if article['materialType'] == material_type:
                return article['name']

        self.info("No article with requested material type, So create article")
        materialType = {"id": material_type_id, "text": material_type}
        api, payload = self.create_article(
            materialType=materialType,
            selectedMaterialType=[materialType],
            materialTypeId=int(material_type_id))
        if api['status'] == 1:
            return api['article']['name']
Ejemplo n.º 6
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)
Ejemplo n.º 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
Ejemplo n.º 8
0
 def get_suborder_data_with_different_material_type(self, material_type):
     new_material = random.choice(GeneralUtilitiesAPI(
     ).get_formatted_material_types_without_duplicate(material_type))
     formatted_material = {
         'id': new_material['id'],
         'text': new_material['name']
     }
     formatted_article = ArticleAPI(
     ).get_formatted_article_with_formatted_material_type(
         material_type=formatted_material)
     test_plan_data = self.create_completed_testplan(
         material_type=new_material['name'],
         formatted_article=formatted_article)
     created_data = {
         'test_plan': test_plan_data['testPlanEntity']['name'],
         'test_unit': test_plan_data['specifications'][0]['name'],
         'material_type': new_material['name'],
         'article': formatted_article['name']
     }
     return created_data
Ejemplo n.º 9
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
class OrdersWithoutArticleTestCases(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.contacts_api = ContactsAPI()
        self.test_unit_api = TestUnitAPI()
        self.test_plan_api = TestPlanAPI()
        self.general_utilities = GeneralUtilitiesAPI()
        self.set_authorization(auth=BaseAPI().AUTHORIZATION_RESPONSE)
        self.test_unit_api.set_name_configuration_name_only()
        self.orders_api.set_configuration()
        self.header_page = Header()
        article_enabled = self.general_utilities.is_article_enabled()
        if article_enabled:
            self.info('go to Modules Configurations')
            self.header_page.get_modules_config_page()
            self.header_page.disable_article_option()
        self.header_page.sleep_tiny()
        self.order_page.get_orders_page()

    def tearDown(self):
        article_enabled = self.general_utilities.is_article_enabled()
        if not article_enabled:
            self.header_page.get_modules_config_page()
            self.header_page.disable_article_option()
        return super().tearDown()

    @attr(series=True)
    def test001_create_order_without_article(self):
        """
        orders without articles: check that user can create order without article

        LIMS-3253
        """
        created_testplan = TestPlanAPI().create_completed_testplan_random_data(
        )
        self.assertTrue(created_testplan)
        formatted_material = created_testplan['materialType'][0]
        created_testunit = self.test_unit_api.create_qualitative_testunit(
            selectedMaterialTypes=[formatted_material])
        self.info(
            'asserting article is not found in orders active table configuration'
        )
        child_table_header = self.orders_page.navigate_to_child_table_configuration(
        )
        self.assertNotIn('Article Name', child_table_header)
        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_headers = [h.text for h in header_row]
        self.info('asserting article is not displayed in orders table')
        self.assertNotIn('Article Name', displayed_headers)
        order_no, testunits, testplans = self.suborder_table.create_new_order(
            material_type=formatted_material['text'],
            test_plans=[created_testplan['testPlan']['text']],
            test_units=[created_testunit[1]['name']],
            article=None,
            check_testunits_testplans=True)

        self.info('asserting article field is not displayed in new order page')
        fields = self.base_selenium.get_table_head_elements(
            element='order:suborder_table')
        fields_text = [f.text for f in fields]
        self.assertNotIn('Article: *', fields_text)

        self.info(
            'asserting All displayed testunits are loaded correctly according to '
            'selected material type {}'.format(formatted_material['text']))
        testunit_materials = self.test_unit_api.get_testunits_material_types(
            testunits)
        self.assertTrue(
            all(material in ['All', formatted_material['text']]
                for material in testunit_materials))
        self.info(
            'asserting All displayed testplans are loaded correctly according to '
            'selected material type {}'.format(formatted_material['text']))
        testplan_materials = self.test_plan_api.get_testplans_matches_material_types(
            testplans=testplans, material_type=formatted_material['text'])
        self.assertTrue(
            all(material in [formatted_material['text']]
                for material in testplan_materials))
        self.order_page.sleep_tiny()
        self.order_page.get_orders_page()
        self.order_page.sleep_tiny()
        self.order_page.filter_by_order_no(filter_text=order_no)
        latest_order_data = \
            self.base_selenium.get_row_cells_dict_related_to_header(row=self.order_page.result_table()[0])
        self.info('asserting the order is successfully created')
        self.assertEqual(order_no.replace("'", ""),
                         latest_order_data['Order No.'].replace("'", ""))

    @attr(series=True)
    def test002_create__order_from_existing_order_without_article(self):
        """
         Orders without articles: when creating a new order from existing order,
         all data should be loaded, without article

         LIMS-3254
        """
        created_testplan = TestPlanAPI().create_completed_testplan_random_data(
        )
        self.assertTrue(created_testplan)
        formatted_material = created_testplan['materialType'][0]
        created_testunit = self.test_unit_api.create_qualitative_testunit(
            selectedMaterialTypes=[formatted_material])
        material_type = formatted_material['text']
        self.info('create order from an existing one')
        self.orders_page.sleep_tiny()
        order_no = self.order_page.create_existing_order_with_auto_fill()
        self.assertFalse(
            self.base_selenium.check_element_is_exist(element='order:article'))
        self.info('switch to material type {}'.format(material_type))
        self.suborder_table.set_material_type(material_type=material_type)
        self.assertEqual(
            self.base_selenium.get_value(element='order:test_unit'), None)
        self.assertEqual(
            self.base_selenium.get_value(element='order:test_plan'), None)
        testunits = self.base_selenium.get_drop_down_suggestion_list(
            element='order:test_unit', item_text=' ')
        _testplans = self.base_selenium.get_drop_down_suggestion_list(
            element='order:test_plan', item_text=' ')

        testplans = list(set(_testplans) - set(testunits))
        self.info(
            'asserting All displayed testunits are loaded correctly according to '
            'selected material type {}'.format(material_type))
        testunit_materials = self.test_unit_api.get_testunits_material_types(
            testunits)
        self.assertTrue(
            all(material in ['All', material_type]
                for material in testunit_materials))

        self.info(
            'asserting All displayed testplans are loaded correctly according to '
            'selected material type {}'.format(material_type))
        testplan_materials = self.test_plan_api.get_testplans_matches_material_types(
            testplans=testplans, material_type=material_type)
        self.assertTrue(
            all(material in [material_type]
                for material in testplan_materials))

        self.suborder_table.set_test_units(
            test_units=[created_testunit[1]['name']])
        self.suborder_table.set_test_plans(
            test_plans=[created_testplan['testPlan']['text']])
        self.order_page.save(save_btn='order:save_btn')
        self.info('assert order is created successfully')
        self.orders_page.get_orders_page()
        self.orders_page.filter_by_order_no(filter_text=order_no)
        results = self.order_page.result_table()[0].text
        self.assertIn(order_no.replace("'", ""), results.replace("'", ""))