Exemplo n.º 1
0
    def __new__(mcs, name, bases, dct):
        dct['DoesNotExist'] = type('DoesNotExist', (errors.DoesNotExist,),
                                   {})

        # Every document shall have a unique id
        if '_id' not in dct:
            dct['_id'] = fields.ObjectId(required=True)
        elif not isinstance(dct['_id'], fields.Field):
            raise TypeError("Cannot only declare an _id attribute of type " \
                            "mongo.fields.Field.")

        mcs.__collection = None

        collection = dct.get('__collection__')

        if collection is None:
            # Dirty pluralization here
            collection = text.camelcase_to_underscore(name) + 's'

        mcs.__collection__ = collection
        dct['__collection__'] = collection

        return fields.FieldMapper.__new__(mcs, name, bases, dct)
Exemplo n.º 2
0
 def test_camelcase_to_underscore(self):
     for key, value in self.VALUES:
         self.assertEqual(value, camelcase_to_underscore(key))