Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

44 wiersze
1.0 KiB

  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. for size in settings.IMAGE_SIZES.keys():
  26. Thumbnail.objects.get_or_create_at_size(image.pk, size)
  27. return image
  28. def create_pin(user, image, tags):
  29. pin = Pin.objects.create(submitter=user, image=image)
  30. pin.tags.set(*tags)
  31. return pin