# Path: payway/qiwi/conf/settings.py
# QIWI_BILL_LIFETIME = getattr(settings, 'QIWI_BILL_LIFETIME', 24)  # hours
# 
# Path: payway/qiwi/models.py
# TERMINATION_CODES = Choices(
#     (0, 'SUCCESS',_('0 Success')),
#     (13, 'SERVER_IS_BUSY', _('13 Server is busy, please repeat your request later')),
#     (150, 'AUTHORIZATION_ERROR', _('150 Authorization error (wrong login/password)  ')),
#     (210, 'BILL_NOT_FOUND', _('210 Bill not found')),
#     (215, 'BILL_TXNID_EXISTS', _('215 Bill with this txn-id already exists')),
#     (241, 'BILL_VERY_SMALL_SUM', _('241 Very small bill sum')),
#     (242, 'BILL_MAXIMUM_SUM_EXCEEDED', _('242 Bill maximum sum exceeded')),
#     (278, 'BILL_LIST_MAX_TIME_RANGE_EXCEEDED', _('278 Bill list maximum time range exceeded')),
#     (298, 'NO_SUCH_AGENT', _('298 No such agent in the system')),
#     (300, 'UNKNOWN_ERROR', _('300 Unknown error')),
#     (330, 'ENCRYPTION_ERROR', _('330 Encryption error')),
#     (370, 'MAXIMUM_REQUEST_OVERLIMIT', _('370 Maximum allowed concurrent requests overlimit'))
# )
# 
# class Bill(ResponsePayment):
# 
# 
#     STATUS = Choices(
#         (50, 'MADE', _('50 Made')),
#         (52, 'PROCESSING', _('52 Processing')),
#         (60, 'PAYED', _('60 Paid')),
#         (150, 'TERMINAL_ERROR', _('150 Cancelled (Terminal error)')),
#         (151, 'MACHINE_ERROR', _('151 Cancelled (authorization error, declined, not enough money on account or something else)')),
#         (160, 'CANCELLED', _('160 Cancelled')),
#         (161, 'TIMEOUT', _('161 Cancelled (Timeout)')),
#     )
#     payment_system = _('Qiwi Wallet')
#     status = models.PositiveSmallIntegerField(_('Status'), choices=STATUS)
#     user = models.CharField(_('User phone number'), max_length=10)
#     date = models.CharField(_('Billing date'), max_length=20)
#     lifetime = models.CharField(_('Bill lifetime'), max_length=20)
# 
#     class Meta:
#         verbose_name = _('bill')
#         verbose_name_plural = _('bills')
#         db_table = 'payway_qiwi_bill'
# 
# Path: payway/qiwi/soap/client.py
# class QiwiSoapClient(object):
#     url = QIWI_SOAP_CLIENT_URL
# 
#     @classmethod
#     def createBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, user='', amount='', comment='', txn='', lifetime=QIWI_BILL_LIFETIME, alarm=QIWI_ALARM, create=QIWI_CREATE):
#         if len(user) > 10: raise QiwiSoapClientException("User phone number should be less than 10")
#         client = Client(cls.url)
# 
#         response = client.service.createBill(
#             login=login,
#             password=password,
#             user=user,
#             amount=amount,
#             comment=comment,
#             txn=txn,
#             lifetime=cls.hours_to_lifetime(lifetime),
#             alarm=alarm,
#             create=create)
#         return response
# 
#     @classmethod
#     def hours_to_lifetime(cls, days):
#         now = datetime.datetime.now()
#         now += datetime.timedelta(days=days)
#         return now.strftime(QIWI_DATETIME_FORMAT)
# 
#     @classmethod
#     def cancelBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, txn=''):
#         client = Client(cls.url)
#         response = client.service.cancelBill(
#                     login=login,
#                     password=password,
#                     txn=txn,
#         )
#         return response
# 
#     @classmethod
#     def checkBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, txn=''):
#         client = Client(cls.url)
#         response = client.service.checkBill(
#                     login=login,
#                     password=password,
#                     txn=txn,
#         )
#         return response
# 
# Path: payway/qiwi/tests/mock_provider.py
# class MockQiwiProviderRunner(Thread):
#     PORT = 18888
# 
#     def __init__(self):
#         Thread.__init__(self)
#         self.setDaemon(True)
#         self.services = [
#             ('createBill', MockCreateBillService),
#             ('cancelBill', MockCancelBillService),
#             ('checkBill', MockCheckBillService),
#         ]
# 
#     def run(self):
#         app = webservices.WebService(self.services)
#         app.listen(self.PORT)
#         tornado.ioloop.IOLoop.instance().start()
# 
#     def stop(self):
#         tornado.ioloop.IOLoop.instance().stop()
#         self.join()
# 
# RECEIVED_DATA = {}
# 
# BILLING_DATE = '10.01.2012 13:00:00'


from time import sleep
from django.test import TestCase
from payway.qiwi.conf.settings import QIWI_BILL_LIFETIME
from payway.qiwi.models import TERMINATION_CODES, Bill
from payway.qiwi.soap.client import QiwiSoapClient
from payway.qiwi.tests.mock_provider import MockQiwiProviderRunner, RECEIVED_DATA, BILLING_DATE
# -*- coding: UTF-8 -*-




__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class QiwiSoapClientTestCase(TestCase):

