Revision 4054c46d

b/docs/developers/connection.rst
5 5

  
6 6
Since version 0.6 it is safe to use threaded connections.
7 7

  
8
The Connection package uses httplib, standard python threads and a connection pooling mechanism.
9

  
10
.. note:: Since version 0.6.2 the underlying pooling mechanism is packed in a new GRNET package called *objpool*.
8
The Connection package uses httplib, standard python threads and a connection pooling mechanism, which is imported from the *objpool* package.
11 9

  
12 10
.. automodule:: kamaki.clients.connection
13 11
    :members:
b/docs/developers/extending-clients-api.rst
94 94
                event = SilentEvent(self._single_threaded_method, **args)
95 95
                event.start()
96 96
                thread_list.append(event)
97
                thread_list = self._watch_thread_limit(thread_list)
97
                thread_list = self._watch_thread_limit(thread_list)
98

  
99
Going agile
100
-----------
101

  
102
The kamaki.clients package contains a set of fine-grained unit-tests for all its packages. 
103

  
104
.. note:: unit tests require the optional python-mock package, version 1.X or better
105

  
106
Using the tests
107
^^^^^^^^^^^^^^^
108

  
109
To run the tests, the kamaki source code has to be downloaded.
110

  
111
.. code-block:: console
112

  
113
    $ git clone https://code.grnet.gr/git/kamaki
114
    $ cd kamaki/kamaki/clients
115

  
116
In each package under kamaki.clients, there is a test module (test.py) where the tests are implemented. To run all tests, run the test.py file from kamaki.clients
117

  
118
.. code-block:: console
119

  
120
    $ python test.py
121

  
122
To test a specific class, add the class name as an argument. E.g. for the Client class:
123

  
124
.. code-block:: console
125

  
126
    $ python test.py Client
127

  
128
To test a specific method in a class, apply an extra argument, e.g. for the request method in the Client class:
129

  
130
.. code-block:: console
131

  
132
    $ python test.py Client request
133

  
134
Each package contains a test module (test.py) which is also runnable from the command line. E.g. the pithos package contains a Pithos test which contains, among others, the download sub-test:
135

  
136
.. code-block:: console
137

  
138
    $ cd pithos
139

  
140
    # Run all kamaki.clients.pithos tests
141
    $ python test.py
142

  
143
    # Run all kamaki.clients.pithos.PithoClient tests
144
    $ python test.py Pithos
145

  
146
    # Test kamaki.clients.pithos.PithosClient.download
147
    $ python test.py Pithos download
