# Path: payway/accounts/views/add_account.py
# class AddAccountView(TemplateView):
#     template_name = 'accounts/list.html'
# 
#     MESSAGES =  {
#         'WRONG_CURRENCY':  _('Currency not allowed!'),
#     }
# 
#     def get(self, request, *args, **kwargs):
#         currency = kwargs.get('currency')
#         if currency not in dict(CURRENCY_CHOICES).keys():
#             messages.warning(request, self.MESSAGES['WRONG_CURRENCY'])
#         else:
#             request.user.accounts.create(user=request.user, currency=currency)
#         return redirect('accounts_list')
# 
# Path: payway/utils/tests/base.py
# class BaseViewTestCase(AuthorizedViewTestCase):
# 
#     _url = ''
# 
#     def create_new_user_with_account(self):
#         password = 'abc123'
#         self.user = User.objects.create_user(
#             'user',
#             'user@example.com',
#             password,
#         )
#         self.account = self.user.accounts.create(user=self.user, currency='RUB')
#         self.account.add(Money(20, self.account.currency))
#         self.client_login(username=self.user.username, password=password)
# 
#     def assert_url_available(self):
#         response = self.client.get(self._url)
#         self.failUnlessEqual(response.status_code, 200)
# 
#     def assert_redirects(self, expected_url):
#         response = self.client.get(self._url)
#         self.assertRedirects(response, expected_url)
# 
#     def assert_has_message(self, response, message, level):
#         messages_list = CookieStorage(response)._decode(response.cookies['messages'].value)
#         self.assertIn(Message(level, message), messages_list)


from django.contrib.messages import constants
from django.core.urlresolvers import reverse
from payway.accounts.views.add_account import AddAccountView
from payway.utils.tests.base import BaseViewTestCase
# -*- coding: UTF-8 -*-

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


class AddAccountViewTests(BaseViewTestCase):

    def setUp(self):
        self.create_new_user_with_account()
        self._url = reverse("accounts_add_account", args=['RUB'])

    def test_get(self):
        accounts_count = self.user.accounts.count()
        self.assert_redirects(reverse('accounts_list'))
        self.assertEquals(accounts_count+1, self.user.accounts.count())

    def test_get_with_wrong_currency(self):
        url = reverse("accounts_add_account", args=['XXX'])
        response = self.client.get(url)
        self.assertRedirects(response, reverse('accounts_list'))

        self.assert_has_message(
            response,

# Path: payway/accounts/views/add_account.py
# class AddAccountView(TemplateView):
#     template_name = 'accounts/list.html'
# 
#     MESSAGES =  {
#         'WRONG_CURRENCY':  _('Currency not allowed!'),
#     }
# 
#     def get(self, request, *args, **kwargs):
#         currency = kwargs.get('currency')
#         if currency not in dict(CURRENCY_CHOICES).keys():
#             messages.warning(request, self.MESSAGES['WRONG_CURRENCY'])
#         else:
#             request.user.accounts.create(user=request.user, currency=currency)
#         return redirect('accounts_list')
# 
# Path: payway/utils/tests/base.py
# class BaseViewTestCase(AuthorizedViewTestCase):
# 
#     _url = ''
# 
#     def create_new_user_with_account(self):
#         password = 'abc123'
#         self.user = User.objects.create_user(
#             'user',
#             'user@example.com',
#             password,
#         )
#         self.account = self.user.accounts.create(user=self.user, currency='RUB')
#         self.account.add(Money(20, self.account.currency))
#         self.client_login(username=self.user.username, password=password)
# 
#     def assert_url_available(self):
#         response = self.client.get(self._url)
#         self.failUnlessEqual(response.status_code, 200)
# 
#     def assert_redirects(self, expected_url):
#         response = self.client.get(self._url)
#         self.assertRedirects(response, expected_url)
# 
#     def assert_has_message(self, response, message, level):
#         messages_list = CookieStorage(response)._decode(response.cookies['messages'].value)
#         self.assertIn(Message(level, message), messages_list)


# Path: payway/accounts/tests/views/add_account.py
from django.contrib.messages import constants
from django.core.urlresolvers import reverse
from payway.accounts.views.add_account import AddAccountView
from payway.utils.tests.base import BaseViewTestCase

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

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


class AddAccountViewTests(BaseViewTestCase):

    def setUp(self):
        self.create_new_user_with_account()
        self._url = reverse("accounts_add_account", args=['RUB'])

    def test_get(self):
        accounts_count = self.user.accounts.count()
        self.assert_redirects(reverse('accounts_list'))
        self.assertEquals(accounts_count+1, self.user.accounts.count())

    def test_get_with_wrong_currency(self):
        url = reverse("accounts_add_account", args=['XXX'])
        response = self.client.get(url)
        self.assertRedirects(response, reverse('accounts_list'))

        self.assert_has_message(
            response,

            message=AddAccountView.MESSAGES['WRONG_CURRENCY'],