Added testing for DateField, DateTimeField, and validators on the Model and ModelForm (#23)
* Added testing for DateField and DateTimeField * Update makefile * Adding some of the tests with validators on model * Added ModelForm clean_field and clean tests Co-authored-by: Thu Trang Pham <thu@joinmodernhealth.com>
This commit is contained in:
@@ -1,15 +1,30 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from ..models import GeneralManager, Item, Inventory, Shop, ShoppingMall
|
||||
from ..models import (
|
||||
GeneralManager,
|
||||
Item,
|
||||
Inventory,
|
||||
ItemSale,
|
||||
Shop,
|
||||
ShoppingMall,
|
||||
Transaction,
|
||||
Checkout,
|
||||
)
|
||||
|
||||
from .item_admin import ItemAdmin
|
||||
from .inventory_admin import InventoryAdmin
|
||||
from .shop_admin import ShopAdmin
|
||||
from .shoppingmall_admin import ShoppingMallAdmin
|
||||
from .generalmanager_admin import GeneralManagerAdmin
|
||||
from .item_sale_admin import ItemSaleAdmin
|
||||
from .transaction_admin import TransactionAdmin
|
||||
from .checkout_admin import CheckoutAdmin
|
||||
|
||||
admin.site.register(Item, ItemAdmin)
|
||||
admin.site.register(Inventory, InventoryAdmin)
|
||||
admin.site.register(Shop, ShopAdmin)
|
||||
admin.site.register(ShoppingMall, ShoppingMallAdmin)
|
||||
admin.site.register(GeneralManager, GeneralManagerAdmin)
|
||||
admin.site.register(Transaction, TransactionAdmin)
|
||||
admin.site.register(ItemSale, ItemSaleAdmin)
|
||||
admin.site.register(Checkout, CheckoutAdmin)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from django.forms import ModelForm
|
||||
|
||||
from ..models import Checkout
|
||||
|
||||
|
||||
class CheckoutForm(ModelForm):
|
||||
class Meta:
|
||||
model = Checkout
|
||||
fields = [
|
||||
"currency",
|
||||
"shop",
|
||||
"total",
|
||||
"timestamp",
|
||||
"date",
|
||||
]
|
||||
|
||||
def clean_total(self):
|
||||
try:
|
||||
total = float(self.cleaned_data["total"])
|
||||
except:
|
||||
raise ValidationError("Invalid Total From clean_total")
|
||||
if total == 111: # Use to cause error in test
|
||||
raise ValidationError("Invalid Total 111")
|
||||
|
||||
return total
|
||||
|
||||
def clean(self):
|
||||
try:
|
||||
total = float(self.data["total"])
|
||||
except:
|
||||
raise ValidationError("Invalid Total From clean")
|
||||
if total == 222: # Use to cause error in test
|
||||
raise ValidationError("Invalid Total 222")
|
||||
|
||||
self.cleaned_data["total"] = total
|
||||
|
||||
|
||||
class CheckoutAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
confirm_add = True
|
||||
confirm_change = True
|
||||
autocomplete_fields = ["shop"]
|
||||
form = CheckoutForm
|
||||
@@ -0,0 +1,9 @@
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
|
||||
|
||||
from django.contrib.admin import ModelAdmin
|
||||
|
||||
|
||||
class ItemSaleAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
confirm_add = True
|
||||
confirm_change = True
|
||||
@@ -0,0 +1,9 @@
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
|
||||
|
||||
from django.contrib.admin import ModelAdmin
|
||||
|
||||
|
||||
class TransactionAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
confirm_add = True
|
||||
confirm_change = True
|
||||
Reference in New Issue
Block a user