forked from awesto/django-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request awesto#423 from rfleschenberg/jsonfield-wrapper
Jsonfield wrapper
- Loading branch information
Showing
2 changed files
with
29 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,52 @@ | ||
# -*- coding: utf-8 | ||
from __future__ import unicode_literals | ||
|
||
import decimal | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.db import models | ||
from django.test import TestCase | ||
|
||
from shop.models.defaults.cart_item import CartItem | ||
from shop.models.fields import JSONField | ||
|
||
from myshop.models import Cart, CartItem, Customer | ||
from myshop.models.manufacturer import Manufacturer | ||
from myshop.models.polymorphic.commodity import Commodity | ||
|
||
|
||
class JsonModel(models.Model): | ||
|
||
class Meta: | ||
app_label = 'JsonModel' | ||
|
||
json = JSONField() | ||
default_json = JSONField(default={"check": 12}) | ||
default_json = JSONField(default=lambda: {"check": 12}) | ||
|
||
|
||
class JSONFieldTest(TestCase): | ||
"""JSONField Tests""" | ||
|
||
fixtures = ['myshop-polymorphic.json'] | ||
|
||
def setUp(self): | ||
super(JSONFieldTest, self).setUp() | ||
self.sample = CartItem.objects.get(id=8) | ||
user = get_user_model().objects.create() | ||
customer = Customer.objects.create(number=1, user=user) | ||
manufacturer = Manufacturer.objects.create() | ||
product = Commodity.objects.create( | ||
product_code="testproduct", | ||
unit_price=decimal.Decimal("0"), | ||
order=1, | ||
manufacturer=manufacturer | ||
) | ||
cart = Cart.objects.create(customer=customer) | ||
self.sample = CartItem.objects.create( | ||
quantity=1, | ||
cart=cart, | ||
product=product, | ||
extra={'product_code': 'foo'}, | ||
) | ||
self.assertIsNotNone(self.sample) | ||
|
||
def test_json_field_create(self): | ||
"""Test saving a JSON object in our JSONField""" | ||
extra = {"product_code":"1121"} | ||
|
||
extra = {'product_code': 'foo'} | ||
self.assertEqual(self.sample.extra, extra) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters