Beispiel #1
0
    def test_offline_query_product_no_results(self, monkeypatch):
        class MockSession:
            def get(self, *args, **kwargs):
                r = Response()
                r.status_code = 200
                with open("app/ciscoeox/tests/data/cisco_eox_no_result_response.json") as f:
                    r._content = f.read().encode("utf-8")
                return r

        monkeypatch.setattr(requests, "Session", MockSession)

        cisco_eox_api = CiscoEoxApi()
        monkeypatch.setattr(cisco_eox_api, "create_temporary_access_token", lambda force_new_token=True: mock_access_token_generation())

        with pytest.raises(CiscoApiCallFailed):
            cisco_eox_api.query_product("NOTHING", 1)

        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        _ = cisco_eox_api.query_product("NOTHING", 1)

        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0
        assert cisco_eox_api.has_api_error() is True
        assert cisco_eox_api.get_api_error_message() == "EOX information does not exist for the following product " \
                                                        "ID(s): NOTHING (SSA_ERR_026)"
    def test_online_query_product_single_page_results(self):
        cisco_eox_api = CiscoEoxApi()
        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.get_eox_records() == []
        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        jresult = cisco_eox_api.query_product(self.TEST_QUERY, 1)

        assert "EOXRecord" in jresult
        assert "PaginationResponseRecord" in jresult
        assert len(jresult["EOXRecord"]) == 1
        assert cisco_eox_api.get_eox_records() == jresult["EOXRecord"]
        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 1
        assert cisco_eox_api.get_page_record_count() == 1
        assert cisco_eox_api.has_api_error() is False
        assert cisco_eox_api.get_api_error_message() == "no error"
        assert cisco_eox_api.get_error_description(
            jresult["EOXRecord"][0]) == ""
        assert cisco_eox_api.get_error_description(
            jresult["EOXRecord"][0]) == ""
        assert self.EXPECTED_VALID_TEST_QUERY_RESPONSE == jresult
        assert cisco_eox_api.get_eox_records(
        ) == self.EXPECTED_VALID_TEST_QUERY_RESPONSE["EOXRecord"]
    def test_offline_query_product_no_results(self, monkeypatch):
        def mock_response():
            r = Response()
            r.status_code = 200
            with open("app/ciscoeox/tests/data/cisco_eox_no_result_response.json") as f:
                r._content = f.read().encode("utf-8")
            return r

        monkeypatch.setattr(requests, "get", lambda x, headers: mock_response())

        cisco_eox_api = CiscoEoxApi()
        monkeypatch.setattr(cisco_eox_api, "create_temporary_access_token", lambda force_new_token=True: mock_access_token_generation())

        with pytest.raises(CiscoApiCallFailed):
            cisco_eox_api.query_product("NOTHING", 1)

        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        _ = cisco_eox_api.query_product("NOTHING", 1)

        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0
        assert cisco_eox_api.has_api_error() is True
        assert cisco_eox_api.get_api_error_message() == "EOX information does not exist for the following product " \
                                                        "ID(s): NOTHING (SSA_ERR_026)"
Beispiel #4
0
    def test_offline_query_product_multiple_page_results(self, monkeypatch):
        class MockSessionPageOne:
            _first_call = False

            def get(self, *args, **kwargs):
                r = Response()
                r.status_code = 200
                if not self._first_call:
                    with open("app/ciscoeox/tests/data/cisco_eox_response_page_1_of_2.json") as f:
                        r._content = f.read().encode("utf-8")
                    self._first_call = True

                else:
                    with open("app/ciscoeox/tests/data/cisco_eox_response_page_2_of_2.json") as f:
                        r._content = f.read().encode("utf-8")

                return r

        monkeypatch.setattr(requests, "Session", MockSessionPageOne)

        cisco_eox_api = CiscoEoxApi()
        monkeypatch.setattr(cisco_eox_api, "create_temporary_access_token", lambda force_new_token=True: mock_access_token_generation())
        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.get_eox_records() == []
        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        jresult = cisco_eox_api.query_product(self.TEST_QUERY, 1)

        assert "EOXRecord" in jresult
        assert "PaginationResponseRecord" in jresult
        assert len(jresult["EOXRecord"]) == 2
        assert cisco_eox_api.get_eox_records() == jresult["EOXRecord"]
        assert cisco_eox_api.amount_of_pages() == 2
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 3
        assert cisco_eox_api.get_page_record_count() == 2
        assert cisco_eox_api.has_api_error() is False
        assert cisco_eox_api.get_api_error_message() == "no error"
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""

        jresult = cisco_eox_api.query_product(self.TEST_QUERY, 2)

        assert "EOXRecord" in jresult
        assert "PaginationResponseRecord" in jresult
        assert len(jresult["EOXRecord"]) == 1
        assert cisco_eox_api.get_eox_records() == jresult["EOXRecord"]
        assert cisco_eox_api.amount_of_pages() == 2
        assert cisco_eox_api.get_current_page() == 2
        assert cisco_eox_api.amount_of_total_records() == 3
        assert cisco_eox_api.get_page_record_count() == 1
        assert cisco_eox_api.has_api_error() is False
        assert cisco_eox_api.get_api_error_message() == "no error"
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
    def test_offline_query_product_single_page_results(self, monkeypatch):
        def mock_response():
            r = Response()
            r.status_code = 200
            with open("app/ciscoeox/tests/data/cisco_eox_response_page_1_of_1.json") as f:
                r._content = f.read().encode("utf-8")
            return r

        monkeypatch.setattr(requests, "get", lambda x, headers: mock_response())

        cisco_eox_api = CiscoEoxApi()
        monkeypatch.setattr(cisco_eox_api, "create_temporary_access_token", lambda force_new_token=True: mock_access_token_generation())
        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.get_eox_records() == []
        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        jresult = cisco_eox_api.query_product(self.TEST_QUERY, 1)

        assert "EOXRecord" in jresult
        assert "PaginationResponseRecord" in jresult
        assert len(jresult["EOXRecord"]) == 3
        assert cisco_eox_api.get_eox_records() == jresult["EOXRecord"]
        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 3
        assert cisco_eox_api.get_page_record_count() == 3
        assert cisco_eox_api.has_api_error() is False
        assert cisco_eox_api.get_api_error_message() == "no error"
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
    def test_online_query_product_single_page_results(self):
        cisco_eox_api = CiscoEoxApi()
        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.get_eox_records() == []
        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        jresult = cisco_eox_api.query_product(self.TEST_QUERY, 1)

        assert "EOXRecord" in jresult
        assert "PaginationResponseRecord" in jresult
        assert len(jresult["EOXRecord"]) == 1
        assert cisco_eox_api.get_eox_records() == jresult["EOXRecord"]
        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 1
        assert cisco_eox_api.get_page_record_count() == 1
        assert cisco_eox_api.has_api_error() is False
        assert cisco_eox_api.get_api_error_message() == "no error"
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
        assert cisco_eox_api.get_error_description(jresult["EOXRecord"][0]) == ""
        assert self.EXPECTED_VALID_TEST_QUERY_RESPONSE == jresult
        assert cisco_eox_api.get_eox_records() == self.EXPECTED_VALID_TEST_QUERY_RESPONSE["EOXRecord"]
