def testAsDict(self): data = sample.copy() card = CardResponse(**data) value = card.as_dict() self.assertNotIn("used_at", value) self.assertNotIn("created_at", value) self.assertNotIn("updated_at", value)
def all(self, customer_id: str, status: Status = Status.ALL) -> List[CardResponse]: """Return an list of cards saved on safe for customer_id Args: customer_id (str): customer identify status: Filter of status of returned cards. Default to "all" """ if status and not status in Status: raise AttributeError("Invalid status.") params = {"status": status} if customer_id is not None: params.update({"customer_id": customer_id}) response = self._get(self._format_url(), params=params) cards = [] for card in response.get("cards"): cards.append(CardResponse(**card)) return ResponseList( cards, response.get("page", None), response.get("limit", None), response.get("total", len(cards)), )
def get(self, card_id: Union[CardToken, uuid.UUID, str]) -> CardResponse: """Return the data of an saved card on the safe Args: card_id: Unique card identify on Getnet Plataform """ response = self._get(self._format_url(card_id=str(card_id))) return CardResponse(**response)
def get(self, card_id: Union[CardToken, uuid.UUID, str], **kwargs) -> CardResponse: """Return the data of an saved card on the safe Args: card_id: Unique card identify on Getnet Plataform """ response = self._get(self._format_url(card_id=str(card_id))) if "callback" in kwargs.keys(): kwargs["callback"]( None, response, self._format_url(card_id=str(card_id))) return CardResponse(**response)
def all(self, customer_id: str, status: str = "all") -> List[CardResponse]: if status and not status in CARD_STATUS: raise AttributeError("Status invalid.") params = {"status": status} if customer_id is not None: params.update({"customer_id": customer_id}) response = self._get(self._format_url(), params=params) cards = [] for card in response.get("cards"): cards.append(CardResponse(**card)) return ResponseList( cards, response.get("page", None), response.get("limit", None), response.get("total", len(cards)), )
def testInvalidInitWithoutCardId(self): with self.assertRaises(TypeError): data = sample.copy() data.pop("card_id") CardResponse(**data)
def __init__(self, card: Union[CardResponse, dict], **kwargs): card.update({"customer_id": "", "number_token": ""}) card = (card if isinstance(card, CardResponse) or card is None else CardResponse(**card)) kwargs["card"] = card
def get(self, card_id: Union[CardToken, uuid.UUID, str]) -> CardResponse: response = self._get(self._format_url(card_id=str(card_id))) return CardResponse(**response)
def test_invalid_without_card_id(card_response_sample: dict): with pytest.raises(TypeError): card_response_sample.pop("card_id") CardResponse(**card_response_sample)
def testAsDict(card_response_sample: dict): card = CardResponse(**card_response_sample) value = card._as_dict() assert "used_at" not in value assert "created_at" not in value assert "updated_at" not in value