Example #1
0
 def setUp(self):
     """Setup for PhotoTests."""
     settings.MEDIA_ROOT = tempfile.mkdtemp()
     self.client = Client()
     someuser = User(username='******', password='******')
     self.someuser = someuser
     someuser.save()
     some_pro = someuser.profile
     self.some_pro = some_pro
     some_pro.save()
     album = Album(user=some_pro, title='Some Title')
     album.cover = Sup(name='bad_photo.jpg',
                       content=open('media/images/louie.png', 'rb').read(),
                       content_type='image/png')
     album.save()
     for i in range(10):
         photo = PhotoFactory.build()
         photo.user = some_pro
         photo.imgfile = Sup(name='bad_photo.jpg',
                             content=open('media/images/louie.png',
                                          'rb').read(),
                             content_type='image/png')
         photo.save()
         album.photo.add(photo)
     self.album = album
Example #2
0
    def setUp(self):
        """Setup."""
        self.client = Client()
        self.user1 = RandomUserFactory.build()
        self.user1.set_password('pirate ninja')
        self.user1.save()
        self.user2 = RandomUserFactory.build()
        self.user2.set_password('blue pineapple')
        self.user2.save()
        self.album1 = Album(title='family', owner=self.user1)
        self.album2 = Album(title='friends', owner=self.user1)
        self.photo1 = PhotoFactory.create(title='photo 1',
                                          owner=self.user1)
        self.photo2 = PhotoFactory.create(title='photo 2',
                                          owner=self.user1)
        self.album3 = Album(title='cats', owner=self.user2)
        self.album4 = Album(title='dogs', owner=self.user2)
        self.photo3 = PhotoFactory.create(title='photo 3',
                                          owner=self.user2)
        self.photo4 = PhotoFactory.create(title='photo 4',
                                          owner=self.user2)
        self.album1.save()
        self.album2.save()
        self.photo1.save()
        self.photo2.save()
        self.photo1.albums.add(self.album1)

        self.album3.save()
        self.album4.save()
        self.photo3.save()
        self.photo4.save()
        self.photo3.albums.add(self.album3)
        self.photo4.albums.add(self.album4)
Example #3
0
    def setUp(self):
        """Setup."""
        settings.MEDIA_ROOT = tempfile.mkdtemp()
        self.c = Client()

        jimbo = User(username='******')
        jimbo.set_password('p@ssw0rd')
        jimbo.save()
        jimbo.profile.location = "Buffalo"
        jimbo.profile.save()
        album = Album(user=jimbo.profile, title='The Album')
        album.cover = Sup(name='this_is_fine.png',
                          content=open('media/images/this_is_fine.png',
                                       'rb').read(),
                          content_type='image/png')
        album.save()
        for i in range(30):
            photo = Photo(user=jimbo.profile, title=f'Pic{i}')
            photo.image = Sup(name='this_is_fine.png',
                              content=open('media/images/this_is_fine.png',
                                           'rb').read(),
                              content_type='image/png')
            photo.save()
            album.photo.add(photo)
        self.user = jimbo
        self.album = album
Example #4
0
 def setUp(self):
     """Setup."""
     self.user1 = RandomUserFactory()
     self.user1.save()
     self.album1 = Album(title='family', owner=self.user1)
     self.album2 = Album(title='friends', owner=self.user1)
     self.photo1 = PhotoFactory.create(title='photo 1',
                                       owner=self.user1)
     self.photo2 = PhotoFactory.create(title='photo 2',  
                                       owner=self.user1)
     self.album1.save()
     self.album2.save()
     self.photo1.save()
     self.photo2.save()
     self.photo1.albums.add(self.album1)
 def setUp(self):
     """Setup"""
     larry = User(username='******', password='******')
     larry.save()
     l_profile = larry.profile
     l_profile.location = "Denver"
     l_profile.save()
     album = Album(user=l_profile, title='Denver City')
     album.save()
     for i in range(20):
         photo = PhotoFactory.build()
         photo.user = l_profile
         photo.save()
         album.photos.add(photo)
     self.album = album
