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/02/27 19:52:09 UTC

git commit: [#7225] handle non-artifact related artifacts, with tests!

Repository: incubator-allura
Updated Branches:
  refs/heads/db/7225 3422d6803 -> 3024eda61


[#7225] handle non-artifact related artifacts, with tests!


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

Branch: refs/heads/db/7225
Commit: 3024eda61e139d98377d002982e749cf438646e8
Parents: 3422d68
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Feb 27 18:51:51 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Feb 27 18:51:51 2014 +0000

----------------------------------------------------------------------
 Allura/allura/templates/jinja_master/lib.html   | 13 +++-
 Allura/allura/tests/templates/__init__.py       | 17 +++++
 .../tests/templates/jinja_master/__init__.py    | 17 +++++
 .../tests/templates/jinja_master/test_lib.py    | 80 ++++++++++++++++++++
 4 files changed, 123 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3024eda6/Allura/allura/templates/jinja_master/lib.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/lib.html b/Allura/allura/templates/jinja_master/lib.html
index cad88ef..ecea225 100644
--- a/Allura/allura/templates/jinja_master/lib.html
+++ b/Allura/allura/templates/jinja_master/lib.html
@@ -35,11 +35,16 @@
     <h4>Related</h4>
     <p>
     {% for related in related_artifacts %}
-      {% set tool = related.app_config.options.mount_label %}
-      {% if related.project != artifact.project %}
-        {% set prefix = '%s: %s' % (related.project.name, tool) %}
+      {% if not related.app_config|default %}
+        {# e.g. a Commit is not currently an Artifact #}
+        {% set prefix = related.type_s %}
       {% else %}
-        {% set prefix = tool %}
+        {% set tool = related.app_config.options.mount_label %}
+        {% if related.project != artifact.project %}
+          {% set prefix = '%s: %s' % (related.project.name, tool) %}
+        {% else %}
+          {% set prefix = tool %}
+        {% endif %}
       {% endif %}
       <a href="{{related.url()}}">{{prefix}}: {{related.link_text()}}</a><br>
     {% endfor %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3024eda6/Allura/allura/tests/templates/__init__.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/templates/__init__.py b/Allura/allura/tests/templates/__init__.py
new file mode 100644
index 0000000..77505f1
--- /dev/null
+++ b/Allura/allura/tests/templates/__init__.py
@@ -0,0 +1,17 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3024eda6/Allura/allura/tests/templates/jinja_master/__init__.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/templates/jinja_master/__init__.py b/Allura/allura/tests/templates/jinja_master/__init__.py
new file mode 100644
index 0000000..77505f1
--- /dev/null
+++ b/Allura/allura/tests/templates/jinja_master/__init__.py
@@ -0,0 +1,17 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3024eda6/Allura/allura/tests/templates/jinja_master/test_lib.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/templates/jinja_master/test_lib.py b/Allura/allura/tests/templates/jinja_master/test_lib.py
new file mode 100644
index 0000000..5d3e963
--- /dev/null
+++ b/Allura/allura/tests/templates/jinja_master/test_lib.py
@@ -0,0 +1,80 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from tg import config
+from mock import Mock
+from nose.tools import assert_equal
+
+from allura.config.app_cfg import ForgeConfig
+
+
+def strip_space(s):
+    return ''.join(s.split())
+
+
+class TemplateTest(object):
+    def setUp(self):
+        forge_config = ForgeConfig()
+        forge_config.setup_jinja_renderer()
+        self.jinja2_env = config['pylons.app_globals'].jinja2_env
+
+
+class TestRelatedArtifacts(TemplateTest):
+
+    def _render_related_artifacts(self, artifact):
+        html = self.jinja2_env.from_string('''
+            {% import 'allura:templates/jinja_master/lib.html' as lib with context %}
+            {{ lib.related_artifacts(artifact) }}
+        ''').render(artifact=artifact)
+        return strip_space(html)
+
+    def test_none(self):
+        artifact = Mock(related_artifacts = lambda: [])
+        assert_equal(self._render_related_artifacts(artifact), '')
+
+    def test_simple(self):
+        other = Mock()
+        other.url.return_value = '/p/test/foo/bar'
+        other.project.name = 'Test Project'
+        other.app_config.options.mount_label = 'Foo'
+        other.link_text.return_value = 'Bar'
+        artifact = Mock(related_artifacts = lambda: [other])
+        assert_equal(self._render_related_artifacts(artifact), strip_space('''
+            <h4>Related</h4>
+            <p>
+            <a href="/p/test/foo/bar">Test Project: Foo: Bar</a><br>
+            </p>
+        '''))
+
+    def test_non_artifact(self):
+        # e.g. a commit
+        class CommitThing(object):
+            type_s = 'Commit'
+
+            def link_text(self):
+                return '[deadbeef]'
+
+            def url(self):
+                return '/p/test/code/ci/deadbeef'
+
+        artifact = Mock(related_artifacts = lambda: [CommitThing()])
+        assert_equal(self._render_related_artifacts(artifact), strip_space('''
+            <h4>Related</h4>
+            <p>
+            <a href="/p/test/code/ci/deadbeef">Commit: [deadbeef]</a><br>
+            </p>
+        '''))