def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {
         self.refresh_route:
         exceptions.UserFacingError("Machine token refresh fail")
     }
     return fake_client
Exemplo n.º 2
0
    def test_user_facing_error_due_to_unexpected_process_entitlement_delta(
        self,
        client,
        get_machine_id,
        process_entitlement_delta,
        first_error,
        second_error,
        ux_error_msg,
        FakeConfig,
    ):
        """Unexpected errors from process_entitlement_delta are raised.

        Remaining entitlements are processed regardless of error and error is
        raised at the end.

        Unexpected exceptions take priority over the handled UserFacingErrors.
        """
        # Fail first and succeed second call to process_entitlement_delta
        process_entitlement_delta.side_effect = (
            first_error,
            second_error,
            None,
        )

        # resourceEntitlements specifically ordered reverse alphabetically
        # to ensure proper sorting for process_contract_delta calls below
        machine_token = {
            "machineToken": "mToken",
            "machineTokenInfo": {
                "contractInfo": {
                    "id": "cid",
                    "resourceEntitlements": [
                        {"entitled": False, "type": "ent3"},
                        {"entitled": False, "type": "ent2"},
                        {"entitled": True, "type": "ent1"},
                    ],
                }
            },
        }

        cfg = FakeConfig.for_attached_machine(machine_token=machine_token)
        fake_client = FakeContractClient(cfg)
        fake_client._responses = {
            self.refresh_route: machine_token,
            self.access_route_ent1: {
                "entitlement": {
                    "entitled": True,
                    "type": "ent1",
                    "new": "newval",
                }
            },
        }

        client.return_value = fake_client
        with pytest.raises(exceptions.UserFacingError) as exc:
            assert None is request_updated_contract(cfg)
        assert 3 == process_entitlement_delta.call_count
        assert ux_error_msg == str(exc.value)
Exemplo n.º 3
0
 def fake_contract_client(cfg):
     client = FakeContractClient(cfg)
     # Note ent2 access route is not called
     client._responses = {
         refresh_route: machine_token,
         access_route_ent1: {
             'entitlement': {
                 'entitled': True, 'type': 'ent1', 'new': 'newval'}}}
     return client
 def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {
         self.refresh_route:
         machine_token,
         self.access_route_ent1:
         exceptions.UserFacingError("Broken ent1 route"),
         self.access_route_ent2:
         exceptions.UserFacingError("Broken ent2 route"),
     }
     return fake_client
Exemplo n.º 5
0
 def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {
         API_V1_CONTEXT_MACHINE_TOKEN: ContractAPIError(
             util.UrlError(
                 "Server error", code=500, url="http://me", headers={}
             ),
             error_response={
                 "message": "invalid token: checksum error"
             },
         )
     }
     return fake_client
Exemplo n.º 6
0
 def fake_contract_client(cfg):
     client = FakeContractClient(cfg)
     # Note ent2 access route is not called
     client._responses = {
         self.refresh_route: machine_token,
         self.access_route_ent1: {
             "entitlement": {
                 "entitled": True,
                 "type": "ent1",
                 "new": "newval",
             }
         },
     }
     return client
 def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {
         API_V1_CONTEXT_MACHINE_TOKEN: ContractAPIError(
             util.UrlError(
                 "Server error",
                 code=error_code,
                 url="http://me",
                 headers={},
             ),
             error_response={"message": "unauthorized"},
         )
     }
     return fake_client
 def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {
         API_V1_CONTEXT_MACHINE_TOKEN:
         exceptions.ContractAPIError(
             exceptions.UrlError(
                 "Server error",
                 code=error_code,
                 url="http://me",
                 headers={},
             ),
             error_response=json.loads(
                 error_response, cls=util.DatetimeAwareJSONDecoder),
         )
     }
     return fake_client
 def fake_contract_client(cfg):
     client = FakeContractClient(cfg)
     client._responses = {self.refresh_route: new_token}
     return client
 def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {self.refresh_route: machine_token}
     return fake_client
        def fake_contract_client(cfg):
            fake_client = FakeContractClient(cfg)
            fake_client._responses = {url: information}

            return fake_client
 def fake_contract_client(cfg):
     fake_client = FakeContractClient(cfg)
     fake_client._responses = {url: {"resources": new_resources}}
     return fake_client