Example #6
0
 def setUp(self):
     """Setup."""
     roberto = User(username='******', password='******')
     roberto.save()
     r_profile = roberto.profile
     r_profile.location = "Buffalo"
     r_profile.save()
     album = Album(user=User.objects.get(username='******'),
                   title='The Album')
     album.save()
     for i in range(30):
         photo = PhotoFactory.build()
         photo.user = User.objects.get(username='******')
         photo.save()
         album.photo.add(photo)
     self.album = album
Example #7
0
class LibraryViewTests(TestCase):
    """Test the Library view."""

    def setUp(self):
        """Setup."""
        self.client = Client()
        self.user1 = RandomUserFactory.build()
        self.user1.set_password('pirate ninja')
        self.user1.save()
        self.user2 = RandomUserFactory.build()
        self.user2.set_password('blue pineapple')
        self.user2.save()
        self.album1 = Album(title='family', owner=self.user1)
        self.album2 = Album(title='friends', owner=self.user1)
        self.photo1 = PhotoFactory.create(title='photo 1',
                                          owner=self.user1)
        self.photo2 = PhotoFactory.create(title='photo 2',
                                          owner=self.user1)
        self.album3 = Album(title='cats', owner=self.user2)
        self.album4 = Album(title='dogs', owner=self.user2)
        self.photo3 = PhotoFactory.create(title='photo 3',
                                          owner=self.user2)
        self.photo4 = PhotoFactory.create(title='photo 4',
                                          owner=self.user2)
        self.album1.save()
        self.album2.save()
        self.photo1.save()
        self.photo2.save()
        self.photo1.albums.add(self.album1)

        self.album3.save()
        self.album4.save()
        self.photo3.save()
        self.photo4.save()
        self.photo3.albums.add(self.album3)
        self.photo4.albums.add(self.album4)

    def test_login_decorator(self):
        """Test if login decorator behaves as expected."""
        response = self.client.get('/images/library/')
        self.assertEqual(response.status_code, 302)
        self.client.login(username=self.user1.username, password='******')
        response = self.client.get('/images/library/')
        self.assertEqual(response.status_code, 200)

    def test_can_see_albums_owned(self):
        """Test if the user can see albums."""
        self.client.login(username=self.user1.username, password='******')
        response = self.client.get('/images/library/')
        self.assertEqual(response.context['user'].albums.first().owner.username, self.user1.username)

    def test_user1_no_see_user2_album(self):
        """Test that user1 cannot see user2 albums."""
        self.client.login(username=self.user1.username, password='******')
        response = self.client.get('/images/library/')
        self.assertNotIn(self.user2.photos.first().title, response.rendered_content)
Example #8
0
 def setUp(self):
     """Setup."""
     jimbo = User(username='******',
                  password='******')
     jimbo.save()
     j_profile = jimbo.profile
     j_profile.location = "Buffalo"
     j_profile.save()
     album = Album(user=j_profile, title='The Album')
     album.save()
     for i in range(30):
         photo = PhotoFactory.build()
         photo.user = j_profile
         # photo = Photo(user=j_profile, title=f'Pic{i}')
         photo.save()
         album.photos.add(photo)
     self.album = album
Example #9
0
def new_album(username, password):
    """Custom function to create ImagerProfile with given user."""

    user = User(username=username, password=password)
    user.save()

    photo = Photo(user=user,
                  title='Dank Meme',
                  image='Puppy',
                  description='Dank ass meme about puppies')
    photo.save()

    album = Album(user=user,
                  title='Dank Memes',
                  description='Public Dank Memes',
                  cover=photo)
    album.save()
    return album
Example #10
0
    def setUp(self):
        """Generate users using Factory Boiiii."""
        # os.system('mv ' + media + '/images/ ' + media + '/saved_images/')
        # os.system('mv ' + media + '/cover_images/ ' + media + '/saved_cover_images/')

        self.photos = []
        user = FactoryUserBoi.create()
        user.set_password('percentsignbois')
        user.save()

        user.profile.location = "Seattle"
        user.profile.save()

        cover_img = SimpleUploadedFile(name='sample_meme.jpg',
                                       content=open(
                                           os.path.join(
                                               BASE_DIR,
                                               'imagersite',
                                               'static',
                                               'sample_meme.jpg',
                                           ), 'rb').read(),
                                       content_type='image/jpeg')

        users_album = Album(user=user,
                            title="Albumerino",
                            published="Public",
                            cover=cover_img)
        users_album.save()

        for i in range(3):
            photo = FactoryPhotoBoi.build()
            photo.user = user
            photo.save()
            users_album.photos.add(photo)
            self.photos.append(photo)

        self.album = users_album
        self.profile = user.profile
        self.user = user
