Add integration tests (#20)

* Adding integration tests with inlines

* Adding more tests

* FIx make file

* Setup CI build matrix to work with integration tests

* Try again

* Fix workflow synctax

* Clean up workflow

* Format and some lint stuff

* Try codecov

* yml

* More Testing

* Minor lint things

* Update

* Try again for codecov

* Updates

* Try?

* Ignore quotes

* Exclude test project

* try this?

* checkout required

* Rename

* clean up configs

* Fix

* Allow to fail

* ignores

* FInish the integration tests for cache

* Fix workflow yml

* fix

* Try up again

* TRy again

* Fix

* Fix

* Fix tests

Co-authored-by: Thu Trang Pham <thu@joinmodernhealth.com>
This commit is contained in:
Thu Trang Pham
2021-03-05 19:54:01 -08:00
committed by GitHub
parent 4f50c63f7b
commit ad7409b567
31 changed files with 677 additions and 185 deletions
+10 -4
View File
@@ -8,6 +8,12 @@ You seem concerned about the stability and reliability of this package. You're p
So if you want to include this package in your production codebase, be aware that AdminConfirmMixin works best with simple unmodified ModelAdmins.
# Probable Issues
These are some areas which might/probably have issues that are not currently tested. Use at your own risk!
- [ ] Saving file/image changes on inlines when confirming change on parent model
## Save Options
- [x] Save
@@ -71,10 +77,10 @@ Confirmation on inline changes is not a current feature of this project.
Confirmation on add/change of ModelAdmin that includes inlines needs to be tested. Use AdminConfirmMixin with ModelAdmin containing inlines at your own risk.
- [ ] .inlines
- [ ] .get_inline_instances()
- [ ] .get_inlines() (New in Django 3.0)
- [ ] .get_formsets_with_inlines()
- [x] .inlines
- [x] .get_inline_instances()
- [x] .get_inlines() (New in Django 3.0)
- [ ] .get_formsets_with_inlines() ???
#### Options for inlines
+26 -7
View File
@@ -1,6 +1,12 @@
import socket
from django.core.cache import cache
from django.test import TestCase, RequestFactory
from django.contrib.auth.models import User
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class AdminConfirmTestCase(TestCase):
"""
@@ -62,16 +68,10 @@ class AdminConfirmTestCase(TestCase):
self.assertIn("apple", rendered_content)
import socket
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class AdminConfirmIntegrationTestCase(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.host = socket.gethostbyname(socket.gethostname())
cls.selenium = webdriver.Remote(
command_executor="http://selenium:4444/wd/hub",
@@ -79,6 +79,25 @@ class AdminConfirmIntegrationTestCase(LiveServerTestCase):
)
super().setUpClass()
def setUp(self):
self.superuser = User.objects.create_superuser(
username="super", email="super@email.org", password="pass"
)
self.client.force_login(self.superuser)
cookie = self.client.cookies["sessionid"]
self.selenium.get(
self.live_server_url + "/admin/"
) # selenium will set cookie domain based on current page domain
self.selenium.add_cookie(
{"name": "sessionid", "value": cookie.value, "secure": False, "path": "/"}
)
return super().setUp()
def tearDown(self):
cache.clear()
return super().tearDown()
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
@@ -3,5 +3,6 @@ from admin_confirm.tests.helpers import AdminConfirmIntegrationTestCase
class SmokeTest(AdminConfirmIntegrationTestCase):
def test_load_admin(self):
self.selenium.get(self.live_server_url+'/admin/')
self.assertIn('Django', self.selenium.title)
self.selenium.get(self.live_server_url + "/admin/")
self.assertIn("Django", self.selenium.title)
self.assertIn("Market", self.selenium.page_source)
@@ -0,0 +1,213 @@
"""
Tests confirmation of add/change
on ModelAdmin that utilize caches
"""
import os
import pytest
import pkg_resources
from importlib import reload
from tests.factories import ShopFactory
from tests.market.models import GeneralManager, Item, ShoppingMall, Town
from admin_confirm.tests.helpers import AdminConfirmIntegrationTestCase
from tests.market.admin import shoppingmall_admin
from admin_confirm.constants import CONFIRM_CHANGE
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.remote.file_detector import LocalFileDetector
from django.core.files.uploadedfile import SimpleUploadedFile
from tempfile import NamedTemporaryFile
class ConfirmWithInlinesTests(AdminConfirmIntegrationTestCase):
def setUp(self):
self.selenium.file_detector = LocalFileDetector()
super().setUp()
def tearDown(self):
reload(shoppingmall_admin)
super().tearDown()
def test_models_without_files_should_not_have_confirmation_received(self):
mall = ShoppingMall.objects.create(name="mall")
self.selenium.get(
self.live_server_url + f"/admin/market/shoppingmall/{mall.id}/change/"
)
# Should ask for confirmation of change
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Change name
name = self.selenium.find_element_by_name("name")
name.send_keys("New Name")
self.selenium.find_element_by_name("_continue").click()
# Should have hidden form containing the updated name
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
name = hidden_form.find_element_by_name("name")
self.assertIn("New Name", name.get_attribute("value"))
with self.assertRaises(NoSuchElementException):
self.selenium.find_element_by_name("_confirmation_received")
self.selenium.find_element_by_name("_continue").click()
# Should persist change
mall.refresh_from_db()
self.assertIn("New Name", mall.name)
def test_models_with_files_should_have_confirmation_received(self):
item = Item.objects.create(name="item", price=1)
self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
# Should ask for confirmation of change
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Change price
price = self.selenium.find_element_by_name("price")
price.send_keys(2)
self.selenium.find_element_by_name("_continue").click()
# Should have hidden form containing the updated price
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
price = hidden_form.find_element_by_name("price")
self.assertEqual("21.00", price.get_attribute("value"))
self.selenium.find_element_by_name("_confirmation_received")
self.selenium.find_element_by_name("_continue").click()
item.refresh_from_db()
def test_should_save_file_additions(self):
selenium_version = pkg_resources.get_distribution("selenium").parsed_version
if selenium_version.major < 4:
pytest.skip(
"Known issue `https://github.com/SeleniumHQ/selenium/issues/8762` with this selenium version."
)
item = Item.objects.create(
name="item", price=1, currency=Item.VALID_CURRENCIES[0][0]
)
self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
price = self.selenium.find_element_by_name("price")
price.send_keys(2)
# Upload a new file
self.selenium.find_element_by_id("id_file").send_keys(
os.getcwd() + "/screenshot.png"
)
self.selenium.find_element_by_name("_continue").click()
# Should have hidden form containing the updated price
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
price = hidden_form.find_element_by_name("price")
self.assertEqual("21.00", price.get_attribute("value"))
self.selenium.find_element_by_name("_confirmation_received")
self.selenium.find_element_by_name("_continue").click()
item.refresh_from_db()
self.assertEqual(21, int(item.price))
self.assertIn("screenshot.png", item.file.name)
def test_should_save_file_changes(self):
selenium_version = pkg_resources.get_distribution("selenium").parsed_version
if selenium_version.major < 4:
pytest.skip(
"Known issue `https://github.com/SeleniumHQ/selenium/issues/8762` with this selenium version."
)
file = SimpleUploadedFile(
name="old_file.jpg",
content=open("screenshot.png", "rb").read(),
content_type="image/jpeg",
)
item = Item.objects.create(
name="item", price=1, currency=Item.VALID_CURRENCIES[0][0], file=file
)
self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
price = self.selenium.find_element_by_name("price")
price.send_keys(2)
# Upload a new file
self.selenium.find_element_by_id("id_file").send_keys(
os.getcwd() + "/screenshot.png"
)
self.selenium.find_element_by_name("_continue").click()
# Should have hidden form containing the updated price
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
price = hidden_form.find_element_by_name("price")
self.assertEqual("21.00", price.get_attribute("value"))
self.selenium.find_element_by_name("_confirmation_received")
self.selenium.find_element_by_name("_continue").click()
item.refresh_from_db()
self.assertEqual(21, int(item.price))
self.assertIn("screenshot.png", item.file.name)
def test_should_remove_file_if_clear_selected(self):
file = SimpleUploadedFile(
name="old_file.jpg",
content=open("screenshot.png", "rb").read(),
content_type="image/jpeg",
)
item = Item.objects.create(
name="item", price=1, currency=Item.VALID_CURRENCIES[0][0], file=file
)
self.selenium.get(
self.live_server_url + f"/admin/market/item/{item.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
price = self.selenium.find_element_by_name("price")
price.send_keys(2)
# Choose to clear the existing file
self.selenium.find_element_by_id("file-clear_id").click()
self.assertTrue(
self.selenium.find_element_by_xpath(
".//*[@id='file-clear_id']"
).get_attribute("checked")
)
self.selenium.find_element_by_name("_continue").click()
# Should have hidden form containing the updated price
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
price = hidden_form.find_element_by_name("price")
self.assertEqual("21.00", price.get_attribute("value"))
self.selenium.find_element_by_name("_confirmation_received")
self.selenium.find_element_by_name("_continue").click()
item.refresh_from_db()
self.assertEqual(21, int(item.price))
# Should have cleared `file` since clear was selected
self.assertFalse(item.file)
@@ -0,0 +1,202 @@
"""
Tests confirmation of add/change
on ModelAdmin that includes inlines
Does not test confirmation of inline changes
"""
import pytest
import pkg_resources
from importlib import reload
from tests.factories import ShopFactory
from tests.market.models import GeneralManager, ShoppingMall, Town
from admin_confirm.tests.helpers import AdminConfirmIntegrationTestCase
from tests.market.admin import shoppingmall_admin
from admin_confirm.constants import CONFIRM_CHANGE
from selenium.webdriver.support.ui import Select
class ConfirmWithInlinesTests(AdminConfirmIntegrationTestCase):
def setUp(self):
self.admin = shoppingmall_admin.ShoppingMallAdmin
self.admin.inlines = [shoppingmall_admin.ShopInline]
super().setUp()
def tearDown(self):
reload(shoppingmall_admin)
super().tearDown()
def test_should_have_hidden_form(self):
mall = ShoppingMall.objects.create(name="mall")
self.selenium.get(
self.live_server_url + f"/admin/market/shoppingmall/{mall.id}/change/"
)
# Should ask for confirmation of change
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Change name
name = self.selenium.find_element_by_name("name")
name.send_keys("New Name")
self.selenium.find_element_by_name("_continue").click()
# Should have hidden form containing the updated name
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
name = hidden_form.find_element_by_name("name")
self.assertIn("New Name", name.get_attribute("value"))
self.selenium.find_element_by_name("_continue").click()
# Should persist change
mall.refresh_from_db()
self.assertIn("New Name", mall.name)
def test_should_have_hidden_formsets(self):
# Not having formsets would cause a `ManagementForm tampered with` issue
gm = GeneralManager.objects.create(name="gm")
shops = [ShopFactory(name=i) for i in range(3)]
town = Town.objects.create(name="town")
mall = ShoppingMall.objects.create(name="mall", general_manager=gm, town=town)
mall.shops.set(shops)
self.selenium.get(
self.live_server_url + f"/admin/market/shoppingmall/{mall.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
name = self.selenium.find_element_by_name("name")
name.send_keys("New Name")
self.selenium.find_element_by_name("_continue").click()
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
hidden_form.find_element_by_name("ShoppingMall_shops-TOTAL_FORMS")
self.selenium.find_element_by_name("_continue").click()
mall.refresh_from_db()
self.assertIn("New Name", mall.name)
def test_should_have_saved_inline_changes(self):
gm = GeneralManager.objects.create(name="gm")
town = Town.objects.create(name="town")
mall = ShoppingMall.objects.create(name="mall", general_manager=gm, town=town)
shops = [ShopFactory(name=i) for i in range(3)]
self.selenium.get(
self.live_server_url + f"/admin/market/shoppingmall/{mall.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
name = self.selenium.find_element_by_name("name")
name.send_keys("New Name")
# Change shops via inline form
select_shop = Select(
self.selenium.find_element_by_name("ShoppingMall_shops-0-shop")
)
select_shop.select_by_value(str(shops[2].id))
self.selenium.find_element_by_name("_continue").click()
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
hidden_form.find_element_by_name("ShoppingMall_shops-TOTAL_FORMS")
self.selenium.find_element_by_name("_continue").click()
mall.refresh_from_db()
self.assertIn("New Name", mall.name)
self.assertIn(shops[2], mall.shops.all())
def test_should_respect_get_inlines(self):
# New in Django 3.0
django_version = pkg_resources.get_distribution("Django").parsed_version
if django_version.major < 3:
pytest.skip(
"get_inlines() introducted in Django 3.0, and is not in this version"
)
shoppingmall_admin.ShoppingMallAdmin.inlines = []
shoppingmall_admin.ShoppingMallAdmin.get_inlines = (
lambda self, request, obj=None: [shoppingmall_admin.ShopInline]
)
gm = GeneralManager.objects.create(name="gm")
town = Town.objects.create(name="town")
mall = ShoppingMall.objects.create(name="mall", general_manager=gm, town=town)
shops = [ShopFactory(name=i) for i in range(3)]
self.selenium.get(
self.live_server_url + f"/admin/market/shoppingmall/{mall.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
name = self.selenium.find_element_by_name("name")
name.send_keys("New Name")
# Change shops via inline form
select_shop = Select(
self.selenium.find_element_by_name("ShoppingMall_shops-0-shop")
)
select_shop.select_by_value(str(shops[2].id))
self.selenium.find_element_by_name("_continue").click()
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
hidden_form.find_element_by_name("ShoppingMall_shops-TOTAL_FORMS")
self.selenium.find_element_by_name("_continue").click()
mall.refresh_from_db()
self.assertIn("New Name", mall.name)
self.assertIn(shops[2], mall.shops.all())
def test_should_respect_get_inline_instances(self):
shoppingmall_admin.ShoppingMallAdmin.inlines = []
shoppingmall_admin.ShoppingMallAdmin.get_inline_instances = (
lambda self, request, obj=None: shoppingmall_admin.ShopInline(
self.model, self.admin_site
)
)
gm = GeneralManager.objects.create(name="gm")
town = Town.objects.create(name="town")
mall = ShoppingMall.objects.create(name="mall", general_manager=gm, town=town)
shops = [ShopFactory(name=i) for i in range(3)]
self.selenium.get(
self.live_server_url + f"/admin/market/shoppingmall/{mall.id}/change/"
)
self.assertIn(CONFIRM_CHANGE, self.selenium.page_source)
# Make a change to trigger confirmation page
name = self.selenium.find_element_by_name("name")
name.send_keys("New Name")
# Change shops via inline form
select_shop = Select(
self.selenium.find_element_by_name("ShoppingMall_shops-0-shop")
)
select_shop.select_by_value(str(shops[2].id))
self.selenium.find_element_by_name("_continue").click()
self.assertIn("Confirm", self.selenium.page_source)
hidden_form = self.selenium.find_element_by_id("hidden-form")
hidden_form.find_element_by_name("ShoppingMall_shops-TOTAL_FORMS")
self.selenium.find_element_by_name("_continue").click()
mall.refresh_from_db()
self.assertIn("New Name", mall.name)
self.assertIn(shops[2], mall.shops.all())
@@ -21,8 +21,6 @@ class TestAdminOptions(AdminConfirmTestCase):
mall.shops.set(shops)
# new values
gm2 = GeneralManager.objects.create(name="gm2")
shops2 = [ShopFactory() for i in range(3)]
town2 = Town.objects.create(name="town2")
data = {
@@ -92,7 +90,6 @@ class TestAdminOptions(AdminConfirmTestCase):
# new values
gm2 = GeneralManager.objects.create(name="gm2")
shops2 = [ShopFactory() for i in range(3)]
town2 = Town.objects.create(name="town2")
data = {
@@ -164,7 +161,6 @@ class TestAdminOptions(AdminConfirmTestCase):
# new values
gm2 = GeneralManager.objects.create(name="gm2")
shops2 = [ShopFactory() for i in range(3)]
town2 = Town.objects.create(name="town2")
data = {
@@ -205,7 +201,6 @@ class TestAdminOptions(AdminConfirmTestCase):
# new values
gm2 = GeneralManager.objects.create(name="gm2")
shops2 = [ShopFactory() for i in range(3)]
town2 = Town.objects.create(name="town2")
data = {
@@ -246,7 +241,6 @@ class TestAdminOptions(AdminConfirmTestCase):
# new values
gm2 = GeneralManager.objects.create(name="gm2")
shops2 = [ShopFactory() for i in range(3)]
town2 = Town.objects.create(name="town2")
data = {
@@ -1,5 +1,4 @@
from unittest import mock
from admin_confirm.admin import AdminConfirmMixin
from django.urls import reverse
from admin_confirm.tests.helpers import AdminConfirmTestCase
+14 -70
View File
@@ -170,7 +170,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
item.refresh_from_db()
@@ -290,7 +290,7 @@ class TestFileCache(AdminConfirmTestCase):
data[CONFIRMATION_RECEIVED] = True
with mock.patch.object(ItemAdmin, "message_user") as message_user:
response = self.client.post(f"/admin/market/item/add/", data=data)
response = self.client.post("/admin/market/item/add/", data=data)
# Should show message to user with correct obj and path
message_user.assert_called_once()
message = message_user.call_args[0][1]
@@ -299,7 +299,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should not have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
self.item.refresh_from_db()
@@ -353,7 +353,7 @@ class TestFileCache(AdminConfirmTestCase):
data[CONFIRMATION_RECEIVED] = True
with mock.patch.object(ItemAdmin, "message_user") as message_user:
response = self.client.post(f"/admin/market/item/add/", data=data)
response = self.client.post("/admin/market/item/add/", data=data)
# Should show message to user with correct obj and path
message_user.assert_called_once()
message = message_user.call_args[0][1]
@@ -362,7 +362,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should not have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
self.item.refresh_from_db()
@@ -398,17 +398,6 @@ class TestFileCache(AdminConfirmTestCase):
"_save": True,
}
# Upload new file
f2 = SimpleUploadedFile(
name="test_file2.jpg",
content=open(self.image_path, "rb").read(),
content_type="image/jpeg",
)
# Set cache
cache_item = Item(
name=data["name"], price=data["price"], currency=data["currency"], file=f2
)
# Make sure there's no post cached obj
cache.delete(CACHE_KEYS["object"])
cache.set(CACHE_KEYS["post"], data)
@@ -418,7 +407,7 @@ class TestFileCache(AdminConfirmTestCase):
data[CONFIRMATION_RECEIVED] = True
with mock.patch.object(ItemAdmin, "message_user") as message_user:
response = self.client.post(f"/admin/market/item/add/", data=data)
response = self.client.post("/admin/market/item/add/", data=data)
# Should show message to user with correct obj and path
message_user.assert_called_once()
message = message_user.call_args[0][1]
@@ -427,7 +416,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should not have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
self.item.refresh_from_db()
@@ -463,17 +452,6 @@ class TestFileCache(AdminConfirmTestCase):
"_save": True,
}
# Upload new file
f2 = SimpleUploadedFile(
name="test_file2.jpg",
content=open(self.image_path, "rb").read(),
content_type="image/jpeg",
)
# Set cache
cache_item = Item(
name=data["name"], price=data["price"], currency=data["currency"], file=f2
)
# Make sure there's no cache
cache.delete(CACHE_KEYS["object"])
cache.delete(CACHE_KEYS["post"])
@@ -483,7 +461,7 @@ class TestFileCache(AdminConfirmTestCase):
data[CONFIRMATION_RECEIVED] = True
with mock.patch.object(ItemAdmin, "message_user") as message_user:
response = self.client.post(f"/admin/market/item/add/", data=data)
response = self.client.post("/admin/market/item/add/", data=data)
# Should show message to user with correct obj and path
message_user.assert_called_once()
message = message_user.call_args[0][1]
@@ -492,7 +470,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should not have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
self.item.refresh_from_db()
@@ -571,7 +549,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
item.refresh_from_db()
@@ -601,12 +579,6 @@ class TestFileCache(AdminConfirmTestCase):
# Load the Change Item Page
ItemAdmin.save_as_continue = False
# Upload new image and remove file
i2 = SimpleUploadedFile(
name="test_image2.jpg",
content=open(self.image_path, "rb").read(),
content_type="image/jpeg",
)
# Request.POST
data = {
"id": item.id,
@@ -619,14 +591,6 @@ class TestFileCache(AdminConfirmTestCase):
"_saveasnew": True,
}
# Set cache
cache_item = Item(
name=data["name"],
price=data["price"],
currency=data["currency"],
image=i2,
)
# Ensure no cached obj
cache.delete(CACHE_KEYS["object"])
cache.set(CACHE_KEYS["post"], data)
@@ -647,7 +611,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
item.refresh_from_db()
@@ -676,12 +640,6 @@ class TestFileCache(AdminConfirmTestCase):
# Load the Change Item Page
ItemAdmin.save_as_continue = False
# Upload new image and remove file
i2 = SimpleUploadedFile(
name="test_image2.jpg",
content=open(self.image_path, "rb").read(),
content_type="image/jpeg",
)
# Request.POST
data = {
"id": item.id,
@@ -694,14 +652,6 @@ class TestFileCache(AdminConfirmTestCase):
"_saveasnew": True,
}
# Set cache
cache_item = Item(
name=data["name"],
price=data["price"],
currency=data["currency"],
image=i2,
)
# Ensure no cache
cache.delete(CACHE_KEYS["object"])
cache.delete(CACHE_KEYS["post"])
@@ -722,7 +672,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should not have changed existing item
item.refresh_from_db()
@@ -790,7 +740,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should have changed existing item
self.assertEqual(Item.objects.count(), 1)
@@ -890,12 +840,6 @@ class TestFileCache(AdminConfirmTestCase):
# Load the Change Item Page
ItemAdmin.save_as_continue = False
# Upload new image and remove file
i2 = SimpleUploadedFile(
name="test_image2.jpg",
content=open(self.image_path, "rb").read(),
content_type="image/jpeg",
)
# Request.POST
data = {
"id": item.id,
@@ -930,7 +874,7 @@ class TestFileCache(AdminConfirmTestCase):
self.assertNotIn("You may edit it again below.", message)
# Should have redirected to changelist
self.assertEqual(response.url, f"/admin/market/item/")
self.assertEqual(response.url, "/admin/market/item/")
# Should have changed existing item
self.assertEqual(Item.objects.count(), 1)