~aptdaemon-developers/aptdaemon/1.x

« back to all changes in this revision

Viewing changes to tests/test_worker.py

  • Committer: Sebastian Heinlein
  • Date: 2012-12-29 23:41:16 UTC
  • mfrom: (883.1.26 pep8)
  • Revision ID: devel@glatzor.de-20121229234116-nd390n01ut2fcfce
PEP8 fixes and test for the test suite

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
21
# Licensed under the GNU General Public License Version 2
22
22
 
23
 
__author__  = "Sebastian Heinlein <devel@glatzor.de>"
 
23
__author__ = "Sebastian Heinlein <devel@glatzor.de>"
24
24
 
25
25
import glob
26
26
import netrc
34
34
import apt_pkg
35
35
from gi.repository import GLib
36
36
from mock import (
37
 
    Mock, 
38
 
    patch,
39
 
    )
 
37
    Mock,
 
38
    patch)
40
39
 
41
40
import aptdaemon.test
42
41
from aptdaemon.worker import (
43
 
    AptWorker,
44
 
    )
 
42
    AptWorker)
45
43
from aptdaemon.core import Transaction
46
44
from aptdaemon import enums, errors
47
45
 
63
61
        self.loop = GLib.MainLoop()
64
62
        self.queue = aptdaemon.test.MockQueue()
65
63
        self.worker = AptWorker(chroot=self.chroot.path, load_plugins=False)
66
 
        self.worker.connect("transaction-done", lambda w,t: self.loop.quit())
 
64
        self.worker.connect("transaction-done", lambda w, t: self.loop.quit())
67
65
        self.worker.connect("transaction-simulated",
68
 
                            lambda w,t: self.loop.quit())
 
66
                            lambda w, t: self.loop.quit())
69
67
 
70
68
    @unittest.skipIf("nose" in sys.modules, "Fails under nosetests3")
71
69
    def test_update_cache(self):
134
132
        trans = Transaction(None, enums.ROLE_INSTALL_PACKAGES, self.queue,
135
133
                            os.getpid(), os.getuid(), sys.argv[0],
136
134
                            "org.debian.apt.test", connect=False,
137
 
                            packages=[["silly-base"],[],[],[],[], []])
 
135
                            packages=[["silly-base"], [], [], [], [], []])
138
136
        self.worker.simulate(trans)
139
137
        self.loop.run()
140
138
        trans.allow_unauthenticated = False
148
146
        trans = Transaction(None, enums.ROLE_INSTALL_PACKAGES, self.queue,
149
147
                            os.getpid(), os.getuid(), sys.argv[0],
150
148
                            "org.debian.apt.test", connect=False,
151
 
                            packages=[["silly-base"],[],[],[],[], []])
 
149
                            packages=[["silly-base"], [], [], [], [], []])
152
150
        trans.allow_unauthenticated = True
153
151
        self.worker.simulate(trans)
154
152
        self.loop.run()
168
166
        trans = Transaction(None, enums.ROLE_INSTALL_PACKAGES, self.queue,
169
167
                            os.getpid(), os.getuid(), sys.argv[0],
170
168
                            "org.debian.apt.test", connect=False,
171
 
                            packages=[["silly-depend-base"],[],[],[],[], []])
 
169
                            packages=[["silly-depend-base"], [], [], [],
 
170
                                      [], []])
172
171
        self.worker.simulate(trans)
173
172
        self.loop.run()
174
173
        self.assertEqual(trans.depends[enums.PKGS_INSTALL],
196
195
        trans = Transaction(None, enums.ROLE_REMOVE_PACKAGES, self.queue,
197
196
                            os.getpid(), os.getuid(), sys.argv[0],
198
197
                            "org.debian.apt.test", connect=False,
199
 
                            packages=[[],[],["silly-depend-base"],[],[],[]])
 
198
                            packages=[[], [], ["silly-depend-base"], [],
 
199
                                      [], []])
200
200
        trans.remove_obsoleted_depends = True
201
201
        self.worker.simulate(trans)
202
202
        self.loop.run()
214
214
 
215
215
    def test_remove(self):
216
216
        """Test the removal of packages."""
217
 
        for pkg in ["silly-base_0.1-0_all.deb", "silly-essential_0.1-0_all.deb",
 
217
        for pkg in ["silly-base_0.1-0_all.deb",
 
218
                    "silly-essential_0.1-0_all.deb",
218
219
                    "silly-depend-base_0.1-0_all.deb"]:
219
220
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg))
220
221
        trans = Transaction(None, enums.ROLE_REMOVE_PACKAGES, self.queue,
221
222
                            os.getpid(), os.getuid(), sys.argv[0],
222
223
                            "org.debian.apt.test", connect=False,
223
 
                            packages=[[],[],["silly-base"],[],[],[]])
 
224
                            packages=[[], [], ["silly-base"], [], [], []])
224
225
        self.worker.simulate(trans)
225
226
        self.loop.run()
226
227
        self.assertEqual(trans.depends[enums.PKGS_REMOVE],
241
242
        trans = Transaction(None, enums.ROLE_REMOVE_PACKAGES, self.queue,
242
243
                            os.getpid(), os.getuid(), sys.argv[0],
243
244
                            "org.debian.apt.test", connect=False,
244
 
                            packages=[[],[],["silly-essential"],[],[],[]])
 
245
                            packages=[[], [], ["silly-essential"], [], [], []])
245
246
        self.worker.run(trans)
246
247
        self.loop.run()