Example #11
0
 def setUp(self):
     """Set up fixture for testing."""
     user = User(username='******', email='*****@*****.**')
     user.set_password('test_pass')
     user.save()
     album = Album()
     album.id = 0
     album.user = user
     album.title = 'Hello World Around the World'
     album.description = 'First Album'
     for _ in range(10):
         photo = PhotoFactory.build()
         photo.user = user
         photo.description = 'My {} photo'.format(_)
         photo.image = 'http://cdn.spacetelescope.org/archives/images/screen/opo0328a.jpg'
         photo.save()
         album.photos.add(photo)
     album.save()
Example #12
0
    def setUp(self):
        """Setup users, images, albums, auth & unauth clients."""
        self.test_user1 = User.objects.create_user('testuser',
                                                   '*****@*****.**',
                                                   'testpassword')
        self.test_user1.save()
        self.image1 = PhotoFactory.create(title='image 1',
                                          owner=self.test_user1,
                                          published='Public')
        self.image2 = PhotoFactory.create(title='image 2',
                                          owner=self.test_user1)
        self.image1.save()
        self.image2.save()
        self.album1 = Album(title='My Album', owner=self.test_user1,
                            cover=self.image1.photo)
        self.album1.save()

        self.unauth = Client()

        self.auth = Client()
        self.auth.login(username='******', password='******')
Example #13
0
    def setUp(self):  # like a fixture, run for every time. To run once do class setUp(self):
        """Initiate with two users in the db, one activce and one not."""
        user = UserFactory.build()
        user.username = '******'
        user.email = '*****@*****.**'
        user.set_password('password')
        user.save()
        album = Album(title='Album1', owner=user.profile)
        album.save()  # to access this: user.profile.albums.first()
        photo = Photo(title='Photo1', owner=user.profile)
        photo.save()  # to access this: user.profile.photos.first()
        album.photos.add(photo)  # auto save after adding

        user = UserFactory.build()
        user.username = '******'
        user.email = '*****@*****.**'
        user.set_password('password')
        user.save()
        album = Album(title='Album2', owner=user.profile)
        album.save()  # to access this: user.profile.albums.first()
        photo = Photo(title='Photo2', owner=user.profile)
        photo.save()  # to access this: user.profile.photos.first()
        album.photos.add(photo)
Example #14
0
    def setUp(self):
        """50 users in database last one has profile."""
        image = SimpleUploadedFile(
            name='example.jpg',
            content=open(os.path.join(BASE_DIR,
                                      'static/imagersite',
                                      'photo.jpg'), 'rb').read(),
            content_type='image/jpeg')

        user = User(password='******', username='******')
        user.save()
        user.profile.location = 'Seattle'
        user.profile.website = 'example.com'
        user.profile.fee = 0.0
        user.profile.phone = None
        user.profile.camera = 'NK'
        user.profile.services = 'P'
        user.profile.photo_styles = 'O'
        user.profile.save()

        photo = Photo(user=user.profile,
                      image=image,
                      title='photo title',
                      description='description of photo',
                      date_published='1994-10-12',
                      published='PU')
        photo.save()

        album = Album(user=user.profile,
                      title='album title',
                      description='description of album',
                      date_published='1994-10-12',
                      published='PU')
        album.save()
        album.photo.add(photo)
        album.save()
