# Path: tests/factories.py
# class ProjectFactory(factory.DjangoModelFactory):
#     title = factory.Sequence(lambda n: 'Testproject %s' % n)
#     slug = factory.Sequence(lambda n: 'test%s' % n)
#     goal = 200.00
#     currency = 'CHF'
#     start = timezone.now()
#     end = timezone.now() + timedelta(days=1)
# 
#     class Meta:
#         model = Project
# 
# class RewardFactory(factory.DjangoModelFactory):
#     description = factory.Sequence(lambda n: 'testreward%s' % n)
# 
#     class Meta:
#         model = Reward
# 
# class UserFactory(factory.DjangoModelFactory):
#     username = factory.Sequence(lambda n: 'user%s' % n)
#     email = factory.Sequence(lambda n: 'user%s@example.org' % n)
#     is_active = True
#     is_superuser = False
#     is_staff = False
#     # password 'test'
#     password = 'pbkdf2_sha256$10000$s9Ed0KfEQgTY$CsbbUpXaWk+8eAB+Oga2hBqD82kU4vl+QQaqr/wCZXY='
#     first_name = 'Hans'
#     last_name = 'Muster'
# 
#     class Meta:
#         model = get_user_model()
# 
# Path: zipfelchappe/app_settings.py
# CURRENCIES = getattr(settings, 'ZIPFELCHAPPE_CURRENCIES', ('CHF', 'EUR', 'USD'))
# DISQUS_SHORTNAME = getattr(settings, 'ZIPFELCHAPPE_DISQUS_SHORTNAME', None)
# PAGINATE_BY = getattr(settings, 'ZIPFELCHAPPE_PAGINATE_BY', 10)
# PAGINATE_BACKERS_BY = getattr(settings, 'ZIPFELCHAPPE_PAGINATE_BACKERS', 25)
# ALLOW_ANONYMOUS_PLEDGES = getattr(settings, 'ZIPFELCHAPPE_ALLOW_ANONYMOUS_PLEDGES', True)
# BACKER_PROFILE = getattr(settings, 'ZIPFELCHAPPE_BACKER_PROFILE', None)
# ROOT_URLS = getattr(settings, 'ZIPFELCHAPPE_URLS', 'zipfelchappe.urls')
# DEFAULT_IMAGE_URL = getattr(settings, 'ZIPFELCHAPPE_PLACEHOLDER_IMAGE_URL', '')
# USER_FIRST_NAME_FIELD = getattr(
#     settings, 'ZIPFELCHAPPE_USER_FIRST_NAME_FIELD', 'first_name')
# USER_LAST_NAME_FIELD = getattr(
#     settings, 'ZIPFELCHAPPE_USER_LAST_NAME_FIELD', 'last_name')
# USER_EMAIL_FIELD = getattr(
#     settings, 'ZIPFELCHAPPE_USER_EMAIL_FIELD', 'email')
# MAX_PROJECT_DURATION_DAYS = getattr(settings, 'ZIPFELCHAPPE_MAX_PROJECT_DURATION', 120)
# TERMS_URL = settings.ZIPFELCHAPPE_TERMS_URL
# MANAGERS = getattr(settings, 'ZIPFELCHAPPE_MANAGERS', settings.MANAGERS)


