forked from mirrors/bookwyrm
Fix tests
This commit is contained in:
parent
973b23856c
commit
e07672fff1
4 changed files with 38 additions and 32 deletions
|
@ -49,7 +49,7 @@ EMAIL_USE_SSL=false
|
||||||
# or use_dominant_color_light / use_dominant_color_dark
|
# or use_dominant_color_light / use_dominant_color_dark
|
||||||
PREVIEW_BG_COLOR=use_dominant_color_light
|
PREVIEW_BG_COLOR=use_dominant_color_light
|
||||||
# Change to #FFF if you use use_dominant_color_dark
|
# Change to #FFF if you use use_dominant_color_dark
|
||||||
PREVIEW_TEXT_COLOR=#363636
|
PREVIEW_TEXT_COLOR="#363636"
|
||||||
PREVIEW_IMG_WIDTH=1200
|
PREVIEW_IMG_WIDTH=1200
|
||||||
PREVIEW_IMG_HEIGHT=630
|
PREVIEW_IMG_HEIGHT=630
|
||||||
PREVIEW_DEFAULT_COVER_COLOR=#002549
|
PREVIEW_DEFAULT_COVER_COLOR="#002549"
|
|
@ -49,7 +49,7 @@ EMAIL_USE_SSL=false
|
||||||
# or use_dominant_color_light / use_dominant_color_dark
|
# or use_dominant_color_light / use_dominant_color_dark
|
||||||
PREVIEW_BG_COLOR=use_dominant_color_light
|
PREVIEW_BG_COLOR=use_dominant_color_light
|
||||||
# Change to #FFF if you use use_dominant_color_dark
|
# Change to #FFF if you use use_dominant_color_dark
|
||||||
PREVIEW_TEXT_COLOR=#363636
|
PREVIEW_TEXT_COLOR="#363636"
|
||||||
PREVIEW_IMG_WIDTH=1200
|
PREVIEW_IMG_WIDTH=1200
|
||||||
PREVIEW_IMG_HEIGHT=630
|
PREVIEW_IMG_HEIGHT=630
|
||||||
PREVIEW_DEFAULT_COVER_COLOR=#002549
|
PREVIEW_DEFAULT_COVER_COLOR="#002549"
|
|
@ -21,25 +21,29 @@ class EditUserViews(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
self.local_user = models.User.objects.create_user(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"mouse@local.com",
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@mouse.mouse",
|
"mouse@local.com",
|
||||||
"password",
|
"mouse@mouse.mouse",
|
||||||
local=True,
|
"password",
|
||||||
localname="mouse",
|
local=True,
|
||||||
)
|
localname="mouse",
|
||||||
self.rat = models.User.objects.create_user(
|
)
|
||||||
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
self.rat = models.User.objects.create_user(
|
||||||
)
|
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
|
||||||
self.book = models.Edition.objects.create(title="test")
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
|
||||||
models.ShelfBook.objects.create(
|
|
||||||
book=self.book,
|
|
||||||
user=self.local_user,
|
|
||||||
shelf=self.local_user.shelf_set.first(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
models.SiteSettings.objects.create()
|
with patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay"):
|
||||||
|
self.book = models.Edition.objects.create(title="test")
|
||||||
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
book=self.book,
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
|
||||||
|
@ -64,11 +68,12 @@ class EditUserViews(TestCase):
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
self.assertIsNone(self.local_user.name)
|
self.assertIsNone(self.local_user.name)
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
view(request)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
view(request)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
self.assertEqual(self.local_user.name, "New Name")
|
self.assertEqual(self.local_user.name, "New Name")
|
||||||
self.assertEqual(self.local_user.email, "wow@email.com")
|
self.assertEqual(self.local_user.email, "wow@email.com")
|
||||||
|
|
||||||
|
@ -88,11 +93,12 @@ class EditUserViews(TestCase):
|
||||||
request = self.factory.post("", form.data)
|
request = self.factory.post("", form.data)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch(
|
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
with patch(
|
||||||
) as delay_mock:
|
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||||
view(request)
|
) as delay_mock:
|
||||||
self.assertEqual(delay_mock.call_count, 1)
|
view(request)
|
||||||
|
self.assertEqual(delay_mock.call_count, 1)
|
||||||
self.assertEqual(self.local_user.name, "New Name")
|
self.assertEqual(self.local_user.name, "New Name")
|
||||||
self.assertEqual(self.local_user.email, "wow@email.com")
|
self.assertEqual(self.local_user.email, "wow@email.com")
|
||||||
self.assertIsNotNone(self.local_user.avatar)
|
self.assertIsNotNone(self.local_user.avatar)
|
||||||
|
|
|
@ -135,4 +135,4 @@ class UserViews(TestCase):
|
||||||
with patch("bookwyrm.views.user.is_api_request") as is_api:
|
with patch("bookwyrm.views.user.is_api_request") as is_api:
|
||||||
is_api.return_value = False
|
is_api.return_value = False
|
||||||
with self.assertRaises(Http404):
|
with self.assertRaises(Http404):
|
||||||
view(request, "rat")
|
view(request, "rat")
|
||||||
|
|
Loading…
Reference in a new issue