148

  
149
Mechanism
150
^^^^^^^^^
151

  
152
Each folder / package contains a test.py file, that represents the test module of this package. All test modules contain a set of classes that extent the TestCase class. They also contain a main method to run the tests.
153

  
154
All classes in the tested package are tested by similarly-named classes in the test module. Methods that do no belong to a class are tested by testing classes named after the module tested methods belong to.
155

  
156
For example, the kamaki.clients.pithos.PithosClient class is tested by the kamaki.clients.pithos.test.Pithos class, which the method in the kamaki.clients.utils module are tested by the kamaki.clients.utils.test.Utils testing class.
157

  
158

  
159
Adding unit tests
160
^^^^^^^^^^^^^^^^^
161
After modifying or extending kamaki.clients method, classes, modules or packages, it is a good practice to also modify or extend the corresponding unit tests. What's more, it is recommended to modify or implement the tests that test the new behavior, before implementing the behavior itself.
162

  
163
Modifying an existing method
164
""""""""""""""""""""""""""""
165

  
166
In case of an existing method modification, the programmer has to modify the corresponding test as well. By convention, the test method is located in the test module under the same package, in a TestCase subclass that is named with a name similar to the package or class that contains the tested method.
167

  
168
Example 1: to modify the kamaki.clients.utils.filter_in method, the programmer has to also adjust the kamaki.clients.utils.test.Utils.test_filter_in method.
169

  
170
Example 2: to modify the kamaki.clients.pithos.PithosRestClient.object_get, the programmer has to also adjust the kamaki.clients.pithos.test.PithosRest.test_object_get method.
171

  
172
Adding a new method
173
"""""""""""""""""""
174

  
175
Programmers who want to implement a new method in an existing class, are encouraged to implement the corresponding unit test first. In order to do that, they should first find the testing class that is mapped to the class they need to extend.
176

  
177
Example 1: To add a **list_special** method to kamaki.clients.astakos.AstakosClient, extend the kamaki.clients.astakos.test.Astakos test class, as shown bellow:
178

  
179
.. code-block:: python
180

  
181
    class Astakos(TestCase):
182
        ...
183
        def test_list_special(self):
184
            """Test the list_special method"""
185
            ...
186

  
187
Example 2: To add a **get_random_int** method in kamaki.clients.utils module, extend the kamaki.clients.utils.test.Utils test class, as shown bellow:
188

  
189
.. code-block:: python
190

  
191
    class Utils(TestCase):
192
        ...
193
        def test_get_random_int(self):
194
            """Test the get_random_int method"""
195
            ...
196

  
197
Implementing a new class or module
198
""""""""""""""""""""""""""""""""""
199

  
200
Each class or module needs a seperate test sub-module. By convention, each class or module under the kamaki.clients should be located in a separate directory.
201

  
202
Example 1: To add a NewService class, that extents the kamaki.clients.Client interface: 
203

  
204
* create a new_service package and implement the unit tests in the kamaki.clients.new_service.test module:
205

  
206
.. code-block:: console
207

  
208
    $ mkdir new_service && touch new_service/test.py
209

  
210
* create the file that will hold the package code and implement the module there:
211

  
212
.. code-block:: console
213

  
214
    $ touch new_service/__init__.py
215

  
216
* Create the test class and methods in kamaki.clients.new_service.test
217

  
218
.. code-block:: python
219

  
220
    from unittest import TestCase
221

  
222
    class NewServiceTest(TestCase):
223

  
224
        def test_method1(self):
225
            ...
226

  
227
* Create the NewService and its actual functionality in kamaki.clients.new_service
228

  
229
.. code-block:: python
230

  
231
    from kamaki.clients import Client
232

  
233
    class NewService(Client):
234

  
235
        def method1(self, ...):
236
            ...
237

  
238
* Expose the new tests to top test module, by importing the test class to kamaki.clients.test
239

  
240
..code-block:: python
241

  
242
    # kamaki.clients.test module
243
    ...
244
    from kamaki.clients.new_service.test import NewService
245

  
246
.. note:: If the new class or module is part of an existing sub-package, it is best to append its testing class in the existing test.py file of the sub-package it belongs to. For example, the kamaki.clients.pithos.PithosClient and kamaki.clients.pithos.rest_api.PithosRestClient classes are tested by two different classes (Pithos and PithosRest) in the same module (kamaki.clients.pithos.test).
247

  
b/docs/installation.rst
66 66

  
67 67
        $ sudo apt-get install kamaki
68 68

  
69
Install ansicolors and/or progress (Optional but recommended)
70
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
69
Install ansicolors (optional but recommended)
70
"""""""""""""""""""""""""""""""""""""""""""""
71 71

  
72 72
.. code-block:: console
73 73

  
74 74
    $ sudo apt-get install python-ansicolors
75
    $ sudo apt-get install python-progress
75

  
76
Install mock (for developers only)
77
""""""""""""""""""""""""""""""""""
78

  
79
.. code-block:: console
80

  
81
    $ sudo apt-get install python-mock
82

  
83
.. warning:: kamaki.clients unit-tests need python-mock 1.X or better. e.g.::
84

  
85
    $ sudo apt-get install python-mock=1.0.1
76 86

  
77 87
.. _installing-from-pypi-ref:
78 88

  
......
110 120

  
111 121
    $ pip install kamaki
