コード例 #1
0
    def test_api_get_product_detail_endpoint(self):
        # run multiple times to verify sorting of the list names
        counter = 1
        while counter <= 3:
            apicall = {
                "product_id": self.TEST_PRODUCT_NAME
            }
            # id field omitted, because it may change depending on the database
            expected_list_names = [
                "Cisco Systems",
                "Cisco Catalyst 2960X",
            ]
            expected_list_names.sort()
            expected_result = {
                "product_id": "WS-C2960X-24PD-L",
                "description": "Catalyst 2960-X 24 GigE PoE 370W, 2 x 10G SFP+, LAN Base",
                "list_price": "4595.00",
                "currency": "USD",
                "tags": "chassis",
                "json_data": None,
                "lists": expected_list_names
            }

            response = rest_calls.post_rest_call(api_url=self.PRODUCT_BY_NAME_API_URL,
                                                 data_dict=apicall,
                                                 username=self.API_USERNAME,
                                                 password=self.API_PASSWORD)

            self.assertEqual(response.status_code,
                             status.HTTP_200_OK,
                             "Failed call: %s" % response.content.decode("utf-8"))

            response_json = json.loads(response.content.decode("utf-8"))

            modified_response = extract_dict_a_from_b(expected_result, response_json)
            self.assertSetEqual(set(expected_result), set(modified_response))
            counter += 1
コード例 #2
0
    def test_valid_import_product_import_using_the_bundled_excel_template(self):
        # go to the import products page
        self.browser.get(self.server_url + "/productdb/import/products/")
        self.browser.implicitly_wait(3)

        # handle the login dialog
        self.handle_login_dialog(self.ADMIN_USERNAME, self.ADMIN_PASSWORD, "Import products")

        # add test excel file to dialog and submit the file
        test_excel_file = os.path.join(os.getcwd(), "tests", "data", "excel_import_products_test.xlsx")
        self.handle_upload_dialog(test_excel_file)

        # the process is not works not asynchron, therefore it takes some time before the results are displayed
        self.browser.implicitly_wait(15)

        # verify the output of the upload dialog
        expected_title = "You have imported 25 valid products and 0 invalid products."
        expected_contents = [
            "created product WS-C2960S-48FPD-L",
            "created product WS-C2960S-48LPD-L",
            "created product WS-C2960S-24PD-L",
            "created product WS-C2960S-48TD-L",
        ]
        page_content = self.browser.find_element_by_tag_name("body").text
        self.assertIn(expected_title, page_content)
        for c in expected_contents:
            self.assertIn(c, page_content)
        time.sleep(10)

        # verify the import partially using the API
        parts = [
            {
                "id": "WS-C2960S-48TS-S",
                "expect": [
                    ("product_id", "WS-C2960S-48TS-S"),
                    ("description", "Catalyst 2960S 48 GigE, 2 x SFP LAN Lite"),
                    ("list_price", '3735.00'),
                    ("currency", "USD"),
                    ("vendor", 1),
                ]
            },
            {
                "id": "EX4200-24F-DC",
                "expect": [
                    ("product_id", "EX4200-24F-DC"),
                    ("description", "EX 4200, 24-port  1000BaseX  SFP + 190W DC PS  (optics sold separately), "
                                    "includes 50cm VC cable"),
                    ("list_price", '16300.00'),
                    ("currency", "USD"),
                    ("vendor", 2),
                ]
            }
        ]
        required_keys = ['product_id', 'description', 'list_price', 'currency', 'vendor']
        for part in parts:
            apicall = {
                "product_id": part['id']
            }
            # id field omitted, because it may change depending on the database
            response = rest_calls.post_rest_call(api_url=self.PRODUCT_BY_NAME_API_URL,
                                                 data_dict=apicall,
                                                 username=self.ADMIN_USERNAME,
                                                 password=self.ADMIN_PASSWORD)

            self.assertEqual(response.status_code,
                             status.HTTP_200_OK,
                             "Failed call: %s" % response.content.decode("utf-8"))

            response_json = json.loads(response.content.decode("utf-8"))

            modified_response = [(k, response_json[k]) for k in required_keys if k in response_json.keys()]
            print(part['expect'])
            for s in part['expect']:
                self.assertIn(s, set(modified_response))