Add testcases
authorLingchao Xin <lingchaox.xin@intel.com>
Fri, 29 Nov 2013 03:16:11 +0000 (11:16 +0800)
committerLingchao Xin <lingchaox.xin@intel.com>
Fri, 29 Nov 2013 07:17:50 +0000 (15:17 +0800)
Change-Id: I668c9a59fbd3fec6364439f0a92c90c531804a26

.gitignore [new file with mode: 0644]
snapdiff/templates/sparrow.html [new file with mode: 0644]
tests/test_render.py [new file with mode: 0644]
tests/test_utils.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..50a8726
--- /dev/null
@@ -0,0 +1,51 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+bin/
+build/
+develop-eggs/
+dist/
+eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+.tox/
+.coverage
+.cache
+nosetests.xml
+coverage.xml
+
+# Translations
+*.mo
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
+
+# Rope
+.ropeproject
+
+# Django stuff:
+*.log
+*.pot
+
+# Sphinx documentation
+docs/_build/
+
diff --git a/snapdiff/templates/sparrow.html b/snapdiff/templates/sparrow.html
new file mode 100644 (file)
index 0000000..1c01047
--- /dev/null
@@ -0,0 +1,6 @@
+<ul>
+{% for user in users %}
+  <li><a href="{{ user.url }}">{{ user.username }}</a></li>
+{% endfor %}
+</ul>
+
diff --git a/tests/test_render.py b/tests/test_render.py
new file mode 100644 (file)
index 0000000..099f0ff
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+"""Tests for render module."""
+
+import unittest
+from snapdiff import render
+
+
+class RenderTestCase(unittest.TestCase):
+
+    def test_output_html(self):
+        """Ensures that we can properly render html pages"""
+        users = [{'url': 'http://example.com', 'username': 'foo'}]
+        output = render.output_html('sparrow.html', users=users)
+        self.assertEqual(output, u'<ul>\n\n  <li><a href="http://example.com">foo</a></li>\n\n</ul>\n')
+
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644 (file)
index 0000000..48e5982
--- /dev/null
@@ -0,0 +1,38 @@
+"""Tests for utils module."""
+
+import unittest
+from snapdiff import utils
+
+
+class UtilsTestCase(unittest.TestCase):
+
+    _multiprocess_can_split_ = True
+
+    def test_xml2obj(self):
+        """Ensures that we can properly parse xml to python objs"""
+        repomd = """<?xml version="1.0" ?>
+        <repomd>
+          <revision>1385428310</revision>
+          <data type="other_db">
+            <location href="repodata/0b19c6c1677b8ab3f7-other.sqlite.bz2"/>
+            <checksum type="sha256">06d90b19c6c1677b8ab3f7</checksum>
+            <timestamp>1385428316.34</timestamp>
+            <size>251882</size>
+            <open-size>952320</open-size>
+            <open-checksum type="sha256">71428390a3e9423abb</open-checksum>
+            <database_version>10</database_version>
+          </data>
+          <data type="group">
+            <location href="repodata/df569d7923ed3f60943449-group.xml.gz"/>
+            <checksum type="sha256">df569d7923ed3f60943449</checksum>
+            <timestamp>1385428350.75</timestamp>
+            <open-checksum type="sha256">aab93a15ded699ffd46</open-checksum>
+          </data>
+        </repomd>
+        """
+
+        obj = utils.xml2obj(repomd)
+        self.assertEqual(obj.revision, '1385428310')
+        self.assertTrue(isinstance(obj['data'], list))
+        self.assertEqual(obj['data'][0].size, '251882')
+