from __future__ import print_function
from django.test import TestCase
from django.contrib.auth.models import User
from imager_images.models import Photo
from django.conf import settings


import factory


class UserFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = User
        django_get_or_create = ('username',)

    username = 'Bob'


class PhotoFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = Photo

    profile = UserFactory.create(username='Bobby').ImagerProfile
    photo = 'picture.jpeg'

#class AlbumFactory(factory.django.DjangoModelFactory):
#
#    class Meta:
#        model = Album
#
#    profile = UserFactory.create(username='Freddy').ImagerProfile


class TestHomepageViews(TestCase):

    STOCKPHOTO_URL = '/media/default_stock_photo_640_360.jpg'

    def setUp(self):
        self.bob = UserFactory.create()
        self.alice = UserFactory.create(username='Alice')
        self.bobphoto = PhotoFactory.create(profile=self.bob.ImagerProfile)
        self.publicbobphoto = PhotoFactory.create(profile=self.bob.ImagerProfile,
                                                  published='pb')
        #self.bobphoto2 = PhotoFactory.create(profile=self.bob.ImagerProfile)
        #self.alicephoto = PhotoFactory.create(profile=self.alice.ImagerProfile)
        #self.freddyalbum = AlbumFactory.create()
        #self.bobalbum = AlbumFactory.create(profile=self.bob.ImagerProfile)
        #self.bobalbum2 = AlbumFactory.create(profile=self.bob.ImagerProfile)

    def test_empty_url_finds_home_page(self):
        # import pdb; pdb.set_trace()
        response = self.client.get('/')
        self.assertTemplateUsed(response, 'index.html')

    def test_home_page_photo_is_user_photo_or_default(self):
        response = self.client.get('/')
        self.assertEqual(
            response.context['random_photo'],
            self.publicbobphoto.photo.url)

    def test_home_page_photo_is_stock_if_no_user_photos(self):
        self.publicbobphoto.delete()
        response = self.client.get('/')
        self.assertEqual(
            response.context['random_photo'],
            self.STOCKPHOTO_URL)

@@ -180,16 +180,47 @@
 ettings%0A
+from django.test import Client%0A
 %0A%0Aimport
@@ -2198,8 +2198,671 @@
 TO_URL)%0A
+%0A%0Aclass TestRegistrationViews(TestCase):%0A%0A    def setUp(self):%0A        self.client = Client()%0A%0A    def test_register_page_works(self):%0A        response = self.client.get('/accounts/register/')%0A        self.assertEqual(response.status_code, 200)%0A%0A    def test_register_new_user(self):%0A        self.client.post('/accounts/register/',%0A                         %7B'username': 'bobby',%0A                          'email': 'bobby@example.com',%0A                          'password1': 'test',%0A                          'password2': 'test'%7D%0A                         )%0A        self.assertEqual(len(User.objects.all()), 1)%0A        %0A        %0A        %0A        %0A        %0A        %0A

Test for new user registration.