incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [9/34] git commit: [#4785] ticket:163 add test for migrate-urls command
Date Tue, 02 Oct 2012 21:30:28 GMT
[#4785] ticket:163 add test for migrate-urls command


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

Branch: refs/heads/db/4968
Commit: c1734727edc0ebf2ec05dbeeeab2813826043b7f
Parents: aead33f
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Sep 7 16:26:37 2012 +0300
Committer: Cory Johns <johnsca@geek.net>
Committed: Tue Oct 2 15:12:31 2012 +0000

----------------------------------------------------------------------
 ForgeShortUrl/forgeshorturl/tests/test_commands.py |   80 +++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c1734727/ForgeShortUrl/forgeshorturl/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/tests/test_commands.py b/ForgeShortUrl/forgeshorturl/tests/test_commands.py
new file mode 100644
index 0000000..fe1313d
--- /dev/null
+++ b/ForgeShortUrl/forgeshorturl/tests/test_commands.py
@@ -0,0 +1,80 @@
+from alluratest.controller import setup_basic_test, setup_global_objects
+from forgeshorturl.command import migrate_urls
+from forgeshorturl.model import ShortUrl
+from allura import model as M
+from mock import patch, MagicMock, Mock
+import datetime
+import time
+
+test_config = 'test.ini#main'
+fmt = '%Y-%m-%d %H:%M'
+
+
+def setUp(self):
+    """Method called by nose before running each test"""
+    setup_basic_test()
+    setup_global_objects()
+
+
+class TableMock(MagicMock):
+
+    def _make_timestamp(self, date):
+        d = datetime.datetime.strptime(date, fmt)
+        return time.mktime(d.timetuple())
+
+    def select(self):
+        m = Mock()
+        m.execute = self.execute
+        return m
+
+    def execute(self):
+        test_urls = [
+            {
+                'short_id': 'g',
+                'url': 'http://google.com',
+                'description': 'Two\nlines',
+                'private': 'N',
+                'create_time': self._make_timestamp('2012-09-01 10:00'),
+                'edit_time': self._make_timestamp('2012-09-01 12:30'),
+                'create_user': 1
+            },
+            {
+                'short_id': 'y',
+                'url': 'http://yahoo.com',
+                'description': 'One line',
+                'private': 'Y',
+                'create_time': self._make_timestamp('2012-09-02 10:00'),
+                'edit_time': self._make_timestamp('2012-09-02 12:30'),
+                'create_user': 1
+            }
+        ]
+        for url in test_urls:
+            yield url
+
+
+@patch('sqlalchemy.Table', TableMock)
+def test_migrate_urls():
+    p = M.Project.query.find().first()
+    assert ShortUrl.query.find({'project_id': p._id}).count() == 0
+
+    cmd = migrate_urls.MigrateUrls('migrate-urls')
+    cmd.run([test_config, 'db_name', str(p._id)])
+    assert ShortUrl.query.find({'project_id': p._id}).count() == 2
+
+    u = ShortUrl.query.get(short_name='g')
+    assert u.url == 'http://google.com'
+    assert u.description == 'Two\nlines'
+    assert not u.private
+    assert u.created == datetime.datetime.strptime('2012-09-01 10:00', fmt)
+    assert u.last_updated == (datetime.datetime
+                                      .strptime('2012-09-01 12:30', fmt))
+    assert u.create_user == M.User.anonymous()._id
+
+    u = ShortUrl.query.get(short_name='y')
+    assert u.url == 'http://yahoo.com'
+    assert u.description == 'One line'
+    assert u.private
+    assert u.created == datetime.datetime.strptime('2012-09-02 10:00', fmt)
+    assert u.last_updated == (datetime.datetime
+                                      .strptime('2012-09-02 12:30', fmt))
+    assert u.create_user == M.User.anonymous()._id


Mime
View raw message