Exemple #1
0
def test_delete(client, card_sample: dict):
    card_sample["number_token"] = client.generate_token_card(
        "5155901222280001", "getnet-py")
    service = Service(client)

    created_card = service.create(Card(**card_sample))
    card = service.get(created_card.card_id)

    resp = service.delete(card.card_id)
    assert True == resp
Exemple #2
0
def test_get(client, card_sample: dict):
    card_sample["number_token"] = client.generate_token_card(
        "5155901222280001", "getnet-py")
    service = Service(client)
    sample_card = service.create(Card(**card_sample))

    card = service.get(sample_card.card_id)

    assert isinstance(card, Card)
    assert sample_card.card_id == card.card_id
Exemple #3
0
    def testCreate(self, client_mock):
        client_mock.post.return_value = {
            "card_id": "e8ad2ae4-9e3e-4532-998f-1a5a11e56e58",
            "number_token": "123",
        }

        service = Service(client_mock)
        card = service.create(Card(**sample))

        self.assertIsInstance(card, NewCardResponse)
        self.assertEqual("e8ad2ae4-9e3e-4532-998f-1a5a11e56e58",
                         str(card.card_id))
        self.assertEqual("123", card.number_token)
class CardsIntegrationTest(VCRTestCase):
    def setUp(self) -> None:
        super(CardsIntegrationTest, self).setUp()
        self.client = getnet.Client(
            os.environ.get("GETNET_SELLER_ID"),
            os.environ.get("GETNET_CLIENT_ID"),
            os.environ.get("GETNET_CLIENT_SECRET"),
            getnet.api.HOMOLOG,
        )
        self.number_token = self.client.generate_token_card(
            "5155901222280001", "customer_01")
        self.service = Service(self.client)

    def testCreate(self):
        data = sample.copy()
        data["number_token"] = self.number_token
        card = self.service.create(Card(**data))

        self.assertIsInstance(card, NewCardResponse)
        self.assertEqual(self.number_token, card.number_token.number_token)

    def testInvalidCreate(self):
        with self.assertRaises(getnet.exceptions.BadRequest) as err:
            data = sample.copy()
            data["number_token"] = "123"
            self.service.create(Card(**data))

        self.assertEqual("TOKENIZATION-400", err.exception.error_code)

    def testGet(self):
        data = sample.copy()
        data["number_token"] = self.number_token
        sample_card = self.service.create(Card(**data))

        card = self.service.get(sample_card.card_id)

        self.assertIsInstance(card, Card)
        self.assertEqual(card, card)
        self.assertEqual(sample_card.card_id, card.card_id)

    def testInvalidGet(self):
        with self.assertRaises(getnet.exceptions.NotFound) as err:
            self.service.get("14a2ce5d-ebc3-49dc-a516-cb5239b02285")

        self.assertEqual("404", err.exception.error_code)

    def testAll(self):
        with self.assertRaises(TypeError):
            cards = self.service.all()

        cards = self.service.all(sample.get("customer_id"))
        self.assertIsInstance(cards, ResponseList)
        self.assertIsNone(cards.page)
        self.assertIsNone(cards.limit)
        self.assertIsNotNone(cards.total)

    def testAll404(self):
        with self.assertRaises(NotFound) as err:
            cards = self.service.all("foobar")

        self.assertEqual("404", err.exception.error_code)

    def testDelete(self):
        data = sample.copy()
        data["number_token"] = self.client.generate_token_card(
            "5155901222280001", "customer_01")

        created_card = self.service.create(Card(**data))
        card = self.service.get(created_card.card_id)

        resp = self.service.delete(card.card_id)
        self.assertTrue(resp)

    def testDelete404(self):
        with self.assertRaises(NotFound) as err:
            cards = self.service.delete("72402c54-6bd3-4895-a6b4-adfded0c11dc")

        self.assertEqual("VAULT-404", err.exception.error_code)