# Path: payway/qiwi/conf/settings.py
# QIWI_BILL_LIFETIME = getattr(settings, 'QIWI_BILL_LIFETIME', 24)  # hours
# 
# Path: payway/qiwi/models.py
# TERMINATION_CODES = Choices(
#     (0, 'SUCCESS',_('0 Success')),
#     (13, 'SERVER_IS_BUSY', _('13 Server is busy, please repeat your request later')),
#     (150, 'AUTHORIZATION_ERROR', _('150 Authorization error (wrong login/password)  ')),
#     (210, 'BILL_NOT_FOUND', _('210 Bill not found')),
#     (215, 'BILL_TXNID_EXISTS', _('215 Bill with this txn-id already exists')),
#     (241, 'BILL_VERY_SMALL_SUM', _('241 Very small bill sum')),
#     (242, 'BILL_MAXIMUM_SUM_EXCEEDED', _('242 Bill maximum sum exceeded')),
#     (278, 'BILL_LIST_MAX_TIME_RANGE_EXCEEDED', _('278 Bill list maximum time range exceeded')),
#     (298, 'NO_SUCH_AGENT', _('298 No such agent in the system')),
#     (300, 'UNKNOWN_ERROR', _('300 Unknown error')),
#     (330, 'ENCRYPTION_ERROR', _('330 Encryption error')),
#     (370, 'MAXIMUM_REQUEST_OVERLIMIT', _('370 Maximum allowed concurrent requests overlimit'))
# )
# 
# class Bill(ResponsePayment):
# 
# 
#     STATUS = Choices(
#         (50, 'MADE', _('50 Made')),
#         (52, 'PROCESSING', _('52 Processing')),
#         (60, 'PAYED', _('60 Paid')),
#         (150, 'TERMINAL_ERROR', _('150 Cancelled (Terminal error)')),
#         (151, 'MACHINE_ERROR', _('151 Cancelled (authorization error, declined, not enough money on account or something else)')),
#         (160, 'CANCELLED', _('160 Cancelled')),
#         (161, 'TIMEOUT', _('161 Cancelled (Timeout)')),
#     )
#     payment_system = _('Qiwi Wallet')
#     status = models.PositiveSmallIntegerField(_('Status'), choices=STATUS)
#     user = models.CharField(_('User phone number'), max_length=10)
#     date = models.CharField(_('Billing date'), max_length=20)
#     lifetime = models.CharField(_('Bill lifetime'), max_length=20)
# 
#     class Meta:
#         verbose_name = _('bill')
#         verbose_name_plural = _('bills')
#         db_table = 'payway_qiwi_bill'
# 
# Path: payway/qiwi/soap/client.py
# class QiwiSoapClient(object):
#     url = QIWI_SOAP_CLIENT_URL
# 
#     @classmethod
#     def createBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, user='', amount='', comment='', txn='', lifetime=QIWI_BILL_LIFETIME, alarm=QIWI_ALARM, create=QIWI_CREATE):
#         if len(user) > 10: raise QiwiSoapClientException("User phone number should be less than 10")
#         client = Client(cls.url)
# 
#         response = client.service.createBill(
#             login=login,
#             password=password,
#             user=user,
#             amount=amount,
#             comment=comment,
#             txn=txn,
#             lifetime=cls.hours_to_lifetime(lifetime),
#             alarm=alarm,
#             create=create)
#         return response
# 
#     @classmethod
#     def hours_to_lifetime(cls, days):
#         now = datetime.datetime.now()
#         now += datetime.timedelta(days=days)
#         return now.strftime(QIWI_DATETIME_FORMAT)
# 
#     @classmethod
#     def cancelBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, txn=''):
#         client = Client(cls.url)
#         response = client.service.cancelBill(
#                     login=login,
#                     password=password,
#                     txn=txn,
#         )
#         return response
# 
#     @classmethod
#     def checkBill(cls, login=QIWI_LOGIN, password=QIWI_PASSWORD, txn=''):
#         client = Client(cls.url)
#         response = client.service.checkBill(
#                     login=login,
#                     password=password,
#                     txn=txn,
#         )
#         return response
# 
# Path: payway/qiwi/tests/mock_provider.py
# class MockQiwiProviderRunner(Thread):
#     PORT = 18888
# 
#     def __init__(self):
#         Thread.__init__(self)
#         self.setDaemon(True)
#         self.services = [
#             ('createBill', MockCreateBillService),
#             ('cancelBill', MockCancelBillService),
#             ('checkBill', MockCheckBillService),
#         ]
# 
#     def run(self):
#         app = webservices.WebService(self.services)
#         app.listen(self.PORT)
#         tornado.ioloop.IOLoop.instance().start()
# 
#     def stop(self):
#         tornado.ioloop.IOLoop.instance().stop()
#         self.join()
# 
# RECEIVED_DATA = {}
# 
# BILLING_DATE = '10.01.2012 13:00:00'


# Path: payway/qiwi/tests/soap/client.py
from time import sleep
from django.test import TestCase
from payway.qiwi.conf.settings import QIWI_BILL_LIFETIME
from payway.qiwi.models import TERMINATION_CODES, Bill
from payway.qiwi.soap.client import QiwiSoapClient
from payway.qiwi.tests.mock_provider import MockQiwiProviderRunner, RECEIVED_DATA, BILLING_DATE

# -*- coding: UTF-8 -*-




__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


class QiwiSoapClientTestCase(TestCase):

    mock_qiwi_provider = None