# Path: payway/merchants/models.py
# class Merchant(RandomUIDAbstractModel):
# 
#     URL_METHODS = Choices(
#         ('POST', 'POST'),
#         ('GET',  'GET'),
#     )
# 
#     user = models.ForeignKey(User, related_name='merchants', verbose_name=_('user'))
#     name = models.CharField('Имя', max_length=255)
#     secret_key = models.CharField(_('secret key'), max_length=50)
# 
#     result_url = models.URLField(_('result url'))
#     result_url_method = models.CharField(_('result url method'), max_length=4, choices=URL_METHODS)
# 
#     success_url = models.URLField(_('success url'))
#     fail_url = models.URLField(_('fail url'))
# 
#     class Meta:
#         verbose_name = 'продавец'
#         verbose_name_plural = 'продавцы'
#         db_table = 'payway_merchants'


from django.test import TestCase
from simptools.wrappers.http import HttpClient
from payway.merchants.models import Merchant
from payway.merchants.tests.http.mocks import *
# -*- coding: UTF-8 -*-


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



class MerchantHttpClientTestCase(TestCase):
    fixtures = [
        "payway_merchants_merchants.json",
        "payway_orders_orders.json",
    ]

    def setUp(self):
        self.merchant = Merchant.objects.get(uid=972855239)
        self.order = self.merchant.orders.all()[0]

    def tearDown(self):
        set_back_MerchantHttpClient_execute()

    def test_success_notify(self):
        mock_MerchantHttpClient_success_execute()
        response = MerchantHttpClient.notify(self.merchant, self.order)
        self.assertIn(RESPONSE_STATUS.OK, response)

    def test_connection_error(self):
        self.merchant.result_url = 'http://wrong12343434.com'
        mock_MerchantHttpClient_fail_execute()
        response = MerchantHttpClient.notify(self.merchant, self.order)

# Path: payway/merchants/models.py
# class Merchant(RandomUIDAbstractModel):
# 
#     URL_METHODS = Choices(
#         ('POST', 'POST'),
#         ('GET',  'GET'),
#     )
# 
#     user = models.ForeignKey(User, related_name='merchants', verbose_name=_('user'))
#     name = models.CharField('Имя', max_length=255)
#     secret_key = models.CharField(_('secret key'), max_length=50)
# 
#     result_url = models.URLField(_('result url'))
#     result_url_method = models.CharField(_('result url method'), max_length=4, choices=URL_METHODS)
# 
#     success_url = models.URLField(_('success url'))
#     fail_url = models.URLField(_('fail url'))
# 
#     class Meta:
#         verbose_name = 'продавец'
#         verbose_name_plural = 'продавцы'
#         db_table = 'payway_merchants'


# Path: payway/merchants/tests/http/tests.py
from django.test import TestCase
from simptools.wrappers.http import HttpClient
from payway.merchants.models import Merchant
from payway.merchants.tests.http.mocks import *

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


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



class MerchantHttpClientTestCase(TestCase):
    fixtures = [
        "payway_merchants_merchants.json",
        "payway_orders_orders.json",
    ]

    def setUp(self):
        self.merchant = Merchant.objects.get(uid=972855239)
        self.order = self.merchant.orders.all()[0]

    def tearDown(self):
        set_back_MerchantHttpClient_execute()

    def test_success_notify(self):
        mock_MerchantHttpClient_success_execute()
        response = MerchantHttpClient.notify(self.merchant, self.order)
        self.assertIn(RESPONSE_STATUS.OK, response)

    def test_connection_error(self):
        self.merchant.result_url = 'http://wrong12343434.com'
        mock_MerchantHttpClient_fail_execute()
        response = MerchantHttpClient.notify(self.merchant, self.order)

        self.assertEquals('', response)