Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CONTRIBUTING.rst 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. ============
  2. Contributing
  3. ============
  4. Some ground rules:
  5. * To avoid disappointment, new features should be discussed on the mailing list
  6. (django-oscar@googlegroups.com) before serious work starts.
  7. * Write tests! Pull requests will be rejected if sufficient tests aren't
  8. provided. See the guidance below on the testing conventions that Oscar uses.
  9. * Write docs! Please update the documentation when altering behaviour or introducing new features.
  10. * Write good commit messages: see `Tim Pope's excellent note`_.
  11. .. _`Tim Pope's excellent note`: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
  12. * Make pull requests against Oscar's master branch unless instructed otherwise.
  13. Installation
  14. ============
  15. After forking, run::
  16. git clone git@github.com:<username>/django-oscar.git
  17. cd django-oscar
  18. mkvirtualenv oscar # using virtualenvwrapper
  19. make install
  20. Running tests
  21. =============
  22. Oscar uses a nose_ testrunner which can be invoked using::
  23. ./runtests.py
  24. .. _nose: http://nose.readthedocs.org/en/latest/
  25. To run a subset of tests, you can use filesystem or module paths. These two
  26. commands will run the same set of tests::
  27. ./runtests.py tests/unit/order
  28. ./runtests.py tests.unit.order
  29. To run an individual test class, use one of::
  30. ./runtests.py tests/unit/order:TestSuccessfulOrderCreation
  31. ./runtests.py tests.unit.order:TestSuccessfulOrderCreation
  32. (Note the ':'.)
  33. To run an individual test, use one of::
  34. ./runtests.py tests/unit/order:TestSuccessfulOrderCreation.test_creates_order_and_line_models
  35. ./runtests.py tests.unit.order:TestSuccessfulOrderCreation.test_creates_order_and_line_models
  36. Oscar's testrunner uses the progressive_ plugin when running all tests, but uses
  37. the spec_ plugin when running a subset. It is a good practice to name your test
  38. cases and methods so that the spec output reads well. For example::
  39. $ ./runtests.py tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount
  40. nosetests --verbosity 1 tests/unit/offer/benefit_tests.py:TestAbsoluteDiscount -s -x --with-spec
  41. Creating test database for alias 'default'...
  42. Absolute discount
  43. - consumes all lines for multi item basket cheaper than threshold
  44. - consumes all products for heterogeneous basket
  45. - consumes correct quantity for multi item basket more expensive than threshold
  46. - correctly discounts line
  47. - discount is applied to lines
  48. - gives correct discount for multi item basket cheaper than threshold
  49. - gives correct discount for multi item basket more expensive than threshold
  50. - gives correct discount for multi item basket with max affected items set
  51. - gives correct discount for single item basket cheaper than threshold
  52. - gives correct discount for single item basket equal to threshold
  53. - gives correct discount for single item basket more expensive than threshold
  54. - gives correct discounts when applied multiple times
  55. - gives correct discounts when applied multiple times with condition
  56. - gives no discount for a non discountable product
  57. - gives no discount for an empty basket
  58. ----------------------------------------------------------------------
  59. Ran 15 tests in 0.295s
  60. .. _progressive: http://pypi.python.org/pypi/nose-progressive/
  61. .. _spec: http://darcs.idyll.org/~t/projects/pinocchio/doc/#spec-generate-test-description-from-test-class-method-names
  62. Playing in the sandbox
  63. ======================
  64. Oscar ships with a 'sandbox' site which can be run locally to play around with
  65. Oscar using a browser. Set it up by::
  66. make sandbox
  67. cd sites/sandbox
  68. ./manage.py runserver
  69. This will create the database and load some fixtures for categories and shipping
  70. countries.
  71. Note that Oscar uses PIL_ and Sorl_ for thumbnailing, and so you will need
  72. ``libjpeg-dev`` installed in your OS so that your PIL installation supports
  73. JPEGS.
  74. .. _PIL: http://www.pythonware.com/products/pil/
  75. .. _Sorl: http://sorl-thumbnail.readthedocs.org/en/latest/
  76. Vagrant
  77. =======
  78. Oscar ships with a Vagrant_ virtual machine that can be used to test integration
  79. with various services in a controlled environment. For instance, it is used to
  80. test that the migrations run correctly in both MySQL and Postgres.
  81. .. _Vagrant: http://vagrantup.com/
  82. Building the Vagrant machine
  83. ----------------------------
  84. To create the machine, first ensure that Vagrant and puppet_ are installed. You will require a
  85. puppet version that supports ``puppet module install``, that is > 2.7.14. Now
  86. run::
  87. make puppet
  88. .. _puppet: http://docs.puppetlabs.com/guides/installation.html
  89. to fetch the required puppet modules for provisioning. Finally, run::
  90. vagrant up
  91. to create the virtual machine and provision it.
  92. Testing migrations against MySQL and Postgres
  93. ---------------------------------------------
  94. To test the migrations against MySQL and Postgres, do the following:
  95. 1. SSH onto the VM::
  96. vagrant ssh
  97. 2. Change to sandbox folder and activate virtualenv::
  98. cd /vagrant/sites/sandbox
  99. source /var/www/virtualenv/bin/activate
  100. 3. Run helper script::
  101. ./test_migrations.sh
  102. This will recreate the Oscar database in both MySQL and Postgres and rebuild
  103. it using ``syncdb`` and ``migrate``.
  104. Testing WSGI server configurations
  105. ----------------------------------
  106. You can browse the Oscar sandbox site in two ways:
  107. * Start Django's development server on port 8000::
  108. vagrant ssh
  109. cd /vagrant/sites/sandbox
  110. source /var/www/virtualenv/bin/activate
  111. ./manage.py runserver 0.0.0.0:8000
  112. The Vagrant machine forwards port 8000 to post 8080 and so the site can be
  113. accessed at http://localhost:8080 on your host machine.
  114. * The Vagrant machine install Apache2 and mod_wsgi. You can browse the site
  115. through Apache at http://localhost:8081 on your host machine.
  116. Writing LESS/CSS
  117. ================
  118. The sandbox Oscar site defaults to serving the CSS files directly, bypassing
  119. LESS compilation. If you want to develop the LESS files, set::
  120. USE_LESS = True
  121. COMPRESS_ENABLED = False
  122. in ``sites/sandbox/settings_local.py``. You will also need to ensure that
  123. ``lessc`` is installed. This can be acheived by running::
  124. pip install -r requirements_less.txt
  125. which will install the `virtual-node`_ and `virtual-less`_ packages, which will
  126. install node.js and LESS in your virtualenv.
  127. .. _`virtual-node`: https://github.com/elbaschid/virtual-node
  128. .. _`virtual-less`: https://github.com/elbaschid/virtual-less
  129. Writing docs
  130. ============
  131. There's a helper script for building the docs locally::
  132. cd docs
  133. ./test_docs.sh
  134. The actual docs are in ``/docs/source``. This directory structure is a
  135. simplified version of what Django does.
  136. * ``internals/`` contains everything related to Oscar itself, e.g. contributing
  137. guidelines or design philosophies.
  138. * ``ref/`` is the reference documentation, esp. consisting of
  139. * ``ref/apps/`` which should be a guide to each Oscar core app, explaining it's
  140. function, the main models, how it relates to the other apps, etc.
  141. * ``topics/`` will contain "meta" articles, explaining how things tie together
  142. over several apps, or how Oscar can be combined with other solutions.
  143. * ``howto/`` contains tutorial-style descriptions on how to solve a certain
  144. problem. Ideally, those will be kept to a minimum; as the other docs should
  145. be understandable enough that necessary steps to achieve a certain goal are
  146. obvious.
  147. * ``_old/`` contains legacy documents that have not been moved into the new
  148. structure. Please help get rid of those!
  149. ``/index.rst`` is designed as the entry point, and diverges from above
  150. structure to make the documentation more approachable. Other ``index.rst``
  151. files should only be created if there's too many files to list them all.
  152. E.g. ``/index.rst`` directly links to all files in ``topics/`` and
  153. ``internals/``, but there's an ``index.rst`` both for the files in ``howto/``
  154. and ``ref/apps/``.
  155. Conventions
  156. ===========
  157. General
  158. -------
  159. * PEP8 everywhere while remaining sensible
  160. URLs
  161. ----
  162. * List pages should use plurals; e.g. ``/products/``, ``/notifications/``
  163. * Detail pages should simply be a PK/slug on top of the list page; e.g.
  164. ``/products/the-bible/``, ``/notifications/1/``
  165. * Create pages should have 'create' as the final path segment; e.g.
  166. ``/dashboard/notifications/create/``
  167. * Update pages are sometimes the same as detail pages (i.e., when in the
  168. dashboard). In those cases, just use the detail convention, eg
  169. ``/dashboard/notifications/3/``. If there is a distinction between the detail
  170. page and the update page, use ``/dashboard/notifications/3/update/``.
  171. * Delete pages; e.g., ``/dashboard/notifications/3/delete/``
  172. View class names
  173. ----------------
  174. Classes should be named according to::
  175. '%s%sView' % (class_name, verb)
  176. For example, ``ProductUpdateView``, ``OfferCreateView`` and
  177. ``PromotionDeleteView``. This doesn't fit all situations, but it's a good basis.