コード例 #1
0
    def test_upcoming_by_subscription_success(self):
        self.preview_invoice_mock.side_effect = [APIError("message"), self.invoice]

        invoice = vendor.retrieve_stripe_invoice_upcoming_by_subscription(
            customer_id="cust_123", subscription_id="sub_123"
        )
        assert invoice == self.invoice  # nosec
コード例 #2
0
    def test_cancel_immediately_error(self):
        self.mock_delete_subscription.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.cancel_stripe_subscription_immediately(
                subscription_id="sub_123", idempotency_key=utils.get_indempotency_key()
            )
コード例 #3
0
    def test_cancel_at_end_error(self):
        self.mock_modify_subscription.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.cancel_stripe_subscription_period_end(
                subscription_id="sub_123", idempotency_key=utils.get_indempotency_key()
            )
コード例 #4
0
    def test_reactivate_error(self):
        self.mock_modify_subscription.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.reactivate_stripe_subscription(
                subscription_id="sub_123", idempotency_key=utils.get_indempotency_key()
            )
コード例 #5
0
    def test_upcoming_by_subscription_error(self):
        self.preview_invoice_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.retrieve_stripe_invoice_upcoming_by_subscription(
                customer_id="cust_123", subscription_id="sub_123"
            )
コード例 #6
0
def test_stripe_hook_stripe_api_error(mock1, client):
    mock1.side_effect = APIError("badness")
    response = client.post(
        reverse("api.v1.stripe_hooks"),
        content_type="application/json",
        data={},
    )
    assert response.status_code == 400
コード例 #7
0
    def test_modify_error(self):
        self.modify_customer_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.modify_customer(  # nosec
                customer_id="cust_123",
                source_token="token",
                idempotency_key=utils.get_indempotency_key(),
            )
コード例 #8
0
    def test_delete_success(self):
        self.delete_customer_mock.side_effect = [
            APIError("message"),
            self.deleted_customer,
        ]

        deleted_customer = vendor.delete_stripe_customer(customer_id="cust_123")

        assert deleted_customer == self.deleted_customer  # nosec
コード例 #9
0
    def test_build_error(self):
        self.mock_create_subscription.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.build_stripe_subscription(
                customer_id="cust_123",
                plan_id="plan_123",
                idempotency_key=utils.get_indempotency_key(),
            )
コード例 #10
0
    def test_update_error(self):
        self.mock_modify_subscription.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.update_stripe_subscription(
                subscription=self.subscription,
                plan_id="plan_123",
                idempotency_key=utils.get_indempotency_key(),
            )
コード例 #11
0
    def test_modify_success(self):
        self.modify_customer_mock.side_effect = [APIError("message"), self.customer]

        customer = vendor.modify_customer(  # nosec
            customer_id="cust_123",
            source_token="token",
            idempotency_key=utils.get_indempotency_key(),
        )

        assert customer == self.customer  # nosec
コード例 #12
0
    def test_cancel_immediately_success(self):
        self.mock_delete_subscription.side_effect = [
            APIError("message"),
            self.subscription,
        ]

        subscription = vendor.cancel_stripe_subscription_immediately(
            subscription_id="sub_123", idempotency_key=utils.get_indempotency_key()
        )

        assert subscription == self.subscription  # nosec
コード例 #13
0
    def test_create_error(self):
        self.create_customer_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.create_stripe_customer(  # nosec
                source_token="token",
                email="*****@*****.**",
                userid="user_123",
                name="Test User",
                idempotency_key=utils.get_indempotency_key(),
            )
コード例 #14
0
    def test_reactivate_success(self):
        self.mock_modify_subscription.side_effect = [
            APIError("message"),
            self.subscription,
        ]

        subscription = vendor.reactivate_stripe_subscription(
            subscription_id="sub_123", idempotency_key=utils.get_indempotency_key()
        )

        assert subscription == self.subscription  # nosec
コード例 #15
0
    def test_cancel_at_end_success(self):
        self.mock_modify_subscription.side_effect = [
            APIError("message"),
            self.subscription,
        ]

        subscription = vendor.cancel_stripe_subscription_period_end(
            subscription_id="sub_123", idempotency_key=utils.get_indempotency_key()
        )

        assert subscription == self.subscription  # nosec
