diff options
author | Jauhien Piatlicki (jauhien) <piatlicki@gmail.com> | 2013-09-16 02:19:17 +0200 |
---|---|---|
committer | Jauhien Piatlicki (jauhien) <piatlicki@gmail.com> | 2013-09-16 02:19:17 +0200 |
commit | 4210ddc888ca6146467897a7023a3648457b13ab (patch) | |
tree | 0ae672c99075cf77d4184fdd4ab449890d3421ee | |
parent | tests/server: make server work with python2 (diff) | |
download | g-sorcery-4210ddc888ca6146467897a7023a3648457b13ab.tar.gz g-sorcery-4210ddc888ca6146467897a7023a3648457b13ab.tar.bz2 g-sorcery-4210ddc888ca6146467897a7023a3648457b13ab.zip |
tests/test_PackageDB: initial commit
-rwxr-xr-x | scripts/all_pythons.sh | 2 | ||||
-rw-r--r-- | tests/test_PackageDB.py | 62 |
2 files changed, 63 insertions, 1 deletions
diff --git a/scripts/all_pythons.sh b/scripts/all_pythons.sh index a31dbea..9160dd0 100755 --- a/scripts/all_pythons.sh +++ b/scripts/all_pythons.sh @@ -2,7 +2,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -for VER in 2.7 3.2 3.3 #2.6 to be added later +for VER in 2.7 3.2 3.3 do echo echo "testing python${VER}" diff --git a/tests/test_PackageDB.py b/tests/test_PackageDB.py new file mode 100644 index 0000000..87cf3ea --- /dev/null +++ b/tests/test_PackageDB.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + test_PackageDB.py + ~~~~~~~~~~~~~~~~ + + PackageDB test suite + + :copyright: (c) 2013 by Jauhien Piatlicki + :license: GPL-2, see LICENSE for more details. +""" + +import os +import time +import unittest + +from g_sorcery.compatibility import TemporaryDirectory +from g_sorcery.exceptions import SyncError +from g_sorcery.g_collections import Package +from g_sorcery.package_db import PackageDB + +from tests.base import BaseTest +from tests.server import Server + + +class TestDB(PackageDB): + def get_real_db_uri(self, db_uri): + return db_uri + "/dummy.tar.gz" + + +class TestPackageDB(BaseTest): + + def test_functionality(self): + orig_tempdir = TemporaryDirectory() + orig_path = os.path.join(orig_tempdir.name, "db") + os.makedirs(orig_path) + orig_db = PackageDB(orig_path) + orig_db.add_category("app-test1") + orig_db.add_category("app-test2") + ebuild_data = {"test1": "test1", "test2": "test2"} + orig_db.add_package(Package("app-test1", "test", "1"), ebuild_data) + orig_db.add_package(Package("app-test1", "test", "2")) + orig_db.add_package(Package("app-test1", "test1", "1"), ebuild_data) + orig_db.add_package(Package("app-test2", "test2", "1"), ebuild_data) + orig_db.write_and_manifest() + os.system("cd " + orig_tempdir.name + " && tar cvzf dummy.tar.gz db") + + test_db = TestDB(self.tempdir.name) + self.assertRaises(SyncError, test_db.sync, "127.0.0.1:8080") + + srv = Server(orig_tempdir.name) + srv.start() + test_db.sync("127.0.0.1:8080") + srv.shutdown() + srv.join() + + +def suite(): + suite = unittest.TestSuite() + suite.addTest(TestPackageDB('test_functionality')) + return suite |