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