#!/usr/bin/env python
# -*- coding: utf-8 -*-
from test_plus.test import TestCase
from unittest import skip
from mock import patch, Mock, MagicMock
from mhackspace.users.models import Membership
import django.utils.timezone

from mhackspace.subscriptions.payments import gocardless_provider, braintree_provider
from mhackspace.subscriptions.tests.mocks import gocardlessMocks


class TestPaymentGatewaysGocardless(gocardlessMocks):

    def setUp(self):
        super().setUp()

    def test_unsubscribe(self):
        self.mock_success_responses()

        result = self.provider.cancel_subscription(user=self.user1, reference='M01')

        self.assertEqual(result.get('amount'), 20.00)
        self.assertEqual(result.get('reference'), '02')
        self.assertEqual(result.get('success'), True)

    def test_confirm_subscription_callback(self):
        self.mock_success_responses()
        membership = self.create_membership_record()
        result = self.provider.confirm_subscription(
            membership=membership,
            session=None,
            provider_response={'redirect_flow_id': 'redirect_mock_url'},
            name='test')

        self.assertEqual(result.get('amount'), '20.00')
        self.assertEqual(result.get('reference'), '02')
        self.assertEqual(result.get('success'), '200')

    def test_fetch_subscription_gocardless(self):
        self.mock_success_responses()
        self.mock_mandate_success_responses()
        self.mock_customer_success_responses()
        for item in self.provider.fetch_subscriptions():
            self.assertEqual(item.get('status'), 'active')
            self.assertEqual(item.get('email'), 'test@test.com')
            self.assertEqual(item.get('reference'), '02')
            self.assertEqual(item.get('amount'), 20.00)
