def setUp(self): super(QueryTests, self).setUp() self.objs = [ DynamicModel(attrs={'a': 'b'}), DynamicModel(attrs={ 'a': 'b', 'c': 'd' }), DynamicModel(attrs={'c': 'd'}), DynamicModel(attrs={}), DynamicModel( attrs={ 'datetimey': datetime(2001, 1, 4, 14, 15, 16), 'datey': date(2001, 1, 4), 'floaty': 128.5, 'inty': 9001, 'stry': "strvalue", 'str_underscorey': "strvalue2", 'timey': time(14, 15, 16), 'nesty': { 'level2': 'chirp' } }), ] DynamicModel.objects.bulk_create(self.objs) self.objs = list(DynamicModel.objects.all().order_by('id'))
def test_bulk_create(self): DynamicModel.objects.bulk_create([ DynamicModel(attrs={'a': 'value'}), DynamicModel(attrs={'b': 'value2'}), ]) dm1, dm2 = DynamicModel.objects.all().order_by('id') assert dm1.attrs == {'a': 'value'} assert dm2.attrs == {'b': 'value2'}
def test_mariadb_old_version(self): # Uncache cached_property for db in connections: if 'mysql_version' in connections[db].__dict__: del connections[db].__dict__['mysql_version'] errors = DynamicModel.check() assert len(errors) == 1 assert errors[0].id == 'django_mysql.E013' assert "MariaDB 10.0.1+ is required" in errors[0].msg
def test_character_set_not_utf8_compatible(self): with connection.cursor() as cursor: cursor.execute("SELECT @@character_set_client") orig_charset = cursor.fetchone()[0] cursor.execute("SET NAMES 'latin1'") try: errors = DynamicModel.check() finally: cursor.execute("SET NAMES '{}'".format(orig_charset)) assert len(errors) == 1 assert errors[0].id == 'django_mysql.E014' assert "The MySQL charset must be 'utf8'" in errors[0].msg
def test_dumping(self): instance = DynamicModel(attrs={'a': 'b'}) data = serializers.serialize('json', [instance]) assert json.loads(data) == json.loads(self.test_data)
def test_mariadb_dyncol_missing(self): errors = DynamicModel.check() assert len(errors) == 1 assert errors[0].id == 'django_mysql.E012' assert "'mariadb_dyncol' is required" in errors[0].msg
def test_illegal_nested_type(self): m = DynamicModel(attrs={'nesty': []}) with pytest.raises(TypeError) as excinfo: m.save() assert "Key 'nesty' should be of type dict" in str(excinfo.value)
def test_illegal_nested(self): m = DynamicModel(attrs={'nesty': {'level2': 1}}) with pytest.raises(TypeError) as excinfo: m.save() assert "Key 'nesty.level2' should be of type " in str(excinfo.value)
def test_illegal_int(self): m = DynamicModel(attrs={'inty': 1.0}) with pytest.raises(TypeError) as excinfo: m.save() assert "Key 'inty' should be of type int" in str(excinfo.value)