Skip to content

Instantly share code, notes, and snippets.

@hellais
Created December 4, 2012 11:45
Show Gist options
  • Save hellais/4202977 to your computer and use it in GitHub Desktop.
Save hellais/4202977 to your computer and use it in GitHub Desktop.
from twisted.internet import defer
from unittest import TestCase
from globaleaks.models.base import TXModel
class DummyModel(TXModel):
some_attribute = 'fooo'
other_attribute = 'bar'
def get_something_else(self):
return {'antanisblinda': 12345}
@defer.inlineCallbacks
def get_more_stuff(self):
"""
Questo fa vedere come interagire con robe che hanno dei
inlineCallbacks.
"""
defer.returnValue('more_stuff')
def serialize(self):
import json
serialized_object = {
'some_attribute': self.some_attribute,
'other_attribute': self.other_attribute,
'something_else': self.get_something_else(),
'more_stuff': yield self.get_more_stuff()
}
return json.dumps(serialized_obj)
class TestModel(TestCase):
def test_serialize_object()
dummy_model = DummyModel()
self.assertIsInstance(dummy_model.serialize(), dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment