Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjp93 committed Sep 27, 2024
1 parent e58fad1 commit 4775881
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion news/tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import io

from PIL import Image
import pytest
from django.db.models import Q
from django.contrib.auth.models import Group, Permission
Expand Down Expand Up @@ -98,7 +100,14 @@ def moderator_user(db, make_user):
# we could use `tp.make_user` but we need this fix to be released
# https://github.com/revsys/django-test-plus/issues/199
user = make_user(email="[email protected]", perms=["news.*"])
user.image = "test.png"

file = io.BytesIO()
filename = "test.png"
file.name = filename
image = Image.new("RGBA", size=(100, 100), color=(155, 0, 0))
image.save(file, 'png')
file.seek(0)
user.image.save(filename, file)
user.save()
return user

Expand Down
13 changes: 12 additions & 1 deletion news/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import date, timedelta
from io import BytesIO

from PIL import Image
import pytest
from django.core import mail
from django.utils.text import slugify
Expand Down Expand Up @@ -377,7 +378,17 @@ def test_news_create_requirements(
url = tp.reverse(url_name)

# Setup user based on parameters
user.image = "test_image.jpg" if has_image else None
if has_image:
file = BytesIO()
filename = "test_image.jpg"
file.name = filename
image = Image.new("RGB", size=(100, 100), color=(155, 0, 0))
image.save(file, 'jpeg')
file.seek(0)
user.image.save(filename, file)
else:
user.image = None

user.first_name = "Test" if has_first_name else ""
user.last_name = "User" if has_last_name else ""
user.save()
Expand Down

0 comments on commit 4775881

Please sign in to comment.