You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
1001 B

  1. from django.conf import settings
  2. from django.core.files.images import ImageFile
  3. from django_images.models import Thumbnail
  4. from taggit.models import Tag
  5. from core.models import Pin, Image
  6. from users.models import User
  7. TEST_IMAGE_PATH = 'logo.png'
  8. def create_user(username):
  9. user, _ = User.objects.get_or_create(
  10. username='user_{}'.format(username),
  11. defaults={
  12. "email": 'user_{}@example.com'.format(username)
  13. }
  14. )
  15. user.set_password("password")
  16. user.save()
  17. return user
  18. def create_tag(name):
  19. return Tag.objects.get_or_create(
  20. name='tag_{}'.format(name),
  21. slug='tag_{}'.format(name),
  22. )
  23. def create_image():
  24. image = Image.objects.create(image=ImageFile(open(TEST_IMAGE_PATH, 'rb')))
  25. Thumbnail.objects.get_or_create_at_sizes(image, settings.IMAGE_SIZES.keys())
  26. return image
  27. def create_pin(user, image, tags):
  28. pin = Pin.objects.create(submitter=user, image=image)
  29. pin.tags.set(*tags)
  30. return pin