Skip to content

Commit

Permalink
crm plugin crm query resource support
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtepkeev committed Sep 18, 2014
1 parent 2b695e8 commit 00141f8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -9,6 +9,7 @@ Changelog
* `ContactTag <http://python-redmine.readthedocs.org/resources/contact_tag.html>`_
* `DealStatus <http://python-redmine.readthedocs.org/resources/deal_status.html>`_
* `DealCategory <http://python-redmine.readthedocs.org/resources/deal_category.html>`_
* `CrmQuery <http://python-redmine.readthedocs.org/resources/crm_query.html>`_

0.9.0 (2014-09-11)
++++++++++++++++++
Expand Down
67 changes: 67 additions & 0 deletions docs/resources/crm_query.rst
@@ -0,0 +1,67 @@
CRM Query
=========

Supported starting from version 1.0.0 and only available if `CRM plugin <http://redminecrm.com/
projects/crm/pages/1>`_ of version 3.3.0 and higher is installed.

Manager
-------

All operations on the crm query resource are provided via it's manager. To get access to
it you have to call ``redmine.crm_query`` where ``redmine`` is a configured redmine object.
See the :doc:`../configuration` about how to configure redmine object.

Create methods
--------------

Not supported by CRM plugin

Read methods
------------

get
+++

Not supported by CRM plugin

all
+++

Not supported by CRM plugin

filter
++++++

.. py:method:: filter(**filters)
:module: redmine.managers.ResourceManager
:noindex:

Returns crm query resources that match the given lookup parameters.

:param string resource:
.. raw:: html

(required). Get crm queries for the requested resource. Available resources are:

- contact
- deal

:param integer limit: (optional). How much resources to return.
:param integer offset: (optional). Starting from what resource to return the other resources.
:return: ResourceSet object

.. code-block:: python
>>> queries = redmine.crm_query.filter(resource='contact')
>>> queries
<redmine.resultsets.ResourceSet object with CrmQuery resources>
Update methods
--------------

Not supported by CRM plugin

Delete methods
--------------

Not supported by CRM plugin
1 change: 1 addition & 0 deletions docs/resources/index.rst
Expand Up @@ -52,3 +52,4 @@ Resources
contact_tag
deal_status
deal_category
crm_query
16 changes: 16 additions & 0 deletions redmine/resources.py
Expand Up @@ -792,6 +792,22 @@ def url(self):
return '{0}/contacts_tags/{1}/edit'.format(self.manager.redmine.url, self.internal_id)


class CrmQuery(_Resource):
redmine_version = '2.3'
requirements = (('CRM plugin', '3.3.0'),)
container_filter = 'queries'
query_filter = '/crm_queries.json?object_type={resource}'

@property
def url(self):
return '{0}/projects/{1}/{2}s?query_id={3}'.format(
self.manager.redmine.url,
self._attributes.get('project_id', 0),
self.manager.params.get('resource', ''),
self.internal_id
)


class DealStatus(_Resource):
redmine_version = '2.3'
requirements = (('CRM plugin', '3.3.0'),)
Expand Down
26 changes: 25 additions & 1 deletion tests/test_resources.py
Expand Up @@ -80,6 +80,9 @@
'deal_category': {
'filter': {'deal_categories': [{'name': 'Foo', 'id': 1}, {'name': 'Bar', 'id': 2}]},
},
'crm_query': {
'filter': {'queries': [{'name': 'Foo', 'id': 1}, {'name': 'Bar', 'id': 2}]},
},
}


Expand Down Expand Up @@ -1184,4 +1187,25 @@ def test_deal_category_url(self):
self.assertEqual(
self.redmine.deal_category.filter(project_id=1)[0].url,
'{0}/deal_categories/edit?id=1'.format(self.url)
)
)

def test_crm_query_version(self):
self.assertEqual(self.redmine.crm_query.resource_class.redmine_version, '2.3')

def test_crm_query_requirements(self):
self.assertEqual(self.redmine.crm_query.resource_class.requirements, (('CRM plugin', '3.3.0'),))

def test_crm_query_filter(self):
self.response.json = json_response(responses['crm_query']['filter'])
queries = self.redmine.crm_query.filter(resource='contact')
self.assertEqual(queries[0].id, 1)
self.assertEqual(queries[0].name, 'Foo')
self.assertEqual(queries[1].id, 2)
self.assertEqual(queries[1].name, 'Bar')

def test_crm_query_url(self):
self.response.json = json_response(responses['crm_query']['filter'])
self.assertEqual(
self.redmine.crm_query.filter(resource='contact')[0].url,
'{0}/projects/0/contacts?query_id=1'.format(self.url)
)

0 comments on commit 00141f8

Please sign in to comment.