Skip to content

Instantly share code, notes, and snippets.

@goodwillcoding
goodwillcoding / gist:3808838
Created October 1, 2012 00:39
JSON Serializable SQLAlchemy Object
class JsonSerializableMixin(object):
def __json__(self, request):
"""
Converts all the properties of the object into a dict for use in json.
You can define the following in your class
_json_eager_load :
list of which child classes need to be eagerly loaded. This applies
to one-to-many relationships defined in SQLAlchemy classes.
@goodwillcoding
goodwillcoding / gist:3808856
Created October 1, 2012 00:45 — forked from pjenvey/gist:3808830
JSON Serializable SQLAlchemy Object
class JsonSerializableMixin(object):
def __json__(self, request):
"""
Converts all the properties of the object into a dict for use in json.
You can define the following in your class
_json_eager_load :
list of which child classes need to be eagerly loaded. This applies
to one-to-many relationships defined in SQLAlchemy classes.
@goodwillcoding
goodwillcoding / gist:3808931
Created October 1, 2012 01:17
JSON Serializable SQLAlchemy Object
class JsonSerializableMixin(object):
"""
Converts all the properties of the object into a dict for use in json.
You can define the following as your class properties.
_json_eager_load :
list of which child classes need to be eagerly loaded. This applies
to one-to-many relationships defined in SQLAlchemy classes.
_base_blacklist :
File Edit Options Buffers Tools Python Help
class Bar(object):
def meth1(self):
pass
class Foo(Bar):
def meth2(self, func=Bar.meth1):
class FooError(Exception): pass
def public_api1(x):
"""
Return given value, after making sure it is not 1.
:param x: value:
:type x: int
:raises: ForError if x == 1
class Foo(object):
_prop1 = None
_prop2 = None
_prop3 = None
def set_prop1(self, value):
self._prop1 = self._set_if_valid(value)
def set_prop2(self, value):
class Foo(object):
def bar(value):
if value == 11:
raise ValueError()
return value
def hello(msg):
return msg
class TestFoo_bar(TestCase):
# --------------------------------------------------------------------------- #
class Foo(object):
# ....................................................................... #
def get_string(self):
return "hello"
# ....................................................................... #
def reverse_string(self, str_=self.get_string()):
return str_[::-1]
from os import makedirs
from unittest import TestCase
def foo(_default_folder='foo', _os_makedirs=makedirs):
"""
The purpose of this function is to create a folder called 'foo'
on the file system.
"""
try:
# -*- coding: utf-8 -*-
"""
Sample Test Cases More Injections
"""
from unittest import TestCase
# --------------------------------------------------------------------------- #