112 122

  
113
Install ansicolors / progress
114
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115

  
116
Packages **ansicolors** and **progress** are not required for running kamaki, but
117
they are recommended as a user experience improvement. In specific, ansicolors
118
adds colors to kamaki responses and progress adds progressbars to the commands
119
that can make use of it (*/store download*, */store upload*, */server wait* etc.)
120

  
121
Debian and Ubuntu
122
"""""""""""""""""
123
Install ansicolors
124
""""""""""""""""""
123 125

  
124
Follow the `Debian <#debian>`_ or `Ubuntu <#ubuntu>`_ installation procedure described earlier
125
and then type:
126
The **ansicolors** package is not required for running kamaki, but it is
127
recommended as a user experience improvement. In specific, ansicolors
128
adds colors to kamaki responses.
126 129

  
127 130
.. code-block:: console
128 131

  
129
    #For ansicolors
130
    $ sudo apt-get install python-ansicolors
131

  
132
    # For progress
133
    $ sudo apt-get install python-progress
132
    $ pip install ansicolors
134 133

  
135
From source
136
"""""""""""
134
Install mock
135
""""""""""""
137 136

  
138
If setuptools is not installed, `install them <http://pypi.python.org/pypi/setuptools>`_ and then type:
137
The **mock** package is needed for running the prepared unit-tests in the kamaki.clients
138
package. This feature is useful when extendnig / debugging kamaki functionality and is
139
aimed to kamaki developers and contributors. Therefore, users can enjoy the full kamaki
140
user experience without installing mock.
139 141

  
140 142
.. code-block:: console
141 143

  
142
    #For ansicolors
143
    $ pip install ansicolors
144
    $ pip install mock
144 145

  
145
    #For progress
146
    $ pip install progress
146
.. warning:: mock version >= 1.X
147 147

  
148 148
Mac OS X
149 149
--------
......
209 209
.. code-block:: console
210 210

  
211 211
    $ easy_setup kamaki
212

  
213
Install progress (optional)
214
^^^^^^^^^^^^^^^^^^^^^^^^^^^
215

  
216
progress: command-line progress bars (in some commands)
217

  
218
.. code-block:: console
219

  
220
    $ easy_setup progress
221

  
b/docs/setup.rst
21 21
Optional features
22 22
-----------------
23 23

  
24
For installing any all of the following, consult the `kamaki installation guide <installation.html#install-progress-and-or-ansicolors-optional>`_
24
For installing any or all of the following, consult the `kamaki installation guide <installation.html#install-ansicolors>`_
25 25

  
26 26
* ansicolors
27 27
    * Make command line / console user interface responses prettier with text formating (colors, bold, etc.)
28 28
    * Can be switched on/off in kamaki configuration file: colors=on/off
29
    * Has not been tested on non unix / linux based platforms
29 30

  
30
* progress 
31
    * Attach progress bars to various kamaki commands (e.g. kamaki store upload)
32
    * If desired, progress version should be 1.0.2 or better
31
* mock 
32
    * For kamaki contributors only
33
    * Allow unittests to run on kamaki.clients package
34
    * Needs mock version 1.X or better
33 35

  
34 36
Any of the above features can be installed at any time before or after kamaki installation.
35 37

  
......
257 259
    url=<URL of quotaholder service>
258 260

  
259 261
Quotaholder is not tested in livetest
262

  
263
The unit testing system
264
"""""""""""""""""""""""
265

  
266
Kamaki container a set of finegrained unit tests for the kamaki.clients package. This set is not used when kamaki is running. Instead, it is aimed to developers who debug or extent the kamaki clients library. For more information, check the `Going Agile <developers/extending-clients-api.html#going-agile>`_ entry at the `developers section <developers/extending-clients-api.html>`_.
b/setup.py
40 40
import kamaki
41 41

  
42 42

  
43
optional = ['ansicolors',
44
            'progress>=1.0.2']
45
requires = ['objpool', 'mock']
43
optional = ['ansicolors', 'mock>=1.0.1']
44

  
45
requires = ['objpool', 'progress>=1.1']
46 46

  
47 47
if version_info < (2, 7):
48 48
    requires.append('argparse')

Also available in: Unified diff