Example #1
0
 def test_column_introspection(self):
     """Test for getting the names of columns as strings."""
     columns = _get_columns(self.Person)
     self.assertEqual(sorted(columns.keys()), sorted(['age', 'birth_date',
                                                      'computers', 'id',
                                                      'name', 'other']))
     relations = _get_relations(self.Person)
     self.assertEqual(relations, ['computers'])
Example #2
0
    def serialize(self, exclude_columns=None, exclude_relations=None, include_columns=None, include_relations=None):

        relations = frozenset(_get_relations(self))
        # do not follow relations that will not be included in the response
        if include_columns is not None:
            cols = frozenset(include_columns)
            rels = frozenset(include_relations)
            relations &= (cols | rels)
        elif exclude_columns is not None:
            relations -= frozenset(exclude_columns)
        deep = dict((r, {}) for r in relations)
# FIXME: необходимо реализавать фильтрацию по атрибутам и связям 
#        result = _to_dict(instance=self, deep=deep, exclude=exclude_columns, include=include_columns, exclude_relations=exclude_relations, include_relations=include_relations)
        result = _to_dict(instance=self, deep=deep)

        return result
Example #3
0
 def test_get_relations(self):
     """Tests getting the names of the relations of a model as strings."""
     relations = _get_relations(self.Person)
     self.assertEqual(relations, ['computers'])
Example #4
0
 def test_get_relations(self):
     """Tests getting the names of the relations of a model as strings."""
     relations = _get_relations(self.Person)
     self.assertEqual(relations, ["computers"])