You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/03/25 15:27:25 UTC

[27/50] git commit: [#7208] ticket:549 Add tests for DOAP

[#7208] ticket:549 Add tests for DOAP


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/3f4a1fb9
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/3f4a1fb9
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/3f4a1fb9

Branch: refs/heads/db/5995
Commit: 3f4a1fb91f26b0ee816f6b74b926a956f57488ba
Parents: 19cbbfa
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Feb 26 15:45:07 2014 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed Mar 12 20:47:55 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           |  2 +-
 Allura/allura/tests/functional/test_rest.py | 67 ++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3f4a1fb9/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 2985c55..8610462 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -310,5 +310,5 @@ class ProjectRestController(object):
         if 'doap' in kw:
             response.headers['Content-Type'] = ''
             response.content_type = 'application/rdf+xml'
-            return c.project.doap()
+            return '<?xml version="1.0" encoding="UTF-8" ?>' + c.project.doap()
         return c.project.__json__()

http://git-wip-us.apache.org/repos/asf/allura/blob/3f4a1fb9/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index 03e8316..500e88f 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -23,6 +23,7 @@ from pylons import app_globals as g
 import mock
 from nose.tools import assert_equal, assert_in, assert_not_in
 from ming.odm import ThreadLocalODMSession
+from datatree import Node
 
 from allura.tests import decorators as td
 from alluratest.controller import TestRestApiBase
@@ -30,6 +31,8 @@ from allura.lib import helpers as h
 from allura.lib.exceptions import Invalid
 from allura import model as M
 
+from forgetracker.tracker_main import ForgeTrackerApp
+
 
 class TestRestHome(TestRestApiBase):
 
@@ -223,3 +226,67 @@ class TestRestHome(TestRestApiBase):
                 'name', 'value', {})
             r = self.api_get('/rest/p/test/')
             assert r.status_int == 404
+
+class TestDoap(TestRestApiBase):
+    validate_skip = True
+    ns = '{http://usefulinc.com/ns/doap#}'
+    ns_sf = '{http://sourceforge.net/api/sfelements.rdf#}'
+    foaf = '{http://xmlns.com/foaf/0.1/}'
+
+    def test_project_data(self):
+        r = self.app.get('/rest/p/test?doap')
+        assert_equal(r.content_type, 'application/rdf+xml')
+        p = r.xml.find(self.ns + 'Project')
+        assert_equal(p.find(self.ns + 'name').text, 'Test Project')
+        assert_equal(p.find(self.ns_sf + 'shortname').text, 'test')
+        assert p.find(self.ns_sf + 'id') is not None
+
+        maintainers = p.findall(self.ns + 'maintainer')
+        assert_equal(len(maintainers), 1)
+        user = maintainers[0].find(self.foaf + 'Person')
+        assert_equal(user.find(self.foaf + 'name').text, 'Test Admin')
+        assert_equal(user.find(self.foaf + 'nick').text, 'test-admin')
+        assert_equal(user.find(self.foaf + 'homepage').items()[0][1],
+                     'http://localhost/u/test-admin/')
+
+    @td.with_tool('test', 'Tickets', 'bugs')
+    @td.with_tool('test', 'Tickets', 'private-bugs')
+    def test_project_data_tools(self):
+        # Deny anonymous to see 'private-bugs' tool
+        role = M.ProjectRole.by_name('*anonymous')._id
+        read_permission = M.ACE.allow(role, 'read')
+        app = M.Project.query.get(
+            shortname='test').app_instance('private-bugs')
+        if read_permission in app.config.acl:
+            app.config.acl.remove(read_permission)
+
+        # admin sees both 'Tickets' tools
+        r = self.app.get('/rest/p/test?doap')
+        p = r.xml.find(self.ns + 'Project')
+        tools = p.findall(self.ns_sf + 'feature')
+        tools = [(t.find(self.ns_sf + 'Feature').find(self.ns + 'name').text,
+                  t.find(self.ns_sf + 'Feature').find(self.foaf + 'page').items()[0][1])
+                 for t in tools]
+        assert_in(('Tickets', 'http://localhost/p/test/bugs/'), tools)
+        assert_in(('Tickets', 'http://localhost/p/test/private-bugs/'), tools)
+
+        # anonymous sees only non-private tool
+        r = self.app.get('/rest/p/test?doap',
+                         extra_environ={'username': '*anonymous'})
+        p = r.xml.find(self.ns + 'Project')
+        tools = p.findall(self.ns_sf + 'feature')
+        tools = [(t.find(self.ns_sf + 'Feature').find(self.ns + 'name').text,
+                  t.find(self.ns_sf + 'Feature').find(self.foaf + 'page').items()[0][1])
+                 for t in tools]
+        assert_in(('Tickets', 'http://localhost/p/test/bugs/'), tools)
+        assert_not_in(('Tickets', 'http://localhost/p/test/private-bugs/'), tools)
+
+    @td.with_tool('test', 'Tickets', 'bugs')
+    def test_tools_additional_entries(self):
+        with mock.patch.object(ForgeTrackerApp, 'additional_doap_entries') as add:
+            add.return_value = [Node('additional-entry1', 'some text1'),
+                                Node('additional-entry2', 'some text2'),]
+            r = self.app.get('/rest/p/test?doap')
+        p = r.xml.find(self.ns + 'Project')
+        assert_equal(p.find(self.ns + 'additional-entry1').text, 'some text1')
+        assert_equal(p.find(self.ns + 'additional-entry2').text, 'some text2')