def test_model_datastore(self): ds = datastore.ModelDatastore(plugin_name="test") self.assertEqual(0, models.PluginData.objects.all().count()) ds.set("foo", "bar") q = models.PluginData.objects.all() self.assertEqual(1, q.count()) self.assertEqual("test", q[0].plugin_name) self.assertEqual("foo", q[0].key) self.assertEqual("bar", q[0].value) # Setting to 'None' clears value ds.set("foo", None) self.assertEqual(0, models.PluginData.objects.all().count()) # Complex types survive. ds.set("obj", {"asdf": 123, "foo": None}) self.assertEqual({"asdf": 123, "foo": None}, ds.get("obj"))
def test_model_datastore(self): ds = datastore.ModelDatastore(plugin_name='test') self.assertEqual(0, models.PluginData.objects.all().count()) ds.set('foo', 'bar') q = models.PluginData.objects.all() self.assertEqual(1, q.count()) self.assertEqual('test', q[0].plugin_name) self.assertEqual('foo', q[0].key) self.assertEqual('bar', q[0].value) # Setting to 'None' clears value ds.set('foo', None) self.assertEqual(0, models.PluginData.objects.all().count()) # Complex types survive. ds.set('obj', {'asdf': 123, 'foo': None}) self.assertEqual({'asdf': 123, 'foo': None}, ds.get('obj'))