コード例 #1
0
    def test_subscription(self):
        subscription = self.subscription
        json_data = subscription_adapter(subscription, self.dummy_request)
        expected = dict(
            guid=subscription.guid,
            amount=None,
            effective_amount=subscription.plan.amount,
            funding_instrument_uri=subscription.funding_instrument_uri,
            appears_on_statement_as=subscription.appears_on_statement_as,
            invoice_count=subscription.invoice_count,
            canceled=subscription.canceled,
            next_invoice_at=subscription.next_invoice_at.isoformat(),
            created_at=subscription.created_at.isoformat(),
            updated_at=subscription.updated_at.isoformat(),
            started_at=subscription.started_at.isoformat(),
            canceled_at=None,
            customer_guid=subscription.customer_guid,
            plan_guid=subscription.plan_guid,
        )
        self.assertEqual(json_data, expected)

        def assert_amount(amount, expected_amount, expected_effective_amount):
            subscription.amount = amount
            json_data = subscription_adapter(subscription, self.dummy_request)
            self.assertEqual(json_data['amount'], expected_amount)
            self.assertEqual(json_data['effective_amount'],
                             expected_effective_amount)

        assert_amount(None, None, subscription.plan.amount)
        assert_amount(1234, 1234, 1234)

        def assert_canceled_at(canceled_at, expected_canceled_at):
            subscription.canceled_at = canceled_at
            json_data = subscription_adapter(subscription, self.dummy_request)
            self.assertEqual(json_data['canceled_at'], expected_canceled_at)

        now = utc_now()
        assert_canceled_at(None, None)
        assert_canceled_at(now, now.isoformat())
コード例 #2
0
ファイル: test_renderer.py プロジェクト: Imaxinacion/billy
    def test_subscription(self):
        subscription = self.subscription
        json_data = subscription_adapter(subscription, self.dummy_request)
        expected = dict(
            guid=subscription.guid,
            amount=None,
            effective_amount=subscription.plan.amount,
            funding_instrument_uri=subscription.funding_instrument_uri,
            appears_on_statement_as=subscription.appears_on_statement_as,
            invoice_count=subscription.invoice_count,
            canceled=subscription.canceled,
            next_invoice_at=subscription.next_invoice_at.isoformat(),
            created_at=subscription.created_at.isoformat(),
            updated_at=subscription.updated_at.isoformat(),
            started_at=subscription.started_at.isoformat(),
            canceled_at=None,
            customer_guid=subscription.customer_guid,
            plan_guid=subscription.plan_guid,
        )
        self.assertEqual(json_data, expected)

        def assert_amount(amount, expected_amount, expected_effective_amount):
            subscription.amount = amount
            json_data = subscription_adapter(subscription, self.dummy_request)
            self.assertEqual(json_data['amount'], expected_amount)
            self.assertEqual(json_data['effective_amount'],
                             expected_effective_amount)

        assert_amount(None, None, subscription.plan.amount)
        assert_amount(1234, 1234, 1234)

        def assert_canceled_at(canceled_at, expected_canceled_at):
            subscription.canceled_at = canceled_at
            json_data = subscription_adapter(subscription, self.dummy_request)
            self.assertEqual(json_data['canceled_at'], expected_canceled_at)

        now = utc_now()
        assert_canceled_at(None, None)
        assert_canceled_at(now, now.isoformat())
コード例 #3
0
ファイル: test_renderer.py プロジェクト: JeffersonK/billy
    def test_subscription(self):
        from billy.models.subscription import SubscriptionModel
        from billy.renderers import subscription_adapter
        subscription_model = SubscriptionModel(self.testapp.session)
        subscription = subscription_model.get(self.subscription_guid)
        json_data = subscription_adapter(subscription, self.dummy_request)
        expected = dict(
            guid=subscription.guid, 
            amount=None,
            payment_uri=subscription.payment_uri,
            period=subscription.period,
            canceled=subscription.canceled,
            next_transaction_at=subscription.next_transaction_at.isoformat(),
            created_at=subscription.created_at.isoformat(),
            updated_at=subscription.updated_at.isoformat(),
            started_at=subscription.started_at.isoformat(),
            canceled_at=None,
            customer_guid=subscription.customer_guid,
            plan_guid=subscription.plan_guid,
        )
        self.assertEqual(json_data, expected)

        def assert_amount(amount, expected_amount):
            subscription.amount = amount 
            json_data = subscription_adapter(subscription, self.dummy_request)
            self.assertEqual(json_data['amount'], expected_amount)

        assert_amount(None, None)
        assert_amount(1234, 1234)

        def assert_canceled_at(canceled_at, expected_canceled_at):
            subscription.canceled_at = canceled_at 
            json_data = subscription_adapter(subscription, self.dummy_request)
            self.assertEqual(json_data['canceled_at'], expected_canceled_at)

        now = datetime.datetime.utcnow()
        assert_canceled_at(None, None)
        assert_canceled_at(now, now.isoformat())
コード例 #4
0
ファイル: test_renderer.py プロジェクト: JeffersonK/billy
 def assert_canceled_at(canceled_at, expected_canceled_at):
     subscription.canceled_at = canceled_at 
     json_data = subscription_adapter(subscription, self.dummy_request)
     self.assertEqual(json_data['canceled_at'], expected_canceled_at)
コード例 #5
0
ファイル: test_renderer.py プロジェクト: JeffersonK/billy
 def assert_amount(amount, expected_amount):
     subscription.amount = amount 
     json_data = subscription_adapter(subscription, self.dummy_request)
     self.assertEqual(json_data['amount'], expected_amount)
コード例 #6
0
 def assert_canceled_at(canceled_at, expected_canceled_at):
     subscription.canceled_at = canceled_at
     json_data = subscription_adapter(subscription, self.dummy_request)
     self.assertEqual(json_data['canceled_at'], expected_canceled_at)
コード例 #7
0
 def assert_amount(amount, expected_amount, expected_effective_amount):
     subscription.amount = amount
     json_data = subscription_adapter(subscription, self.dummy_request)
     self.assertEqual(json_data['amount'], expected_amount)
     self.assertEqual(json_data['effective_amount'],
                      expected_effective_amount)