コード例 #16
0
    def test_create_success(self):
        self.create_customer_mock.side_effect = [APIError("message"), self.customer]

        customer = vendor.create_stripe_customer(  # nosec
            source_token="token",
            email="*****@*****.**",
            userid="user_123",
            name="Test User",
            idempotency_key=utils.get_indempotency_key(),
        )

        assert customer == self.customer  # nosec
コード例 #17
0
    def test_build_success(self):
        self.mock_create_subscription.side_effect = [
            APIError("message"),
            self.subscription,
        ]

        subscription = vendor.build_stripe_subscription(
            customer_id="cust_123",
            plan_id="plan_123",
            idempotency_key=utils.get_indempotency_key(),
        )

        assert subscription == self.subscription  # nosec
コード例 #18
0
def verify(hostname, certificate):
    """Verifies a PEM encoded certficate against a blacklist of known revoked
    fingerprints.

    returns True on success, raises RuntimeError on failure.
    """

    if hostname not in BLACKLISTED_DIGESTS:
        return True

    sha = hashlib.sha1()
    sha.update(certificate)
    fingerprint = sha.hexdigest()

    if fingerprint in BLACKLISTED_DIGESTS[hostname]:
        raise APIError("Invalid server certificate. You tried to "
                       "connect to a server that has a revoked "
                       "SSL certificate, which means we cannot "
                       "securely send data to that server. "
                       "Please email [email protected] if you "
                       "need help connecting to the correct API "
                       "server.")
    return True
コード例 #19
0
    def test_retrieve_success(self):
        self.retrieve_invoice_mock.side_effect = [APIError("message"), self.invoice]

        invoice = vendor.retrieve_stripe_invoice("in_test1")
        assert invoice == self.invoice  # nosec
コード例 #20
0
    def test_list_error(self):
        self.list_customer_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.get_customer_list("*****@*****.**")
コード例 #21
0
    def test_list_success(self):
        self.mock_list_subscription.side_effect = [APIError("message"), self.list]

        subscription_list = vendor.list_customer_subscriptions(cust_id="cust_123")

        assert subscription_list == self.list  # nosec
コード例 #22
0
    def test_retrieve_error(self):
        self.retrieve_customer_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.retrieve_stripe_customer(customer_id="cust_123")
コード例 #23
0
    def test_list_success(self):
        self.list_customer_mock.side_effect = [APIError("message"), [self.customer]]

        customer_list = vendor.get_customer_list("*****@*****.**")

        assert customer_list == [self.customer]  # nosec
コード例 #24
0
    def test_list_error(self):
        self.mock_list_subscription.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.list_customer_subscriptions(cust_id="cust_123")
コード例 #25
0
    def test_retrieve_success(self):
        self.retrieve_customer_mock.side_effect = [APIError("message"), self.customer]

        customer = vendor.retrieve_stripe_customer(customer_id="cust_123")

        assert customer == self.customer  # nosec
コード例 #26
0
    def test_retrieve_no_charge_id(self):
        self.retrieve_charge_mock.side_effect = [APIError("message"), self.charge2]

        charge = vendor.retrieve_stripe_charge("in_test1")
        assert charge == self.charge2  # nosec
コード例 #27
0
    def test_retrieve_list_error(self):
        self.list_plan_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.retrieve_plan_list(1)
コード例 #28
0
    def test_retrieve_list_success(self):
        self.list_plan_mock.side_effect = [APIError("message"), self.plan_list]

        plan_list = vendor.retrieve_plan_list(1)
        assert plan_list == self.plan_list  # nosec
コード例 #29
0
    def test_upcoming_error(self):
        self.preview_invoice_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.retrieve_stripe_invoice_upcoming(customer="cust_123")
コード例 #30
0
    def test_retrieve_error(self):
        self.retrieve_invoice_mock.side_effect = APIError("message")

        with self.assertRaises(APIError):
            vendor.retrieve_stripe_invoice("in_test1")