Esempio n. 1
0
    def testVerify(self, client_mock):
        client_mock.post.return_value = {"status": "VERIFIED"}

        service = Service(client_mock)
        response = service.verify(Card(**sample))

        self.assertIsInstance(response, bool)
        self.assertTrue(response)
Esempio n. 2
0
    def testDelete(self, client_mock):
        client_mock.delete.return_value = True

        service = Service(client_mock)
        card = service.delete(card_id="123")

        self.assertTrue(card)
        client_mock.delete.assert_called_once_with("/v1/cards/123")
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
0
 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)
Esempio n. 6
0
    def testAll(self, client_mock):
        client_mock.get.return_value = {
            "cards": [response_sample, response_sample, response_sample]
        }

        service = Service(client_mock)
        cards = service.all("client_id")

        self.assertIsInstance(cards, ResponseList)
        self.assertIsNone(cards.page)
        self.assertEqual(3, cards.total)
        self.assertEqual(response_sample.get("card_id"), cards[0].card_id)
Esempio n. 7
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)
Esempio n. 8
0
def test_create(client, card_sample: dict):
    card_sample["number_token"] = client.generate_token_card(
        "5155901222280001", "getnet-py")
    card = Service(client).create(Card(**card_sample))

    assert isinstance(card, NewCardResponse)
    assert card_sample["number_token"] == card.number_token.number_token
Esempio n. 9
0
def test_delete_not_found(client):
    with pytest.raises(NotFound) as excinfo:
        cards = Service(client).delete("72402c54-6bd3-4895-a6b4-adfded0c11dc")

    assert "VAULT-404" == excinfo.value.error_code
Esempio n. 10
0
def test_all_not_found(client):
    with pytest.raises(NotFound) as excinfo:
        Service(client).all("foobar")

    assert "404" == excinfo.value.error_code
Esempio n. 11
0
def test_all(client, card_sample: dict):
    cards = Service(client).all(card_sample.get("customer_id"))
    assert isinstance(cards, ResponseList)
    assert cards.page is None
    assert cards.limit is None
    assert cards.total is not None
Esempio n. 12
0
def test_invalid_get(client):
    with pytest.raises(NotFound) as excinfo:
        Service(client).get("14a2ce5d-ebc3-49dc-a516-cb5239b02285")

    assert "404" == excinfo.value.error_code
Esempio n. 13
0
def test_invalid_create(client, card_sample: dict):
    with pytest.raises(BadRequest) as excinfo:
        card_sample["number_token"] = "123"
        Service(client).create(Card(**card_sample))

    assert "TOKENIZATION-400" == excinfo.value.error_code
Esempio n. 14
0
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)