コード例 #1
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
 def test_pay__invoice_not_exists_by_test(self):
     self.assertEqual(InvoicePrototype._db_count(), 0)
     self.create_invoice(worker_call_count=1)
     self.assertEqual(InvoicePrototype._db_count(), 1)
     self.assertTrue(
         self.pay(worker_call_count=1, test='1').pay_result.is_SUCCESS)
     self.assertEqual(InvoicePrototype._db_count(), 2)
コード例 #2
0
    def test_test_is_1(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)
        with mock.patch('the_tale.finances.bank.logic.get_account_id', mock.Mock(return_value=1234)):
            result, invoice_id = pay(command=COMMAND_TYPE.PAY,
                                     external_md5=self.pay_md5,
                                     v1=self.user_email, v2=None, v3=None,
                                     id=self.xsolla_id, sum=self.payment_sum, test='1', date=None, request_url='bla-bla.test.com')

        self.assertTrue(result.is_SUCCESS)
        self.assertEqual(InvoicePrototype._db_count(), 1)
        self.assertTrue(InvoicePrototype._db_get_object(0).test)
コード例 #3
0
    def test_get_by_xsolla_id__different_by_test(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice_real = self.create_invoice(worker_call_count=1, xsolla_id='1', test='0')
        invoice_test = self.create_invoice(worker_call_count=1, xsolla_id='1', test='1')

        self.assertEqual(InvoicePrototype._db_count(), 2)

        self.assertNotEqual(invoice_test.id, invoice_real.id)

        self.assertEqual(InvoicePrototype.get_by_xsolla_id(1, False).id, invoice_real.id)
        self.assertEqual(InvoicePrototype.get_by_xsolla_id(1, True).id, invoice_test.id)
コード例 #4
0
    def test_create_success__date_specified(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=1, date='2013-03-25 18:48:22')

        self.assertEqual(invoice.date, datetime.datetime(year=2013, month=3, day=25, hour=18, minute=48, second=22))
        self.assertTrue(invoice.pay_result.is_SUCCESS)
コード例 #5
0
    def test_create_success__test_not_none__test(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=1, test='1')

        self.assertTrue(invoice.test)
        self.assertTrue(invoice.pay_result.is_SUCCESS)
コード例 #6
0
    def test_create_success__wrong_date_format(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=0, date='')

        self.assertEqual(invoice.date, None)
        self.assertTrue(invoice.pay_result.is_WRONG_DATE_FORMAT)
コード例 #7
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_create_success__test_not_none__test(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=1, test='1')

        self.assertTrue(invoice.test)
        self.assertTrue(invoice.pay_result.is_SUCCESS)
コード例 #8
0
    def pay(self, **kwargs):
        if set(kwargs.keys()) - set([
                'account_id', 'user_email', 'xsolla_id', 'payment_sum', 'test',
                'date', 'request_url'
        ]):
            raise Exception('wrong agruments in pay')

        account_id = kwargs.get('account_id', self.account_id)
        user_email = kwargs.get('user_email', self.user_email)
        xsolla_id = kwargs.get('xsolla_id', self.xsolla_id)
        payment_sum = kwargs.get('payment_sum', self.payment_sum)
        test = kwargs.get('test', self._test)
        date = kwargs.get('date', self.date)
        request_url = kwargs.get('request_url', self.request_url)

        with mock.patch('the_tale.finances.bank.logic.get_account_id',
                        mock.Mock(return_value=account_id)):
            return InvoicePrototype.pay(v1=user_email,
                                        v2=self.v2,
                                        v3=self.v3,
                                        xsolla_id=xsolla_id,
                                        payment_sum=payment_sum,
                                        test=test,
                                        date=date,
                                        request_url=request_url)
コード例 #9
0
def pay(command, external_md5, v1, v2, v3, id, sum, test, date, request_url):

    if v1 is None:
        return PAY_RESULT.NOT_SPECIFIED_V1, None

    if id is None:
        return PAY_RESULT.NOT_SPECIFIED_ID, None

    if sum is None:
        return PAY_RESULT.NOT_SPECIFIED_SUM, None

    if not external_md5 or pay_md5(command, v1,
                                   id).lower() != external_md5.lower():
        return PAY_RESULT.WRONG_MD5, None

    invoice = InvoicePrototype.pay(v1=v1,
                                   v2=v2,
                                   v3=v3,
                                   xsolla_id=id,
                                   payment_sum=sum,
                                   test=test,
                                   date=date,
                                   request_url=request_url)

    return invoice.pay_result, invoice.id
コード例 #10
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_create_success__wrong_date_format(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=0, date='')

        self.assertEqual(invoice.date, None)
        self.assertTrue(invoice.pay_result.is_WRONG_DATE_FORMAT)
コード例 #11
0
    def test_test_is_1(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)
        with mock.patch('the_tale.finances.bank.logic.get_account_id',
                        mock.Mock(return_value=1234)):
            result, invoice_id = pay(command=COMMAND_TYPE.PAY,
                                     external_md5=self.pay_md5,
                                     v1=self.user_email,
                                     v2=None,
                                     v3=None,
                                     id=self.xsolla_id,
                                     sum=self.payment_sum,
                                     test='1',
                                     date=None,
                                     request_url=u'bla-bla.test.com')

        self.assertTrue(result.is_SUCCESS)
        self.assertEqual(InvoicePrototype._db_count(), 1)
        self.assertTrue(InvoicePrototype._db_get_object(0).test)
コード例 #12
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_get_by_xsolla_id__different_by_test(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice_real = self.create_invoice(worker_call_count=1,
                                           xsolla_id='1',
                                           test='0')
        invoice_test = self.create_invoice(worker_call_count=1,
                                           xsolla_id='1',
                                           test='1')

        self.assertEqual(InvoicePrototype._db_count(), 2)

        self.assertNotEqual(invoice_test.id, invoice_real.id)

        self.assertEqual(
            InvoicePrototype.get_by_xsolla_id(1, False).id, invoice_real.id)
        self.assertEqual(
            InvoicePrototype.get_by_xsolla_id(1, True).id, invoice_test.id)
コード例 #13
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_create_success(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=1)

        self.assertEqual(InvoicePrototype._db_count(), 1)

        self.assertEqual(invoice.bank_amount, int(self.fabric.payment_sum))
        self.assertEqual(invoice.bank_id, self.fabric.account_id)
        self.assertEqual(invoice.bank_invoice_id, None)
        self.assertTrue(invoice.state.is_CREATED)
        self.assertEqual(invoice.xsolla_id, self.fabric.xsolla_id)
        self.assertEqual(invoice.xsolla_v1, self.fabric.user_email)
        self.assertEqual(invoice.xsolla_v2, self.fabric.v2)
        self.assertEqual(invoice.xsolla_v3, self.fabric.v3)
        self.assertEqual(invoice.request_url, self.fabric.request_url)
        self.assertFalse(invoice.test)

        self.assertFalse(invoice.test)
        self.assertTrue(invoice.pay_result.is_SUCCESS)
コード例 #14
0
    def test_create_success(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=1)

        self.assertEqual(InvoicePrototype._db_count(), 1)

        self.assertEqual(invoice.bank_amount, int(self.fabric.payment_sum))
        self.assertEqual(invoice.bank_id, self.fabric.account_id)
        self.assertEqual(invoice.bank_invoice_id, None)
        self.assertTrue(invoice.state.is_CREATED)
        self.assertEqual(invoice.xsolla_id, self.fabric.xsolla_id)
        self.assertEqual(invoice.xsolla_v1, self.fabric.user_email)
        self.assertEqual(invoice.xsolla_v2, self.fabric.v2)
        self.assertEqual(invoice.xsolla_v3, self.fabric.v3)
        self.assertEqual(invoice.request_url, self.fabric.request_url)
        self.assertFalse(invoice.test)

        self.assertFalse(invoice.test)
        self.assertTrue(invoice.pay_result.is_SUCCESS)
コード例 #15
0
    def test_process_invoices(self):
        invoice_1 = self.create_invoice(worker_call_count=1, xsolla_id=1)
        invoice_2 = self.create_invoice(worker_call_count=1, xsolla_id=2, test='1')
        invoice_3 = self.create_invoice(worker_call_count=1, xsolla_id=3)
        invoice_4 = self.create_invoice(worker_call_count=1, xsolla_id=4)

        invoice_3.process()

        InvoicePrototype.process_invoices()

        invoice_1.reload()
        invoice_2.reload()
        invoice_3.reload()
        invoice_4.reload()

        self.assertTrue(invoice_1.state.is_PROCESSED)
        self.assertTrue(invoice_2.state.is_SKIPPED_BECOUSE_TEST)
        self.assertTrue(invoice_3.state.is_PROCESSED)
        self.assertTrue(invoice_4.state.is_PROCESSED)

        self.assertTrue(invoice_3.updated_at < invoice_1.updated_at < invoice_2.updated_at < invoice_4.updated_at)
コード例 #16
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_create_success__date_specified(self):
        self.assertEqual(InvoicePrototype._db_count(), 0)

        invoice = self.create_invoice(worker_call_count=1,
                                      date='2013-03-25 18:48:22')

        self.assertEqual(
            invoice.date,
            datetime.datetime(year=2013,
                              month=3,
                              day=25,
                              hour=18,
                              minute=48,
                              second=22))
        self.assertTrue(invoice.pay_result.is_SUCCESS)
コード例 #17
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_process_invoices(self):
        invoice_1 = self.create_invoice(worker_call_count=1, xsolla_id=1)
        invoice_2 = self.create_invoice(worker_call_count=1,
                                        xsolla_id=2,
                                        test='1')
        invoice_3 = self.create_invoice(worker_call_count=1, xsolla_id=3)
        invoice_4 = self.create_invoice(worker_call_count=1, xsolla_id=4)

        invoice_3.process()

        InvoicePrototype.process_invoices()

        invoice_1.reload()
        invoice_2.reload()
        invoice_3.reload()
        invoice_4.reload()

        self.assertTrue(invoice_1.state.is_PROCESSED)
        self.assertTrue(invoice_2.state.is_SKIPPED_BECOUSE_TEST)
        self.assertTrue(invoice_3.state.is_PROCESSED)
        self.assertTrue(invoice_4.state.is_PROCESSED)

        self.assertTrue(invoice_3.updated_at < invoice_1.updated_at <
                        invoice_2.updated_at < invoice_4.updated_at)
コード例 #18
0
    def test_user_not_exists(self):
        with mock.patch('the_tale.finances.bank.logic.get_account_id',
                        mock.Mock(return_value=None)) as bank_check_user:
            response = self.request_xml(self.construct_url())

        self.check_xml_ok(
            response,
            body=self.construct_pay_answer(
                PAY_RESULT.USER_NOT_EXISTS,
                internal_id=InvoicePrototype._db_get_object(0).id),
            encoding='cp1251')

        self.assertEqual(bank_check_user.call_count, 1)
        self.assertEqual(bank_check_user.call_args,
                         mock.call(email=self.user_email))
コード例 #19
0
def pay(command, external_md5, v1, v2, v3, id, sum, test, date, request_url):

    if v1 is None:
        return PAY_RESULT.NOT_SPECIFIED_V1, None

    if id is None:
        return PAY_RESULT.NOT_SPECIFIED_ID, None

    if sum is None:
        return PAY_RESULT.NOT_SPECIFIED_SUM, None

    if not external_md5 or pay_md5(command, v1, id).lower() != external_md5.lower():
        return PAY_RESULT.WRONG_MD5, None

    invoice = InvoicePrototype.pay(v1=v1, v2=v2, v3=v3, xsolla_id=id, payment_sum=sum, test=test, date=date, request_url=request_url)

    return invoice.pay_result, invoice.id
コード例 #20
0
ファイル: helpers.py プロジェクト: Alkalit/the-tale
    def pay(self, **kwargs):
        if set(kwargs.keys()) - set(['account_id', 'user_email', 'xsolla_id', 'payment_sum', 'test', 'date', 'request_url']):
            raise Exception('wrong agruments in pay')

        account_id = kwargs.get('account_id', self.account_id)
        user_email = kwargs.get('user_email', self.user_email)
        xsolla_id = kwargs.get('xsolla_id', self.xsolla_id)
        payment_sum = kwargs.get('payment_sum', self.payment_sum)
        test = kwargs.get('test', self._test)
        date = kwargs.get('date', self.date)
        request_url = kwargs.get('request_url', self.request_url)

        with mock.patch('the_tale.finances.bank.logic.get_account_id', mock.Mock(return_value=account_id)):
            return InvoicePrototype.pay(v1=user_email,
                                        v2=self.v2,
                                        v3=self.v3,
                                        xsolla_id=xsolla_id,
                                        payment_sum=payment_sum,
                                        test=test,
                                        date=date,
                                        request_url=request_url)
コード例 #21
0
    def test_user_not_exists(self):
        with mock.patch('the_tale.finances.bank.logic.get_account_id', mock.Mock(return_value=None)) as bank_check_user:
            response = self.request_xml(self.construct_url())

        self.check_xml_ok(response,
                          body=self.construct_pay_answer(PAY_RESULT.USER_NOT_EXISTS, internal_id=InvoicePrototype._db_get_object(0).id),
                          encoding='cp1251')

        self.assertEqual(bank_check_user.call_count, 1)
        self.assertEqual(bank_check_user.call_args, mock.call(email=self.user_email))
コード例 #22
0
 def handle_invoices(self):
     InvoicePrototype.process_invoices()
コード例 #23
0
 def test_pay__created(self):
     self.assertEqual(InvoicePrototype._db_count(), 0)
     self.assertTrue(self.pay(worker_call_count=1).pay_result.is_SUCCESS)
     self.assertEqual(InvoicePrototype._db_count(), 1)
コード例 #24
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
    def test_get_by_xsolla_id__not_exists_by_test(self):
        self.create_invoice(worker_call_count=1, xsolla_id='2', test='1')
        self.assertEqual(InvoicePrototype.get_by_xsolla_id(2, False), None)

        self.create_invoice(worker_call_count=1, xsolla_id='3', test='0')
        self.assertEqual(InvoicePrototype.get_by_xsolla_id(3, True), None)
コード例 #25
0
ファイル: test_prototypes.py プロジェクト: serhii73/the-tale
 def test_pay__created(self):
     self.assertEqual(InvoicePrototype._db_count(), 0)
     self.assertTrue(self.pay(worker_call_count=1).pay_result.is_SUCCESS)
     self.assertEqual(InvoicePrototype._db_count(), 1)
コード例 #26
0
 def test_pay__invoice_not_exists_by_test(self):
     self.assertEqual(InvoicePrototype._db_count(), 0)
     self.create_invoice(worker_call_count=1)
     self.assertEqual(InvoicePrototype._db_count(), 1)
     self.assertTrue(self.pay(worker_call_count=1, test='1').pay_result.is_SUCCESS)
     self.assertEqual(InvoicePrototype._db_count(), 2)
コード例 #27
0
ファイル: banker.py プロジェクト: pavetok/the-tale
 def handle_invoices(self):
     InvoicePrototype.process_invoices()
コード例 #28
0
    def test_get_by_xsolla_id__not_exists_by_test(self):
        self.create_invoice(worker_call_count=1, xsolla_id='2', test='1')
        self.assertEqual(InvoicePrototype.get_by_xsolla_id(2, False), None)

        self.create_invoice(worker_call_count=1, xsolla_id='3', test='0')
        self.assertEqual(InvoicePrototype.get_by_xsolla_id(3, True), None)