def test_dont_overwrite_if_empty(self): class Dummy(models.Model): char = models.CharField(max_length=128) m = ModelMapper(Dummy, {'char': 'choose other', 'other': ''}).map() m.map_one('char', 'other') dummy = m.create() self.assertEquals(dummy.char, 'choose other') self.assertIsInstance(dummy, Dummy)
def test_rename_one(self): class Dummy(models.Model): char = models.CharField(max_length=128) dummy = ModelMapper(Dummy, {'some_param': 'value'}).map_one('char', 'some_param').create() self.assertEquals(dummy.char, 'value') self.assertIsInstance(dummy, Dummy)
def test_char_missing(self): class Dummy(models.Model): char = models.CharField(max_length=128) dummy = ModelMapper(Dummy, {}).map().create() self.assertEquals(dummy.char, '') self.assertIsInstance(dummy, Dummy)
def test_create_with_extras(self): class Dummy(models.Model): char = models.CharField(max_length=128) integer = models.IntegerField() dummy = ModelMapper(Dummy, {'char': 'value'}).map().create(char='new value', integer=3) self.assertEquals(dummy.char, 'new value') self.assertEquals(dummy.integer, 3) self.assertIsInstance(dummy, Dummy)
def test_empty(self): # TODO warning RuntimeWarning: Model 'moonsheep.dummy' was already registered. # Reloading models is not advised as it can lead to inconsistencies, most notably with related models. # make dummy a proper test model class Dummy(models.Model): boolean = models.BooleanField() null_boolean = models.NullBooleanField() char = models.CharField(max_length=128) integer = models.IntegerField(blank=True, null=True) data = {} ModelMapper(Dummy, data).map().create()
def test_rename_many(self): class Dummy(models.Model): char = models.CharField(max_length=128) integer = models.IntegerField(blank=True, null=True) dummy = ModelMapper(Dummy, { 'some_param': 'value', 'other_param': '4' }).map(rename={ 'char': 'some_param', 'integer': 'other_param' }).create() self.assertEquals(dummy.char, 'value') self.assertEquals(dummy.integer, 4) self.assertIsInstance(dummy, Dummy)
def test_general(self): class Dummy(models.Model): boolean = models.BooleanField() null_boolean = models.NullBooleanField() char = models.CharField(max_length=128) integer = models.IntegerField(blank=True, null=True) data = { 'boolean': 'on', 'null_boolean': 'on', 'char': 'char', 'integer': '3' } dummy = ModelMapper(Dummy, data).map().create() self.assertIsInstance(dummy, Dummy) self.assertEquals(dummy.boolean, True) self.assertEquals(dummy.null_boolean, True) self.assertEquals(dummy.char, 'char') self.assertEquals(dummy.integer, 3)