mirror of
				https://github.com/enpaul/peewee-plus.git
				synced 2025-11-04 01:08:38 +00:00 
			
		
		
		
	Add JSONField for storing JSON data
This commit is contained in:
		
							
								
								
									
										35
									
								
								tests/test_jsonfield.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								tests/test_jsonfield.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
# pylint: disable=redefined-outer-name
 | 
			
		||||
# pylint: disable=missing-class-docstring
 | 
			
		||||
# pylint: disable=too-few-public-methods
 | 
			
		||||
# pylint: disable=unused-import
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
 | 
			
		||||
import peewee
 | 
			
		||||
import pytest
 | 
			
		||||
 | 
			
		||||
import peewee_plus
 | 
			
		||||
from .fixtures import fakedb
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_json(fakedb):
 | 
			
		||||
    """Test basic usage of JSONField class"""
 | 
			
		||||
 | 
			
		||||
    class TestModel(peewee.Model):
 | 
			
		||||
        class Meta:
 | 
			
		||||
            database = fakedb
 | 
			
		||||
 | 
			
		||||
        some_data = peewee_plus.JSONField()
 | 
			
		||||
 | 
			
		||||
    fakedb.create_tables([TestModel])
 | 
			
		||||
 | 
			
		||||
    data = {"foo": 10, "bar": ["hello", "world"], "baz": True}
 | 
			
		||||
 | 
			
		||||
    model = TestModel(some_data=data)
 | 
			
		||||
    model.save()
 | 
			
		||||
 | 
			
		||||
    model = TestModel.get()
 | 
			
		||||
    assert model.some_data == data
 | 
			
		||||
 | 
			
		||||
    with pytest.raises(peewee.IntegrityError):
 | 
			
		||||
        bad = TestModel(some_data=Path("."))
 | 
			
		||||
        bad.save()
 | 
			
		||||
		Reference in New Issue
	
	Block a user