Example #15
0
class TestProfile(TestCase):

    def setUp(self):
        """Setup users, images, albums, auth & unauth clients."""
        self.test_user1 = User.objects.create_user('testuser',
                                                   '*****@*****.**',
                                                   'testpassword')
        self.test_user1.save()
        self.image1 = PhotoFactory.create(title='image 1',
                                          owner=self.test_user1,
                                          published='Public')
        self.image2 = PhotoFactory.create(title='image 2',
                                          owner=self.test_user1)
        self.image1.save()
        self.image2.save()
        self.album1 = Album(title='My Album', owner=self.test_user1,
                            cover=self.image1.photo)
        self.album1.save()

        self.unauth = Client()

        self.auth = Client()
        self.auth.login(username='******', password='******')

    # def tearDown(self):
        # """Delete temporary pictures."""
        # os.remove('{}{}'.format(BASE_DIR, self.image1.photo.url))
        # os.remove('{}{}'.format(BASE_DIR, self.image2.photo.url))

    def test_unauth_home_response(self):
        """Test anyone can get to home page."""
        response = self.unauth.get('/')
        self.assertEquals(response.status_code, 200)

    def test_unauth_login_response(self):
        response = self.unauth.get('/accounts/login')
        self.assertEquals(response.status_code, 301)

    def test_unauth_register_response(self):
        """Test anyone can get to register page."""
        response = self.unauth.get('/accounts/register/')
        self.assertEquals(response.status_code, 200)

    def test_public_image_in_response(self):
        """Verify public image shows up on homepage."""
        response = self.unauth.get('/')
        self.assertTrue(self.image1.photo.url in str(response.content))

    def test_private_image_not_in_response(self):
        """Verify private image does not show up on home page."""
        response = self.unauth.get('/')
        self.assertTrue(self.image2.photo.url not in str(response.content))

    def test_profile_logged_out(self):
        """Redirect upon attempting to get to profile page if logged out."""
        response = self.unauth.get('/accounts/profile')
        self.assertTrue(response.status_code == 302)

    def test_profile_logged_in(self):
        """Access to profile page if logged in."""
        response = self.auth.get('/accounts/profile')
        self.assertEquals(response.status_code, 200)

    def test_profile_image_count(self):
        """Photo count shown on profile page."""
        response = self.auth.get('/accounts/profile')
        self.assertTrue('Total Photos: 2' in str(response.content))

    def test_profile_album_count(self):
        """Album count shown on profile page."""
        response = self.auth.get('/accounts/profile')
        self.assertTrue('Total Albums: 1' in str(response.content))

    def test_library_logged_out(self):
        """Redirect if unauthorized on library page."""
        response = self.unauth.get('/images/library')
        self.assertEquals(response.status_code, 302)

    def test_library_logged_in(self):
        """Access to library page if logged in."""
        response = self.auth.get('/images/library')
        self.assertEquals(response.status_code, 200)

    def test_library_album_display(self):
        """Verify album titles display in library."""
        response = self.auth.get('/images/library')
        self.assertTrue('My Album' in str(response.content))

    def test_library_image_display(self):
        """Image titles display in image library."""
        response = self.auth.get('/images/library')
        self.assertTrue('image 1' in str(response.content))

    def test_auth_public_image_view(self):
        """Access granted if logged in as user to view private picture."""
        user_id = self.test_user1.id
        image_id = self.image2.id
        response = self.auth.get('/images/image/{}/{}'.format(user_id,
                                                              image_id))
        self.assertEquals(response.status_code, 200)

    def test_unauth_public_image_view(self):
        """Access denied if not authorized to view private picture."""
        user_id = self.test_user1.id
        image_id = self.image2.id
        response = self.unauth.get('/images/image/{}/{}'.format(user_id,
                                                                image_id))
        self.assertEquals(response.status_code, 401)