247
248
        self.assertEqual(trans.exit, enums.EXIT_FAILED,
264
265
        trans = Transaction(None, enums.ROLE_COMMIT_PACKAGES, self.queue,
265
266
                            os.getpid(), os.getuid(), sys.argv[0],
266
267
                            "org.debian.apt.test", connect=False,
267
 
                            packages=[[],[],[],[],["silly-base=0.1-0update1"],[]])
 
268
                            packages=[[], [], [], [],
 
269
                                      ["silly-base=0.1-0update1"], []])
268
270
        self.worker.run(trans)
269
271
        self.loop.run()
270
272
        self.assertEqual(trans.exit, enums.EXIT_SUCCESS,
283
285
        trans = Transaction(None, enums.ROLE_COMMIT_PACKAGES, self.queue,
284
286
                            os.getpid(), os.getuid(), sys.argv[0],
285
287
                            "org.debian.apt.test", connect=False,
286
 
                            packages=[[],[],[],[],[],["silly-base=0.1-0"]])
 
288
                            packages=[[], [], [], [], [],
 
289
                                      ["silly-base=0.1-0"]])
287
290
        self.worker.run(trans)
288
291
        self.loop.run()
289
292
        self.assertEqual(trans.exit, enums.EXIT_SUCCESS,
300
303
        trans = Transaction(None, enums.ROLE_REMOVE_PACKAGES, self.queue,
301
304
                            os.getpid(), os.getuid(), sys.argv[0],
302
305
                            "org.debian.apt.test", connect=False,
303
 
                            packages=[[],[],[],["silly-config"],[],[]])
 
306
                            packages=[[], [], [], ["silly-config"], [], []])
304
307
        self.worker.run(trans)
305
308
        self.loop.run()
306
309
        self.assertEqual(trans.exit, enums.EXIT_SUCCESS,
307
310
                         "%s: %s" % (trans._error_property[0],
308
311
                                     trans._error_property[1]))
309
 
        self.assertFalse(os.path.exists(os.path.join(self.chroot.path,
310
 
                                                     "etc/silly-packages.cfg")),
311
 
                         "Configuration file wasn't removed.")
 
312
        self.assertFalse(
 
313
            os.path.exists(os.path.join(self.chroot.path,
 
314
                                        "etc/silly-packages.cfg")),
 
315
            "Configuration file wasn't removed.")
312
316
 
313
317
    def test_install_file(self):
314
318
        """Test the installation of a local package file."""
319
323
        #import pdb; pdb.set_trace()
320
324
        shutil.copytree("/usr/share/lintian", lintian_root)
321
325
        for profile in glob.glob(os.path.join(aptdaemon.test.get_tests_dir(),
322
 
                                                "../data/lintian/*/*.profile")):
 
326
                                              "../data/lintian/*/*.profile")):
323
327
            dst = [lintian_root, "profiles"]
324
328
            dst.extend(profile.split("/")[-2:])
325
329
            shutil.copy(profile, os.path.join(*dst))
350
354
                         "%s: %s" % (trans._error_property[0],
351
355
                                     trans._error_property[1]))
352
356
        self.worker._cache.open()
353
 
        self.assertTrue(self.worker._cache["silly-depend-base-lintian-broken"].is_installed)
 
357
        pkg = self.worker._cache["silly-depend-base-lintian-broken"]
 
358
        self.assertTrue(pkg.is_installed)
354
359
 
355
360
    def test_install_conflicting_file(self):
356
361
        """Test installing of a local package file that conflicts with
425
430
        trans = Transaction(None, enums.ROLE_COMMIT_PACKAGES, self.queue,
426
431
                            os.getpid(), os.getuid(), sys.argv[0],
427
432
                            "org.debian.apt.test",
428
 
                            packages=[["silly-broken",], [], [], [], [], []],
 
433
                            packages=[["silly-broken"], [], [], [], [], []],
429
434
                            connect=False)
430
435
        self.worker.simulate(trans)
431
436
        self.loop.run()
451
456
        self.assertRaises(errors.TransactionFailed,
452
457
                          self.worker._add_license_key_to_system,
453
458
                          pkg_name, license_key, license_key_path)
454
 
 
 
459
 
455
460
    def test_add_license_key(self):
456
461
        """Test the installation of license key files."""
457
462
        license_key = "Bli bla blub, I am a nasty BLOB!"
458
463
        license_path = "/opt/silly-license/NASTY.KEY"
 
464
 
459
465
        def get_license_key_mock(uid, pkg, oauth, server):
460
466
            return license_key, license_path
 
467
 
461
468
        self.chroot.add_test_repository()
462
469
        trans = Transaction(None, enums.ROLE_ADD_LICENSE_KEY, self.queue,
463
470
                            os.getpid(), os.getuid(), sys.argv[0],
527
534
        netrc_file = netrc.netrc(auth_file_path)
528
535
        self.assertEqual(len(netrc_file.hosts), 1)
529
536
        # add another one
530
 
        self.worker.add_repository(Mock(), "deb",
531
 
                                   "https://user2:pass2@host.example.com/path2",
532
 
                                   "natty", ["main"], "comment",
533
 
                                   source_file_name)
 
537
        self.worker.add_repository(
 
538
            Mock(), "deb", "https://user2:pass2@host.example.com/path2",
 
539
            "natty", ["main"], "comment", source_file_name)
534
540
        netrc_file = netrc.netrc(auth_file_path)
535
541
        self.assertEqual(len(netrc_file.hosts), 2)
536
542
        # change mode and add another repo
583
589
 
584
590
machine private-ppa.launchpad.net/project-moobar login m%20oo password bär
585
591
""")
586
 
        
587
592
 
588
593
 
589
594
@unittest.skipIf(not PY3K, "Only test the backend for Python3")