Ejemplo n.º 1
0
def test_create(client_mock, plan_sample, plan_response_sample):
    client_mock.post.return_value = plan_response_sample

    service = Service(client_mock)
    plan = service.create(Plan(**plan_sample))

    assert isinstance(plan, Plan)
    assert plan_response_sample.get("plan_id") == str(plan.plan_id)
Ejemplo n.º 2
0
def test_get(client, plan_sample):
    created_plan = Service(client).create(Plan(**plan_sample))

    plan = Service(client).get(created_plan.plan_id)

    assert isinstance(plan, Plan)
    assert created_plan == plan
    assert created_plan.plan_id == plan.plan_id
Ejemplo n.º 3
0
    def testCreate(self, client_mock):
        client_mock.post.return_value = response_sample

        service = Service(client_mock)
        plan = service.create(Plan(**sample))

        self.assertIsInstance(plan, Plan)
        self.assertEqual(response_sample.get("plan_id"), str(plan.plan_id))
Ejemplo n.º 4
0
 def setUp(self) -> None:
     super(PlansIntegrationTest, 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.client.HOMOLOG,
     )
     self.service = Service(self.client)
Ejemplo n.º 5
0
    def testUpdateStatus(self, client_mock):
        client_mock.patch.return_value = response_sample

        service = Service(client_mock)
        plan = service.update_status(response_sample.get("plan_id"), False)

        client_mock.patch.assert_called_once_with(
            "/v1/plans/{}/status/inactive".format(response_sample.get("plan_id")),
        )
Ejemplo n.º 6
0
def test_update_status(client_mock, plan_response_sample):
    client_mock.patch.return_value = plan_response_sample

    service = Service(client_mock)
    _ = service.update_status(plan_response_sample.get("plan_id"), False)

    client_mock.patch.assert_called_once_with(
        "/v1/plans/{}/status/inactive".format(plan_response_sample.get("plan_id")),
    )
Ejemplo n.º 7
0
    def testUpdate(self, client_mock):
        client_mock.patch.return_value = response_sample

        service = Service(client_mock)
        plan = service.update(response_sample.get("plan_id"), "Demo", "Demo Desc")

        client_mock.patch.assert_called_once_with(
            "/v1/plans/{}".format(response_sample.get("plan_id")),
            json={"name": "Demo", "description": "Demo Desc"},
        )
Ejemplo n.º 8
0
    def testGet(self, client_mock):
        client_mock.get.return_value = response_sample

        service = Service(client_mock)
        plan = service.get(response_sample.get("plan_id"))

        self.assertIsInstance(plan, PlanResponse)
        self.assertEqual(response_sample.get("plan_id"), str(plan.plan_id))
        client_mock.get.assert_called_once_with(
            "/v1/plans/{}".format(response_sample.get("plan_id"))
        )
Ejemplo n.º 9
0
def test_get(client_mock, plan_response_sample):
    client_mock.get.return_value = plan_response_sample

    service = Service(client_mock)
    plan = service.get(plan_response_sample.get("plan_id"))

    assert isinstance(plan, PlanResponse)
    assert plan_response_sample.get("plan_id") == str(plan.plan_id)
    client_mock.get.assert_called_once_with(
        "/v1/plans/{}".format(plan_response_sample.get("plan_id"))
    )
Ejemplo n.º 10
0
    def testAll(self, client_mock):
        client_mock.get.return_value = {
            "plans": [response_sample, response_sample, response_sample],
            "page": 1,
            "limit": 100,
            "total": 3,
        }

        service = Service(client_mock)
        plans = service.all()

        self.assertIsInstance(plans, ResponseList)
        self.assertEqual(1, plans.page)
        self.assertEqual(3, plans.total)
        self.assertEqual(response_sample.get("plan_id"), str(plans[0].plan_id))
