def request_entitlement(self, identity, cert_length_in_min=None): """ Will request an entitlement certificate for all engineering_ids associated to this 'identity'. @param identity: the identity requesting an entitlement certificate @type identity: checkin_service.entitlement.models.ConsumerIdentity @param cert_length_in_min: optional param, if specified will ask candlepin for a cert that will live for this many minutes @type cert_length_in_min: int @return: Certificate and the time it took for entitlement server to process the call @rtype: str, int """ cp_config = config.get_entitlement_config_info() start_date=None end_date=None if cert_length_in_min: start_date = datetime.now(tz=pytz.utc) end_date = start_date + timedelta(minutes=cert_length_in_min) start_date = start_date.isoformat() end_date = end_date.isoformat() _LOG.info("Request entitlement certificate from external service: %s:%s%s for RHIC <%s> with products <%s>" %\ (cp_config["host"], cp_config["port"], cp_config["url"], identity.uuid, identity.engineering_ids)) start_time = time.time() cert_info = candlepin_client.get_entitlement( host=cp_config["host"], port=cp_config["port"], url=cp_config["url"], requested_products=identity.engineering_ids, identity=str(identity.uuid), username=cp_config["username"], password=cp_config["password"], start_date=start_date, end_date=end_date) end_time = time.time() return cert_info, end_time - start_time
def test_get_entitlement(self): cert_info = candlepin_client.get_entitlement( host="localhost", port=0, url="mocked", requested_products=[4], identity="dummy identity", username="", password="", ) self.assertEquals(len(cert_info), 1) self.assertEquals(cert_info[0][0], self.expected_cert) self.assertEquals(cert_info[0][1], self.expected_key)