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
def new_photo(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() return photo
def upload_new_photo(request): user = User.objects.get(pk=request.user.id) if request.method == 'GET': new_photo_form = NewPhotoForm() return render(request, 'newphoto.html', context={ 'new_photo_form': new_photo_form }) elif request.method == 'POST': new_photo = NewPhotoForm(request.POST, request.FILES) # new_photo.clean() photo = Photo(title=new_photo.data['title'], description=new_photo.data['description'], img_file=request.FILES['img_file']) photo.save() user.photos.add(photo) return redirect('/images/library/')
def test_add_album_submission_changes_owner(self): """Test that submitting a new album changes the owner.""" test_user = self.add_test_user() self.client.force_login(test_user) photo = Photo() photo.owner = test_user.profile photo.save() self.client.post( "/images/albums/add/", { 'title': 'Test Album', 'description': 'Test Description for album', 'published': 'PUBLIC', 'photos': [photo.id], 'cover_photo': '' }) album = Album.public.first() self.assertTrue(album.owner == test_user.profile)
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()
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)
def test_photo_created_without_title(self): """Photo created without a title should should be empty string.""" photo = Photo() photo.user = User.objects.get(username='******') photo.save() self.assertTrue(photo.title == '')