METADATA 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. Metadata-Version: 2.0
  2. Name: mixer
  3. Version: 6.1.3
  4. Summary: Mixer -- Is a fixtures replacement. Supported Django ORM, SqlAlchemy ORM, Mongoengine ODM and custom python objects.
  5. Requires-Dist: Faker (==0.9.1)
  6. Home-page: http://github.com/klen/mixer
  7. Author: Kirill Klenov
  8. Author-email: horneds@gmail.com
  9. License: BSD
  10. Description-Content-Type: UNKNOWN
  11. Description: |logo| Mixer
  12. ############
  13. Mixer is an application to generate instances of Django or SQLAlchemy models.
  14. It's useful for testing and fixtures replacement. Fast and convenient test-data
  15. generation.
  16. Mixer supports:
  17. * Django_;
  18. * SQLAlchemy_;
  19. * Flask-SQLAlchemy_;
  20. * Peewee_;
  21. * Pony_;
  22. * Mongoengine_;
  23. * Marshmallow_;
  24. * Custom schemes;
  25. .. _badges:
  26. .. image:: http://img.shields.io/travis/klen/mixer.svg?style=flat-square
  27. :target: http://travis-ci.org/klen/mixer
  28. :alt: Build Status
  29. .. image:: http://img.shields.io/coveralls/klen/mixer.svg?style=flat-square
  30. :target: https://coveralls.io/r/klen/mixer
  31. :alt: Coverals
  32. .. image:: http://img.shields.io/pypi/v/mixer.svg?style=flat-square
  33. :target: https://pypi.python.org/pypi/mixer
  34. :alt: Version
  35. .. image:: http://img.shields.io/pypi/dm/mixer.svg?style=flat-square
  36. :target: https://pypi.python.org/pypi/mixer
  37. :alt: Downloads
  38. .. image:: http://img.shields.io/pypi/l/mixer.svg?style=flat-square
  39. :target: https://pypi.python.org/pypi/mixer
  40. :alt: License
  41. .. _documentation:
  42. **Docs are available at https://mixer.readthedocs.org/. Pull requests with
  43. documentation enhancements and/or fixes are awesome and most welcome.**
  44. Описание на русском языке: http://klen.github.io/mixer.html
  45. .. _contents:
  46. .. contents::
  47. Requirements
  48. =============
  49. - Django (1.11, 2.1) for Django ORM support;
  50. - Faker >= 0.7.3
  51. - Flask-SQLALchemy for SQLAlchemy ORM support and integration as Flask application;
  52. - Mongoengine for Mongoengine ODM support;
  53. - SQLAlchemy for SQLAlchemy ORM support;
  54. - Peewee ORM support;
  55. - fake-factory >= 0.5.0
  56. - faker == 0.7.3
  57. - python 2.7 or 3.6+
  58. Installation
  59. =============
  60. **Mixer** should be installed using pip: ::
  61. pip install mixer
  62. Usage
  63. =====
  64. | By default Mixer tries to generate a fake (human-friendly) data.
  65. | If you want to randomize the generated values initialize the Mixer
  66. | by manual: Mixer(fake=False)
  67. | By default Mixer saves the generated objects in a database. If you want to disable
  68. | this, initialize the Mixer by manual like: Mixer(commit=False)
  69. Django workflow
  70. ---------------
  71. Quick example: ::
  72. from mixer.backend.django import mixer
  73. from customapp.models import User, UserMessage
  74. # Generate a random user
  75. user = mixer.blend(User)
  76. # Generate an UserMessage
  77. message = mixer.blend(UserMessage, user=user)
  78. # Generate an UserMessage and an User. Set username for generated user to 'testname'.
  79. message = mixer.blend(UserMessage, user__username='testname')
  80. # Generate SomeModel from SomeApp and select FK or M2M values from db
  81. some = mixer.blend('someapp.somemodel', somerelation=mixer.SELECT)
  82. # Generate SomeModel from SomeApp and force a value of money field from default to random
  83. some = mixer.blend('someapp.somemodel', money=mixer.RANDOM)
  84. # Generate 5 SomeModel's instances and take company field's values from custom generator
  85. some_models = mixer.cycle(5).blend('somemodel', company=(name for name in company_names))
  86. Flask, Flask-SQLAlchemy
  87. -----------------------
  88. Quick example: ::
  89. from mixer.backend.flask import mixer
  90. from models import User, UserMessage
  91. mixer.init_app(self.app)
  92. # Generate a random user
  93. user = mixer.blend(User)
  94. # Generate an userMessage
  95. message = mixer.blend(UserMessage, user=user)
  96. # Generate an UserMessage and an User. Set username for generated user to 'testname'.
  97. message = mixer.blend(UserMessage, user__username='testname')
  98. # Generate SomeModel and select FK or M2M values from db
  99. some = mixer.blend('project.models.SomeModel', somerelation=mixer.SELECT)
  100. # Generate SomeModel from SomeApp and force a value of money field from default to random
  101. some = mixer.blend('project.models.SomeModel', money=mixer.RANDOM)
  102. # Generate 5 SomeModel's instances and take company field's values from custom generator
  103. some_models = mixer.cycle(5).blend('project.models.SomeModel', company=(company for company in companies))
  104. Support for Flask-SQLAlchemy models that have `__init__` arguments
  105. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  106. For support this scheme, just create your own mixer class, like this: ::
  107. from mixer.backend.sqlalchemy import Mixer
  108. class MyOwnMixer(Mixer):
  109. def populate_target(self, values):
  110. target = self.__scheme(**values)
  111. return target
  112. mixer = MyOwnMixer()
  113. SQLAlchemy workflow
  114. -------------------
  115. Example of initialization: ::
  116. from mixer.backend.sqlalchemy import Mixer
  117. ENGINE = create_engine('sqlite:///:memory:')
  118. BASE = declarative_base()
  119. SESSION = sessionmaker(bind=ENGINE)
  120. mixer = Mixer(session=SESSION(), commit=True)
  121. role = mixer.blend('package.models.Role')
  122. Also, see `Flask, Flask-SQLALchemy`_.
  123. Mongoengine workflow
  124. --------------------
  125. Example usage: ::
  126. from mixer.backend.mongoengine import mixer
  127. class User(Document):
  128. created_at = DateTimeField(default=datetime.datetime.now)
  129. email = EmailField(required=True)
  130. first_name = StringField(max_length=50)
  131. last_name = StringField(max_length=50)
  132. username = StringField(max_length=50)
  133. class Post(Document):
  134. title = StringField(max_length=120, required=True)
  135. author = ReferenceField(User)
  136. tags = ListField(StringField(max_length=30))
  137. post = mixer.blend(Post, author__username='foo')
  138. Marshmallow workflow
  139. --------------------
  140. Example usage: ::
  141. from mixer.main import mixer
  142. import marshmallow as ma
  143. class User(ma.Schema):
  144. created_at = ma.fields.DateTime(required=True)
  145. email = ma.fields.Email(required=True)
  146. first_name = ma.fields.String(required=True)
  147. last_name = ma.fields.String(required=True)
  148. username = ma.fields.String(required=True)
  149. class Post(ma.Schema):
  150. title = ma.fields.String(required=True)
  151. author = ma.fields.Nested(User, required=True)
  152. post = mixer.blend(Post, author__username='foo')
  153. Common usage
  154. ------------
  155. Quick example: ::
  156. from mixer.main import mixer
  157. class Test:
  158. one = int
  159. two = int
  160. name = str
  161. class Scheme:
  162. name = str
  163. money = int
  164. male = bool
  165. prop = Test
  166. scheme = mixer.blend(Scheme, prop__one=1)
  167. DB commits
  168. ----------
  169. By default 'django', 'flask', 'mongoengine' backends tries to save objects in
  170. database. For preventing this behavior init `mixer` manually: ::
  171. from mixer.backend.django import Mixer
  172. mixer = Mixer(commit=False)
  173. Or you can temporary switch context use the mixer as context manager: ::
  174. from mixer.backend.django import mixer
  175. # Will be save to db
  176. user1 = mixer.blend('auth.user')
  177. # Will not be save to db
  178. with mixer.ctx(commit=False):
  179. user2 = mixer.blend('auth.user')
  180. .. _custom:
  181. Custom fields
  182. -------------
  183. Mixer allows you to define generators for fields by manually.
  184. Quick example: ::
  185. from mixer.main import mixer
  186. class Test:
  187. id = int
  188. name = str
  189. mixer.register(Test,
  190. name=lambda: 'John',
  191. id=lambda: str(mixer.g.get_positive_integer())
  192. )
  193. test = mixer.blend(Test)
  194. test.name == 'John'
  195. isinstance(test.id, str)
  196. # You could pinned just a value to field
  197. mixer.register(Test, name='Just John')
  198. test = mixer.blend(Test)
  199. test.name == 'Just John'
  200. Also, you can make your own factory for field types: ::
  201. from mixer.backend.django import Mixer, GenFactory
  202. def get_func(*args, **kwargs):
  203. return "Always same"
  204. class MyFactory(GenFactory):
  205. generators = {
  206. models.CharField: get_func
  207. }
  208. mixer = Mixer(factory=MyFactory)
  209. Middlewares
  210. -----------
  211. You can add middleware layers to process generation: ::
  212. from mixer.backend.django import mixer
  213. # Register middleware to model
  214. @mixer.middleware('auth.user')
  215. def encrypt_password(user):
  216. user.set_password('test')
  217. return user
  218. You can add several middlewares. Each middleware should get one argument
  219. (generated value) and return them.
  220. It's also possible to unregister a middleware: ::
  221. mixer.unregister_middleware(encrypt_password)
  222. Locales
  223. -------
  224. By default mixer uses 'en' locale. You could switch mixer default locale by
  225. creating your own mixer: ::
  226. from mixer.backend.django import Mixer
  227. mixer = Mixer(locale='it')
  228. mixer.faker.name() ## u'Acchisio Conte'
  229. At any time you could switch mixer current locale: ::
  230. mixer.faker.locale = 'cz'
  231. mixer.faker.name() ## u'Miloslava Urbanov\xe1 CSc.'
  232. mixer.faker.locale = 'en'
  233. mixer.faker.name() ## u'John Black'
  234. # Use the mixer context manager
  235. mixer.faker.phone() ## u'1-438-238-1116'
  236. with mixer.ctx(locale='fr'):
  237. mixer.faker.phone() ## u'08 64 92 11 79'
  238. mixer.faker.phone() ## u'1-438-238-1116'
  239. .. _bugtracker:
  240. Bug tracker
  241. ===========
  242. If you have any suggestions, bug reports or
  243. annoyances please report them to the issue tracker
  244. at https://github.com/klen/mixer/issues
  245. Contributing
  246. ============
  247. Development of mixer happens at Github: https://github.com/klen/mixer
  248. Contributors
  249. =============
  250. * Antoine Bertin (https://github.com/Diaoul)
  251. * Benjamin Port (https://github.com/bport)
  252. * Dmitriy Moseev (https://github.com/DmitriyMoseev)
  253. * Eelke Hermens (https://github.com/eelkeh)
  254. * Esteban J. G. Gabancho (https://github.com/egabancho)
  255. * Felix Dreissig (https://github.com/F30)
  256. * Illia Volochii (https://github.com/illia-v)
  257. * Jannis (https://github.com/jnns)
  258. * Kirill Pavlov (https://github.com/pavlov99)
  259. * Kwok-kuen Cheung (https://github.com/cheungpat)
  260. * Mahdi Yusuf (https://github.com/myusuf3)
  261. * Marek Baczyński (https://github.com/imbaczek)
  262. * Marigold (https://github.com/Marigold)
  263. * Matt Caldwell (https://github.com/mattcaldwell)
  264. * Mikhail Porokhovnichenko (https://github.com/marazmiki)
  265. * Skylar Saveland (https://github.com/skyl)
  266. * Suriya Subramanian (https://github.com/suriya)
  267. * Gram (https://github.com/orsinium)
  268. License
  269. =======
  270. Licensed under a `BSD license`_.
  271. .. _links:
  272. .. _BSD license: http://www.linfo.org/bsdlicense.html
  273. .. _Django: http://djangoproject.com/
  274. .. _Flask-SQLAlchemy: http://flask-sqlalchemy.pocoo.org/
  275. .. _Flask: http://flask.pocoo.org/
  276. .. _Marshmallow: http://marshmallow.readthedocs.io/en/latest/
  277. .. _Mongoengine: http://mongoengine.org/
  278. .. _Peewee: http://peewee.readthedocs.org/en/latest/
  279. .. _Pony: http://ponyorm.com/
  280. .. _SQLAlchemy: http://www.sqlalchemy.org/
  281. .. _klen: http://klen.github.io
  282. .. |logo| image:: https://raw.github.com/klen/mixer/develop/docs/_static/logo.png
  283. :width: 100
  284. Keywords: django,flask,sqlalchemy,testing,mock,stub,mongoengine,data
  285. Platform: Any
  286. Classifier: Development Status :: 4 - Beta
  287. Classifier: Intended Audience :: Developers
  288. Classifier: License :: OSI Approved :: BSD License
  289. Classifier: Natural Language :: English
  290. Classifier: Natural Language :: Russian
  291. Classifier: Operating System :: OS Independent
  292. Classifier: Programming Language :: Python :: 2
  293. Classifier: Programming Language :: Python :: 2.7
  294. Classifier: Programming Language :: Python :: 3
  295. Classifier: Programming Language :: Python :: 3.5
  296. Classifier: Programming Language :: Python :: 3.6
  297. Classifier: Programming Language :: Python
  298. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  299. Classifier: Topic :: Software Development :: Testing
  300. Classifier: Topic :: Utilities