Example #16
0
class TestPhotoAndAlbum(TestCase):
    """Album test case."""

    def setUp(self):
        """Setup."""
        self.user1 = RandomUserFactory()
        self.user1.save()
        self.album1 = Album(title='family', owner=self.user1)
        self.album2 = Album(title='friends', owner=self.user1)
        self.photo1 = PhotoFactory.create(title='photo 1',
                                          owner=self.user1)
        self.photo2 = PhotoFactory.create(title='photo 2',  
                                          owner=self.user1)
        self.album1.save()
        self.album2.save()
        self.photo1.save()
        self.photo2.save()
        self.photo1.albums.add(self.album1)

    def test_album_exists(self):
        """Test that when an album is created it is an album."""
        self.assertIsInstance(self.album1, Album)

    def test_photo_exists(self):
        """Test photo has been created."""
        self.assertIsInstance(self.photo1, Photo)

    def test_album_title(self):
        """Test album has title."""
        self.assertEquals(self.album1.title, 'family')

    def test_photo_title(self):
        """Test photo has title."""
        self.assertEquals(self.photo1.title, 'photo 1')

    def test_album_default_description(self):
        """Test album default description is empty string."""
        self.assertEquals(self.album1.description, '')

    def test_photo_default_description(self):
        """Test photo default description is empty string."""
        self.assertEquals(self.photo1.description, '')

    # test photo dates
    def test_photo_uploaded_date(self):
        """Test that the photos uploaded date is working."""
        date_uploaded = self.photo1.date_uploaded
        compare_date = timezone.now()
        self.assertAlmostEqual(date_uploaded, compare_date,
                               delta=timedelta(seconds=10))

    def test_photo_date_modified(self):
        """Test to verify the date changes upon modification of photo."""
        initial = self.photo1.date_modified
        self.assertEquals(initial, self.photo1.date_modified)
        self.photo1.title = 'new title'
        self.photo1.save()
        self.assertNotEqual(initial, self.photo1.date_modified)

    def test_date_published(self):
        """Test that the date published is within acceptable 10 sec."""
        date_published = self.photo1.date_uploaded
        compare_date = timezone.now()
        self.assertAlmostEqual(date_published, compare_date,
                               delta=timedelta(seconds=10))

    def test_photo_published(self):
        """Test that published choices behave as expected."""
        # CHOICES = ['private', 'shared', 'public']
        self.photo1.published = CHOICES[0]
        self.assertEquals(self.photo1.published, 'private')
        self.photo1.published = CHOICES[1]
        self.assertEquals(self.photo1.published, 'shared')
        self.photo1.published = CHOICES[2]
        self.assertEquals(self.photo1.published, 'public')


    # test album dates
    def test_album_created_date(self):
        """Test that the photos uploaded date is working."""
        date_created = self.album1.date_created
        compare_date = timezone.now()
        self.assertAlmostEqual(date_created, compare_date,
                               delta=timedelta(seconds=10))

    def test_album_date_modified(self):
        """Test to verify the date changes upon modification of album."""
        initial = self.photo1.date_modified
        self.assertEquals(initial, self.photo1.date_modified)
        self.photo1.title = 'new title'
        self.photo1.save()
        self.assertNotEqual(initial, self.photo1.date_modified)

    def test_album_date_published(self):
        """Test that album date published is within acceptable 10 sec."""
        self.album1.date_published = timezone.now()
        date_published = self.album1.date_published
        compare_date = timezone.now()
        self.assertAlmostEqual(date_published, compare_date,
                               delta=timedelta(seconds=10))

    def test_album_published(self):
        """Test that album published choices behave as expected."""
        # CHOICES = ['private', 'shared', 'public']
        self.album1.published = CHOICES[0]
        self.assertEquals(self.album1.published, 'private')
        self.album1.published = CHOICES[1]
        self.assertEquals(self.album1.published, 'shared')
        self.album1.published = CHOICES[2]
        self.assertEquals(self.album1.published, 'public')

    def test_photo_in_album(self):
        """Test to verify that photo can be in album."""
        self.assertEquals(self.album1.photos.all()[0], self.photo1)

    def test_photos_have_owner(self):
        """Test to verify that photos have owners."""
        self.assertEquals(self.photo1.owner, self.user1)

    def test_albums_have_owner(self):
        """Test to verify that albums have owners."""
        self.assertEquals(self.album1.owner, self.user1)

    def test_user_has_albums(self):
        """Test to verify that user has albums."""
        self.assertEquals(self.user1.albums.all().count(), 2)

    def test_user_has_photos(self):
        """Test to verify that user has photos."""
        self.assertEquals(self.user1.photos.all().count(), 2)

    def test_photo_has_photo(self):
        """Test to verify photo has been created with an photo."""
        self.assertIsInstance(self.photo1.img_file, ImageFieldFile)