<commit_before>from django.test import TestCase

from mock import patch
from money import Money

from ..models import MangoPayPayIn, MangoPayPayInBankWire

from .factories import MangoPayPayInFactory, MangoPayPayInBankWireFactory
from .client import MockMangoPayApi


class MangoPayPayInTests(TestCase):

    def setUp(self):
        self.pay_in = MangoPayPayInFactory()

    @patch("mangopay.models.get_mangopay_api_client")
    def test_create(self, mock_client):
        id = 76
        mock_client.return_value = MockMangoPayApi(pay_in_id=id)
        self.assertIsNone(self.pay_in.mangopay_id)
        self.pay_in.create(secure_mode_return_url="http://test.com")
        MangoPayPayIn.objects.get(id=self.pay_in.id, mangopay_id=id)

    @patch("mangopay.models.get_mangopay_api_client")
    def test_get(self, mock_client):
        mock_client.return_value = MockMangoPayApi()
        self.assertIsNone(self.pay_in.secure_mode_redirect_url)
        self.assertIsNone(self.pay_in.status)
        self.pay_in = self.pay_in.get()
        self.assertIsNotNone(self.pay_in.status)
        self.assertIsNotNone(self.pay_in.secure_mode_redirect_url)


class MangoPayPayInBankWireTests(TestCase):

    def setUp(self):
        self.pay_in = MangoPayPayInBankWireFactory()

    @patch("mangopay.models.get_mangopay_api_client")
    def test_create(self, mock_client):
        id = 42
        mock_client.return_value = MockMangoPayApi(pay_in_id=id)
        self.assertIsNone(self.pay_in.mangopay_id)
        self.assertIsNone(self.pay_in.mangopay_bank_account)
        self.assertIsNone(self.pay_in.wire_reference)
        self.pay_in.create()
        MangoPayPayInBankWire.objects.get(id=self.pay_in.id, mangopay_id=id)
        self.assertIsNotNone(self.pay_in.mangopay_bank_account['IBAN'])
        self.assertIsNotNone(self.pay_in.mangopay_bank_account['BIC'])
        self.assertIsNotNone(self.pay_in.wire_reference)<commit_msg>test that PayIn type is set automatically by proxy model<commit_after>from django.test import TestCase

from mock import patch

from ..models import MangoPayPayInByCard, MangoPayPayInBankWire

from .factories import MangoPayPayInFactory, MangoPayPayInBankWireFactory
from .client import MockMangoPayApi
from mangopay.constants import CARD_WEB, BANK_WIRE


class MangoPayPayByCardInTests(TestCase):

    def setUp(self):
        self.pay_in = MangoPayPayInFactory()

    @patch("mangopay.models.get_mangopay_api_client")
    def test_create(self, mock_client):
        id = 76
        mock_client.return_value = MockMangoPayApi(pay_in_id=id)
        self.assertIsNone(self.pay_in.mangopay_id)
        self.pay_in.create(secure_mode_return_url="http://test.com")
        MangoPayPayInByCard.objects.get(id=self.pay_in.id, mangopay_id=id)

    @patch("mangopay.models.get_mangopay_api_client")
    def test_get(self, mock_client):
        mock_client.return_value = MockMangoPayApi()
        self.assertIsNone(self.pay_in.secure_mode_redirect_url)
        self.assertIsNone(self.pay_in.status)
        self.pay_in = self.pay_in.get()
        self.assertIsNotNone(self.pay_in.status)
        self.assertIsNotNone(self.pay_in.secure_mode_redirect_url)

    def test_save_sets_type(self):
        payin = MangoPayPayInByCard(mangopay_user=self.pay_in.mangopay_user, mangopay_wallet=self.pay_in.mangopay_wallet, mangopay_card=self.pay_in.mangopay_card)
        payin.save()
        self.assertEqual(CARD_WEB, payin.type)


class MangoPayPayInBankWireTests(TestCase):

    def setUp(self):
        self.pay_in = MangoPayPayInBankWireFactory()

    @patch("mangopay.models.get_mangopay_api_client")
    def test_create(self, mock_client):
        id = 42
        mock_client.return_value = MockMangoPayApi(pay_in_id=id)
        self.assertIsNone(self.pay_in.mangopay_id)
        self.assertIsNone(self.pay_in.mangopay_bank_account)
        self.assertIsNone(self.pay_in.wire_reference)
        self.pay_in.create()
        MangoPayPayInBankWire.objects.get(id=self.pay_in.id, mangopay_id=id)
        self.assertIsNotNone(self.pay_in.mangopay_bank_account['IBAN'])
        self.assertIsNotNone(self.pay_in.mangopay_bank_account['BIC'])
        self.assertIsNotNone(self.pay_in.wire_reference)

    def test_save_sets_type(self):
        payin = MangoPayPayInBankWire(mangopay_user=self.pay_in.mangopay_user, mangopay_wallet=self.pay_in.mangopay_wallet)
        payin.save()
        self.assertEqual(BANK_WIRE, payin.type)
{'fraction_non_alphanumeric': 0.09238395673726904, 'fraction_numerical': 0.0018026137899954935, 'mean_word_length': 4.119953863898501, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1323396', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1589, 'n_words': 184}