Skip to content

Commit

Permalink
test: Update format_html check assert_called_once
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesx00 committed Jun 16, 2022
1 parent 8e0013e commit 46105a9
Showing 1 changed file with 17 additions and 65 deletions.
82 changes: 17 additions & 65 deletions django_omise/tests/test_admin_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,40 @@ def test_charge_chage_permission(self):
request = MockRequest(user=self.user)
self.assertEqual(charge_admin.has_change_permission(request=request), False)

def test_charge_colorized_status_successful(self):
@mock.patch("django_omise.admin.admin.format_html")
def test_charge_colorized_status_successful(self, mock_format_html):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())

charge = self.create_charge(status=ChargeStatus.SUCCESSFUL)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)

def test_charge_colorized_status_pending(self):
charge_admin.colorized_status(obj=charge)
mock_format_html.assert_called_once()

@mock.patch("django_omise.admin.admin.format_html")
def test_charge_colorized_status_pending(self, mock_format_html):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())

charge = self.create_charge(status=ChargeStatus.PENDING)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)

def test_charge_colorized_status_failed(self):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())
charge_admin.colorized_status(obj=charge)
mock_format_html.assert_called_once()

charge = self.create_charge(status=ChargeStatus.FAILED)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)

def test_charge_colorized_status_failed(self):
@mock.patch("django_omise.admin.admin.format_html")
def test_charge_colorized_status_failed(self, mock_format_html):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())

charge = self.create_charge(status=ChargeStatus.FAILED)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)

def test_charge_colorized_status_failed(self):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())
charge_admin.colorized_status(obj=charge)
mock_format_html.assert_called_once()

charge = self.create_charge(status=ChargeStatus.FAILED)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)

def test_charge_colorized_status_partially_refunded(self):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())

charge = self.create_charge(
status=ChargeStatus.SUCCESSFUL,
refunded_amount=10000,
)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)

def test_charge_inline_change_permission(self):
@mock.patch("django_omise.admin.admin.format_html")
def test_charge_colorized_status_partially_refunded(self, mock_format_html):
charge_admin = ChargeAdmin(model=Charge, admin_site=AdminSite())

charge = self.create_charge(
status=ChargeStatus.SUCCESSFUL,
refunded_amount=10000,
)
try:
charge_admin.colorized_status(obj=charge)
except Exception as e:
self.fail(
f"ChargeAdmin.colorized_status should not raise an error. An error was raised {type(e)}: {e}"
)
charge_admin.colorized_status(obj=charge)
mock_format_html.assert_called_once()

def create_charge(self, **kwargs):
default = {
Expand Down

0 comments on commit 46105a9

Please sign in to comment.