def testCreate(self, client_mock): client_mock.post.return_value = self.sample service = Service(client_mock) customer = service.create(Customer(**sample)) self.assertIsInstance(customer, Customer) self.assertEqual(sample.get("customer_id"), customer.customer_id)
def test_create(client_mock: Client, customer_sample: dict, customer_response_sample: dict): client_mock.post.return_value = customer_response_sample service = Service(client_mock) customer = service.create(Customer(**customer_sample)) assert isinstance(customer, Customer) assert customer_sample.get("customer_id") == customer.customer_id
def setUp(self) -> None: super(CustomersIntegrationTest, 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.service = Service(self.client)
def test_get(client_mock: Client, customer_response_sample: dict): client_mock.get.return_value = customer_response_sample service = Service(client_mock) customer = service.get(customer_response_sample.get("customer_id")) assert isinstance(customer, Customer) assert customer_response_sample.get("customer_id") == customer.customer_id client_mock.get.assert_called_once_with("/v1/customers/{}".format( customer_response_sample.get("customer_id")))
def testGet(self, client_mock): client_mock.get.return_value = self.sample service = Service(client_mock) customer = service.get(sample.get("customer_id")) self.assertIsInstance(customer, Customer) self.assertEqual(sample.get("customer_id"), customer.customer_id) client_mock.get.assert_called_once_with( "/v1/customers/{}".format(sample.get("customer_id")) )
def test_get(client: Client, customer_sample: dict): customer_sample["customer_id"] = "test_integration_get" customer_sample["document_number"] = "01234567811" service = Service(client) created_customer = service.create(Customer(**customer_sample)) customer = service.get(created_customer.customer_id) assert isinstance(customer, Customer) assert created_customer == customer assert created_customer.customer_id == customer.customer_id
def testAll(self, client_mock): client_mock.get.return_value = { "customers": [self.sample, self.sample, self.sample], "page": 1, "limit": 100, "total": 3, } service = Service(client_mock) customers = service.all() self.assertIsInstance(customers, ResponseList) self.assertEqual(1, customers.page) self.assertEqual(3, customers.total) self.assertEqual(sample.get("customer_id"), customers[0].customer_id)
class CustomersIntegrationTest(VCRTestCase): def setUp(self) -> None: super(CustomersIntegrationTest, 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.service = Service(self.client) def testCreate(self): data = sample.copy() data["document_number"] = "01234567888" customer = self.service.create(Customer(**data)) self.assertIsInstance(customer, Customer) self.assertEqual(data.get("customer_id"), customer.customer_id) def testInvalidCreate(self): with self.assertRaises(getnet.BadRequest) as err: self.service.create(Customer(**sample)) self.assertEqual("Bad Request", err.exception.error_code) def testGet(self): data = sample.copy() data["customer_id"] = "test_integration_get" data["document_number"] = "01234567811" created_customer = self.service.create(Customer(**data)) customer = self.service.get(created_customer.customer_id) self.assertIsInstance(customer, Customer) self.assertEqual(created_customer, customer) self.assertEqual(created_customer.customer_id, customer.customer_id) def testInvalidGet(self): with self.assertRaises(NotFound) as err: self.service.get("14a2ce5d-ebc3-49dc-a516-cb5239b02285") self.assertEqual("Not Found", err.exception.error_code) def testAll(self): customers = self.service.all() self.assertIsInstance(customers, ResponseList) self.assertEqual(1, customers.page) self.assertEqual(100, customers.limit) self.assertIsNotNone(customers.total) def testAllNotFound(self): cards = self.service.all(document_number="01234567855") self.assertEqual(0, cards.total)
def test_create(client: Client, customer_sample: dict): customer_sample["document_number"] = "01234567888" customer = Service(client).create(Customer(**customer_sample)) assert isinstance(customer, Customer) assert customer_sample.get("customer_id"), customer.customer_id
def test_all(client_mock: Client, customer_response_sample: dict): client_mock.get.return_value = { "customers": [ customer_response_sample, customer_response_sample, customer_response_sample, ], "page": 1, "limit": 100, "total": 3, } service = Service(client_mock) customers = service.all() assert isinstance(customers, ResponseList) assert 1 == customers.page assert 3 == customers.total assert customer_response_sample.get( "customer_id") == customers[0].customer_id
def test_all_not_found(client): cards = Service(client).all(document_number="01234567855") assert 0 == cards.total
def test_all(client): customers = Service(client).all() assert isinstance(customers, ResponseList) assert 1 == customers.page assert 100 == customers.limit assert customers.total is not None
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
def test_create_return_if_already_exists(client: Client, customer_sample: dict): customer = Service(client).create(Customer(**customer_sample), True) assert isinstance(customer, Customer) assert customer_sample.get("customer_id"), customer.customer_id
def test_invalid_create(client: Client, customer_sample: dict): with pytest.raises(BadRequest) as excinfo: Service(client).create(Customer(**customer_sample), False) assert "400" == excinfo.value.error_code