from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.tests.utils import skipIfCustomUser
from feincms.module.page.models import Page
from feincms.content.application.models import ApplicationContent, app_reverse
from tests.factories import ProjectFactory, RewardFactory, UserFactory
from zipfelchappe import app_settings
            project=self.project1,
            minimum=20.00,
            quantity=2
        )

        # Fresh Client for every test
        self.client = Client()

    def tearDown(self):
        mail.outbox = []

    # TODO: use the Django built-in function
    def assertRedirect(self, response, expected_url):
        """ Just check immediate redirect, don't follow target url """
        full_url = ('Location', 'http://testserver' + expected_url)
        self.assertIn('location', response._headers, 'Response from %s is not a redirect: %s'
                      % (expected_url, response.status_code))
        self.assertEqual(response._headers['location'], full_url,
                         'location expected: %s, actual: %s'
                         % (full_url, response._headers.get('location')))
        self.assertEqual(response.status_code, 302)

    def test_user_stays_logged_in(self):
        self.client.login(username=self.user, password='test')
        session_id = self.client.cookies['sessionid'].value
        response = self.client.get(self.project1.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(self.client.cookies['sessionid'].value, session_id)
        back_url = app_reverse('zipfelchappe_backer_create', app_settings.ROOT_URLS,
                               kwargs={"slug": self.project1.slug})

# Path: tests/factories.py
# class ProjectFactory(factory.DjangoModelFactory):
#     title = factory.Sequence(lambda n: 'Testproject %s' % n)
#     slug = factory.Sequence(lambda n: 'test%s' % n)
#     goal = 200.00
#     currency = 'CHF'
#     start = timezone.now()
#     end = timezone.now() + timedelta(days=1)
# 
#     class Meta:
#         model = Project
# 
# class RewardFactory(factory.DjangoModelFactory):
#     description = factory.Sequence(lambda n: 'testreward%s' % n)
# 
#     class Meta:
#         model = Reward
# 
# class UserFactory(factory.DjangoModelFactory):
#     username = factory.Sequence(lambda n: 'user%s' % n)
#     email = factory.Sequence(lambda n: 'user%s@example.org' % n)
#     is_active = True
#     is_superuser = False
#     is_staff = False
#     # password 'test'
#     password = 'pbkdf2_sha256$10000$s9Ed0KfEQgTY$CsbbUpXaWk+8eAB+Oga2hBqD82kU4vl+QQaqr/wCZXY='
#     first_name = 'Hans'
#     last_name = 'Muster'
# 
#     class Meta:
#         model = get_user_model()
# 
# Path: zipfelchappe/app_settings.py
# CURRENCIES = getattr(settings, 'ZIPFELCHAPPE_CURRENCIES', ('CHF', 'EUR', 'USD'))
# DISQUS_SHORTNAME = getattr(settings, 'ZIPFELCHAPPE_DISQUS_SHORTNAME', None)
# PAGINATE_BY = getattr(settings, 'ZIPFELCHAPPE_PAGINATE_BY', 10)
# PAGINATE_BACKERS_BY = getattr(settings, 'ZIPFELCHAPPE_PAGINATE_BACKERS', 25)
# ALLOW_ANONYMOUS_PLEDGES = getattr(settings, 'ZIPFELCHAPPE_ALLOW_ANONYMOUS_PLEDGES', True)
# BACKER_PROFILE = getattr(settings, 'ZIPFELCHAPPE_BACKER_PROFILE', None)
# ROOT_URLS = getattr(settings, 'ZIPFELCHAPPE_URLS', 'zipfelchappe.urls')
# DEFAULT_IMAGE_URL = getattr(settings, 'ZIPFELCHAPPE_PLACEHOLDER_IMAGE_URL', '')
# USER_FIRST_NAME_FIELD = getattr(
#     settings, 'ZIPFELCHAPPE_USER_FIRST_NAME_FIELD', 'first_name')
# USER_LAST_NAME_FIELD = getattr(
#     settings, 'ZIPFELCHAPPE_USER_LAST_NAME_FIELD', 'last_name')
# USER_EMAIL_FIELD = getattr(
#     settings, 'ZIPFELCHAPPE_USER_EMAIL_FIELD', 'email')
# MAX_PROJECT_DURATION_DAYS = getattr(settings, 'ZIPFELCHAPPE_MAX_PROJECT_DURATION', 120)
# TERMS_URL = settings.ZIPFELCHAPPE_TERMS_URL
# MANAGERS = getattr(settings, 'ZIPFELCHAPPE_MANAGERS', settings.MANAGERS)


# Path: tests/test_flow.py
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.tests.utils import skipIfCustomUser
from feincms.module.page.models import Page
from feincms.content.application.models import ApplicationContent, app_reverse
from tests.factories import ProjectFactory, RewardFactory, UserFactory
from zipfelchappe import app_settings

            project=self.project1,
            minimum=20.00,
            quantity=2
        )

        # Fresh Client for every test
        self.client = Client()

    def tearDown(self):
        mail.outbox = []

    # TODO: use the Django built-in function
    def assertRedirect(self, response, expected_url):
        """ Just check immediate redirect, don't follow target url """
        full_url = ('Location', 'http://testserver' + expected_url)
        self.assertIn('location', response._headers, 'Response from %s is not a redirect: %s'
                      % (expected_url, response.status_code))
        self.assertEqual(response._headers['location'], full_url,
                         'location expected: %s, actual: %s'
                         % (full_url, response._headers.get('location')))
        self.assertEqual(response.status_code, 302)

    def test_user_stays_logged_in(self):
        self.client.login(username=self.user, password='test')
        session_id = self.client.cookies['sessionid'].value
        response = self.client.get(self.project1.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(self.client.cookies['sessionid'].value, session_id)
        back_url = app_reverse('zipfelchappe_backer_create', app_settings.ROOT_URLS,
                               kwargs={"slug": self.project1.slug})

        authenticate_url = app_reverse('zipfelchappe_backer_authenticate', app_settings.ROOT_URLS)