Repository: nephila/python-taiga
Pull request #5 (2015-02-13 13:41:07)

Feature/wiki


Patch:
diff --git a/taiga/client.py b/taiga/client.py
index deb5ccb..64785d3 100644
--- a/taiga/client.py
+++ b/taiga/client.py
@@ -12,6 +12,8 @@ from .models import Severities
 from .models import Priorities
 from .models import IssueStatuses
 from .models import TaskStatuses
+from .models import WikiPages
+from .models import WikiLinks
 from .requestmaker import RequestMaker
 from requests.exceptions import RequestException
 from . import exceptions
@@ -23,6 +25,7 @@ class SearchResult(object):
     tasks = []
     issues = []
     user_stories = []
+    wiki_pages = []
 
 
 class TaigaAPI:
@@ -47,6 +50,8 @@ class TaigaAPI:
         self.task_statuses = TaskStatuses(self.raw_request)
         self.priorities = Priorities(self.raw_request)
         self.user_story_statuses = UserStoryStatuses(self.raw_request)
+        self.wikipages = WikiPages(self.raw_request)
+        self.wikilinks = WikiLinks(self.raw_request)
 
     def search(self, project, text=''):
         result = self.raw_request.get(
@@ -59,6 +64,9 @@ class TaigaAPI:
         search_result.user_stories = self.user_stories.parse_list(
             result['userstories']
         )
+        search_result.wikipages = self.wikipages.parse_list(
+            result['wikipages']
+        )
         return search_result
 
     def auth(self, username, password):
diff --git a/taiga/models/__init__.py b/taiga/models/__init__.py
index 2f531d7..87b036d 100644
--- a/taiga/models/__init__.py
+++ b/taiga/models/__init__.py
@@ -22,11 +22,17 @@ from .models import IssueStatus
 from .models import IssueStatuses
 from .models import TaskStatus
 from .models import TaskStatuses
+from .models import WikiPage
+from .models import WikiPages
+from .models import WikiLink
+from .models import WikiLinks
+
 
 __all__ = [
     'User', 'Users', 'Project', 'Projects', 'UserStory', 'UserStories',
     'Task', 'Tasks', 'Issue', 'Issues', 'Milestone', 'Milestones',
     'Point', 'Points', 'UserStoryStatus', 'UserStoryStatuses',
     'Severity', 'Severities', 'Priority', 'Priorities', 'IssueStatus',
-    'IssueStatuses', 'TaskStatus', 'TaskStatuses'
+    'IssueStatuses', 'TaskStatus', 'TaskStatuses', 'WikiPage', 'WikiPages',
+    'WikiLink', 'WikiLinks'
 ]
diff --git a/taiga/models/models.py b/taiga/models/models.py
index 0dfcfca..5d12aab 100644
--- a/taiga/models/models.py
+++ b/taiga/models/models.py
@@ -487,6 +487,20 @@ class Project(InstanceResource):
     def list_issue_statuses(self):
         return IssueStatuses(self.requester).list(project=self.id)
 
+    def add_wikipage(self, slug, content, **attrs):
+        return WikiPages(self.requester).create(
+            self.id, slug, content, **attrs
+        )
+
+    def list_wikipages(self):
+        return WikiPages(self.requester).list(project=self.id)
+
+    def add_wikilink(self, title, href, **attrs):
+        return WikiLinks(self.requester).create(self.id, title, href, **attrs)
+
+    def list_wikilinks(self):
+        return WikiLinks(self.requester).list(project=self.id)
+
 
 class Projects(ListResource):
 
@@ -495,3 +509,53 @@ class Projects(ListResource):
     def create(self, name, description, **attrs):
         attrs.update({'name': name, 'description': description})
         return self._new_resource(payload=attrs)
+
+
+class WikiAttachment(Attachment):
+
+    endpoint = 'wiki/attachments'
+
+
+class WikiAttachments(Attachments):
+
+    instance = WikiAttachment
+
+
+class WikiPage(InstanceResource):
+
+    endpoint = 'wiki'
+
+    def __unicode__(self):
+        return '{0}'.format(self.slug)
+
+    def attach(self, attached_file, **attrs):
+        return WikiAttachments(self.requester).create(
+            self.project, self.id,
+            attached_file, **attrs
+        )
+
+
+class WikiPages(ListResource):
+
+    instance = WikiPage
+
+    def create(self, project, slug, content, **attrs):
+        attrs.update({'project': project, 'slug': slug, 'content': content})
+        return self._new_resource(payload=attrs)
+
+
+class WikiLink(InstanceResource):
+
+    endpoint = 'wiki-links'
+
+    def __unicode__(self):
+        return '{0}'.format(self.title)
+
+
+class WikiLinks(ListResource):
+
+    instance = WikiLink
+
+    def create(self, project, title, href, **attrs):
+        attrs.update({'project': project, 'title': title, 'href': href})
+        return self._new_resource(payload=attrs)


Test patch:
diff --git a/tests/resources/search_success.json b/tests/resources/search_success.json
index 324d5f8..b01ce85 100644
--- a/tests/resources/search_success.json
+++ b/tests/resources/search_success.json
@@ -118,6 +118,19 @@
         }
     ],
     "wikipages":[
-
+        {
+            "html": "<p>Code style guidelines</p>",
+            "editions": 2,
+            "id": 1,
+            "version": 2,
+            "project": 1,
+            "slug": "code-style",
+            "content": "Follow pep8",
+            "owner": 5,
+            "last_modifier": null,
+            "created_date": "2015-01-01T09:29:53+0000",
+            "modified_date": "2015-01-01T09:29:53+0000",
+            "watchers": []
+        }
     ]
 }
