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

CONTRIBUTING.rst 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 # optional but recommended
  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. Vagrant
  72. =======
  73. Oscar ships with a Vagrant_ virtual machine that can be used to test integration
  74. with various services in a controlled environment. For instance, it is used to
  75. test that the migrations run correctly in both MySQL and Postgres.
  76. .. _Vagrant: http://vagrantup.com/
  77. Building the Vagrant machine
  78. ----------------------------
  79. To create the machine, first ensure that vagrant_ and puppet_ are installed. You will require a
  80. puppet version that supports ``puppet module install``, that is > 2.7.14. Now
  81. run::
  82. make puppet
  83. .. _vagrant: http://vagrantup.com/v1/docs/getting-started/index.html
  84. .. _puppet: http://docs.puppetlabs.com/guides/installation.html
  85. to fetch the required puppet modules for provisioning. Finally, run::
  86. vagrant up
  87. to create the virtual machine and provision it.
  88. Testing migrations against MySQL and Postgres
  89. ---------------------------------------------
  90. To test the migrations against MySQL and Postgres, do the following:
  91. 1. SSH onto the VM::
  92. vagrant ssh
  93. 2. Change to sandbox folder and activate virtualenv::
  94. cd /vagrant/sites/sandbox
  95. source /var/www/virtualenv/bin/activate
  96. 3. Run helper script::
  97. ./test_migrations.sh
  98. This will recreate the Oscar database in both MySQL and Postgres and rebuild
  99. it using ``syncdb`` and ``migrate``.
  100. Testing WSGI server configurations
  101. ----------------------------------
  102. You can browse the Oscar sandbox site in two ways:
  103. * Start Django's development server on port 8000::
  104. vagrant ssh
  105. cd /vagrant/sites/sandbox
  106. source /var/www/virtualenv/bin/activate
  107. ./manage.py runserver 0.0.0.0:8000
  108. The Vagrant machine forwards port 8000 to post 8080 and so the site can be
  109. accessed at http://localhost:8080 on your host machine.
  110. * The Vagrant machine install Apache2 and mod_wsgi. You can browse the site
  111. through Apache at http://localhost:8081 on your host machine.
  112. Writing docs
  113. ============
  114. There's a helper script for building the docs locally::
  115. cd docs
  116. ./test_docs.sh
  117. Conventions
  118. ===========
  119. General
  120. -------
  121. * PEP8 everywhere while remaining sensible
  122. URLs
  123. ----
  124. * List pages should use plurals; e.g. ``/products/``, ``/notifications/``
  125. * Detail pages should simply be a PK/slug on top of the list page; e.g.
  126. ``/products/the-bible/``, ``/notifications/1/``
  127. * Create pages should have 'create' as the final path segment; e.g.
  128. ``/dashboard/notifications/create/``
  129. * Update pages are sometimes the same as detail pages (i.e., when in the
  130. dashboard). In those cases, just use the detail convention, eg
  131. ``/dashboard/notifications/3/``. If there is a distinction between the detail
  132. page and the update page, use ``/dashboard/notifications/3/update/``.
  133. * Delete pages; e.g., ``/dashboard/notifications/3/delete/``
  134. View class names
  135. ----------------
  136. Classes should be named according to::
  137. '%s%sView' % (class_name, verb)
  138. For example, ``ProductUpdateView``, ``OfferCreateView`` and
  139. ``PromotionDeleteView``. This doesn't fit all situations, but it's a good basis.