Beispiel #7
0
    def test_offline_query_product_single_page_results(self, monkeypatch):
        def mock_response():
            r = Response()
            r.status_code = 200
            with open(
                    "app/ciscoeox/tests/data/cisco_eox_response_page_1_of_1.json"
            ) as f:
                r._content = f.read().encode("utf-8")
            return r

        monkeypatch.setattr(requests, "get",
                            lambda x, headers: mock_response())

        cisco_eox_api = CiscoEoxApi()
        monkeypatch.setattr(
            cisco_eox_api,
            "create_temporary_access_token",
            lambda force_new_token=True: mock_access_token_generation())
        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.get_eox_records() == []
        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        jresult = cisco_eox_api.query_product(self.TEST_QUERY, 1)

        assert "EOXRecord" in jresult
        assert "PaginationResponseRecord" in jresult
        assert len(jresult["EOXRecord"]) == 3
        assert cisco_eox_api.get_eox_records() == jresult["EOXRecord"]
        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 3
        assert cisco_eox_api.get_page_record_count() == 3
        assert cisco_eox_api.has_api_error() is False
        assert cisco_eox_api.get_api_error_message() == "no error"
        assert cisco_eox_api.get_error_description(
            jresult["EOXRecord"][0]) == ""
        assert cisco_eox_api.get_error_description(
            jresult["EOXRecord"][0]) == ""
    def test_online_query_year(self):
        cisco_eox_api = CiscoEoxApi()

        with pytest.raises(CiscoApiCallFailed):
            cisco_eox_api.query_year(self.TEST_YEAR, 1)

        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        _ = cisco_eox_api.query_year(self.TEST_YEAR, 1)

        assert cisco_eox_api.amount_of_pages() == 14
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() >= 13203
        assert cisco_eox_api.get_page_record_count() == 1000
        assert cisco_eox_api.has_api_error() is False
Beispiel #9
0
    def test_online_query_year(self):
        cisco_eox_api = CiscoEoxApi()

        with pytest.raises(CiscoApiCallFailed):
            cisco_eox_api.query_year(self.TEST_YEAR, 1)

        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        _ = cisco_eox_api.query_year(self.TEST_YEAR, 1)

        # the response for the year is not stable over time, so just check that something was provided
        assert cisco_eox_api.amount_of_pages() > 2
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() >= 1001
        assert cisco_eox_api.get_page_record_count() == 1000
        assert cisco_eox_api.has_api_error() is False
    def test_online_query_product_no_results(self):
        cisco_eox_api = CiscoEoxApi()

        with pytest.raises(CiscoApiCallFailed):
            cisco_eox_api.query_product("NOTHING", 1)

        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        _ = cisco_eox_api.query_product("NOTHING", 1)

        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0
        assert cisco_eox_api.has_api_error() is True
        assert cisco_eox_api.get_api_error_message() == "EOX information does not exist for the following product " \
                                                        "ID(s): NOTHING (SSA_ERR_026)"
    def test_online_query_product_no_results(self):
        cisco_eox_api = CiscoEoxApi()

        with pytest.raises(CiscoApiCallFailed):
            cisco_eox_api.query_product("NOTHING", 1)

        cisco_eox_api.load_client_credentials()
        cisco_eox_api.create_temporary_access_token()

        assert cisco_eox_api.amount_of_pages() == 0
        assert cisco_eox_api.get_current_page() == 0
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0

        _ = cisco_eox_api.query_product("NOTHING", 1)

        assert cisco_eox_api.amount_of_pages() == 1
        assert cisco_eox_api.get_current_page() == 1
        assert cisco_eox_api.amount_of_total_records() == 0
        assert cisco_eox_api.get_page_record_count() == 0
        assert cisco_eox_api.has_api_error() is True
        assert cisco_eox_api.get_api_error_message() == "EOX information does not exist for the following product " \
                                                        "ID(s): NOTHING (SSA_ERR_026)"