\ No newline at end of file
diff --git a/tests/test_search.py b/tests/test_search.py
index e47e60a..6d79f9f 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -3,7 +3,7 @@ import unittest
 from mock import patch
 from .tools import create_mock_json
 from .tools import MockResponse
-from taiga.models import Task, UserStory, Issue
+from taiga.models import Task, UserStory, Issue, WikiPage
 
 
 class TestSearch(unittest.TestCase):
@@ -17,7 +17,9 @@ class TestSearch(unittest.TestCase):
         self.assertEqual(len(search_result.tasks), 1)
         self.assertEqual(len(search_result.user_stories), 1)
         self.assertEqual(len(search_result.issues), 1)
+        self.assertEqual(len(search_result.wikipages), 1)
 
         self.assertTrue(isinstance(search_result.tasks[0], Task))
         self.assertTrue(isinstance(search_result.issues[0], Issue))
         self.assertTrue(isinstance(search_result.user_stories[0], UserStory))
+        self.assertTrue(isinstance(search_result.wikipages[0], WikiPage))
diff --git a/tests/test_wikilinks.py b/tests/test_wikilinks.py
new file mode 100644
index 0000000..beb9b6e
--- /dev/null
+++ b/tests/test_wikilinks.py
@@ -0,0 +1,23 @@
+from taiga.requestmaker import RequestMaker, RequestMakerException
+from taiga.models.base import InstanceResource, ListResource
+from taiga.models import WikiLink, WikiLinks
+from taiga import TaigaAPI
+import taiga.exceptions
+import json
+import requests
+import unittest
+from mock import patch
+from .tools import create_mock_json
+from .tools import MockResponse
+
+
+class TestWikiLinks(unittest.TestCase):
+
+    @patch('taiga.models.base.ListResource._new_resource')
+    def test_create_wikilink(self, mock_new_resource):
+        rm = RequestMaker('/api/v1', 'fakehost', 'faketoken')
+        mock_new_resource.return_value = WikiLink(rm)
+        wikilink = WikiLinks(rm).create(1, 'Title', 'home')
+        mock_new_resource.assert_called_with(
+            payload={'project': 1, 'title': 'Title', 'href': 'home'}
+        )
diff --git a/tests/test_wikipages.py b/tests/test_wikipages.py
new file mode 100644
index 0000000..ceb04c4
--- /dev/null
+++ b/tests/test_wikipages.py
@@ -0,0 +1,23 @@
+from taiga.requestmaker import RequestMaker, RequestMakerException
+from taiga.models.base import InstanceResource, ListResource
+from taiga.models import WikiPage, WikiPages
+from taiga import TaigaAPI
+import taiga.exceptions
+import json
+import requests
+import unittest
+from mock import patch
+from .tools import create_mock_json
+from .tools import MockResponse
+
+
+class TestWikiPages(unittest.TestCase):
+
+    @patch('taiga.models.base.ListResource._new_resource')
+    def test_create_wikipage(self, mock_new_resource):
+        rm = RequestMaker('/api/v1', 'fakehost', 'faketoken')
+        mock_new_resource.return_value = WikiPage(rm)
+        wikipage = WikiPages(rm).create(1, 'WikiPage-Slug', 'Some content')
+        mock_new_resource.assert_called_with(
+            payload={'project': 1, 'slug': 'WikiPage-Slug', 'content': 'Some content'}
+        )