Ejemplo n.º 11
0
def test_all(client_mock, plan_response_sample):
    client_mock.get.return_value = {
        "plans": [plan_response_sample, plan_response_sample, plan_response_sample],
        "page": 1,
        "limit": 100,
        "total": 3,
    }

    service = Service(client_mock)
    plans = service.all()

    assert isinstance(plans, ResponseList)
    assert 1 == plans.page
    assert 3 == plans.total
    assert plan_response_sample.get("plan_id") == str(plans[0].plan_id)
Ejemplo n.º 12
0
def test_all(client):
    plans = Service(client).all()

    assert isinstance(plans, ResponseList)
    assert plans.page == 1
    assert plans.limit == 100
    assert plans.total is not None
Ejemplo n.º 13
0
def test_update(client, plan_sample):
    created_plan = Service(client).create(Plan(**plan_sample))

    plan1 = Service(client).update(created_plan.plan_id, "FooBar #1",
                                   created_plan.description)
    assert plan1.name == "FooBar #1"

    plan2 = Service(client).update(created_plan, "FooBar #2")
    assert plan2.name == "FooBar #2"

    created_plan.name = "FooBar #3"
    plan3 = Service(client).update(created_plan)
    assert plan3.name == "FooBar #3"
Ejemplo n.º 14
0
class PlansIntegrationTest(VCRTestCase):
    def setUp(self) -> None:
        super(PlansIntegrationTest, 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.client.HOMOLOG,
        )
        self.service = Service(self.client)

    def testCreate(self):
        data = sample.copy()

        plan = self.service.create(Plan(**data))
        self.assertIsInstance(plan, Plan)
        self.assertIsNotNone(plan.plan_id)

    def testGet(self):
        data = sample.copy()
        created_plan = self.service.create(Plan(**data))

        plan = self.service.get(created_plan.plan_id)

        self.assertIsInstance(plan, Plan)
        self.assertEqual(created_plan, plan)
        self.assertEqual(created_plan.plan_id, plan.plan_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):
        plans = self.service.all()
        self.assertIsInstance(plans, ResponseList)
        self.assertEqual(1, plans.page)
        self.assertEqual(100, plans.limit)
        self.assertIsNotNone(plans.total)

    def testAllNotFound(self):
        plans = self.service.all(name="foobarTest123")
        self.assertEqual(0, plans.total)

    def testUpdate(self):
        data = sample.copy()
        created_plan = self.service.create(Plan(**data))

        plan1 = self.service.update(created_plan.plan_id, "FooBar #1",
                                    created_plan.description)
        self.assertEqual("FooBar #1", plan1.name)

        plan2 = self.service.update(created_plan, "FooBar #2")
        self.assertEqual("FooBar #2", plan2.name)

        created_plan.name = "FooBar #3"
        plan3 = self.service.update(created_plan)
        self.assertEqual("FooBar #3", plan3.name)

    def testUpdateStatus(self):
        data = sample.copy()
        created_plan = self.service.create(Plan(**data))
        self.assertTrue(created_plan.is_active)

        plan = self.service.update_status(created_plan.plan_id, False)
        self.assertFalse(plan.is_active)
Ejemplo n.º 15
0
def test_invalid_get(client):
    with pytest.raises(NotFound) as excinfo:
        Service(client).get("14a2ce5d-ebc3-49dc-a516-cb5239b02285")

    assert excinfo.value.error_code == "404"
Ejemplo n.º 16
0
def test_create(client, plan_sample):
    plan = Service(client).create(Plan(**plan_sample))
    assert isinstance(plan, Plan)
    assert plan.plan_id is not None
Ejemplo n.º 17
0
def test_update_status(client, plan_sample):
    created_plan = Service(client).create(Plan(**plan_sample))
    assert created_plan.is_active is True

    plan = Service(client).update_status(created_plan.plan_id, False)
    assert plan.is_active is False
Ejemplo n.º 18
0
def test_all_not_found(client):
    plans = Service(client).all(name="foobarTest123")
    assert plans.total == 0