aboutsummaryrefslogtreecommitdiff
blob: 57f549df239117bc3541257898d886c70fae7179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from snakeoil.sequences import iflatten_instance
from snakeoil.test import TestCase

from pkgcore import fetch


class base(TestCase):

    def assertUri(self, obj, uri):
        uri = list(uri)
        self.assertEqual(list(iflatten_instance(obj)), uri)
        if uri:
            self.assertTrue(obj)
        else:
            self.assertFalse(obj)


class TestFetchable(base):

    def test_init(self):
        o = fetch.fetchable("dar", uri=["asdf"], chksums={"asdf":1})
        self.assertEqual(o.filename, "dar")
        self.assertUri(o.uri, ["asdf"])
        self.assertEqual(o.chksums, {"asdf":1})

    def test_eq_ne(self):
        o1 = fetch.fetchable("dar", uri=["asdf"], chksums={"asdf":1})
        self.assertEqual(o1, o1)
        o2 = fetch.fetchable("dar", uri=["asdf"], chksums={"asdf":1})
        self.assertEqual(o1, o2)
        self.assertNotEqual(o1,
            fetch.fetchable("dar1", uri=["asdf"], chksums={"asdf":1}))
        self.assertNotEqual(o1,
            fetch.fetchable("dar", uri=["asdf1"], chksums={"asdf":1}))
        self.assertNotEqual(o1,
            fetch.fetchable("dar", uri=["asdf1"], chksums={"asdf":1, "foon":1}))


class TestMirror(base):

    kls = fetch.mirror

    default_mirrors = ["http://foon", "ftp://spoon"]
    def setUp(self):
        self.mirror = self.kls(self.default_mirrors, "fork")

    def test_init(self):
        self.assertEqual(self.mirror.mirror_name, "fork")
        # explicit test should any tuple like sequence show up
        self.assertInstance(self.mirror.mirrors, tuple)
        self.assertEqual(self.mirror.mirrors, tuple(self.default_mirrors))

    def test_iter(self):
        self.assertEqual(list(self.mirror), self.default_mirrors)

    def test_len(self):
        self.assertEqual(len(self.mirror), len(self.default_mirrors))

    def test_getitem(self):
        self.assertEqual(self.mirror[1], self.default_mirrors[1])

    def test_eq_ne(self):
        self.assertEqual(self.mirror, self.kls(self.default_mirrors, 'fork'))
        self.assertNotEqual(self.mirror,
            self.kls(self.default_mirrors + ['http://fark'], 'fork'))


class TestDefaultMirror(TestMirror):

    kls = fetch.default_mirror


class Test_uri_list(base):

    def setUp(self):
        self.uril = fetch.uri_list("cows")

    @staticmethod
    def mk_uri_list(*iterable, **kwds):
        filename = kwds.get("filename", "asdf")
        obj = fetch.uri_list(filename)
        for x in iterable:
            if isinstance(x, fetch.mirror):
                obj.add_mirror(x)
            else:
                obj.add_uri(x)
        return obj

    def test_mirrors(self):
        self.assertRaises(TypeError, self.uril.add_mirror, "cows")
        mirror = fetch.mirror(["me", "WI"], "asdf")
        self.uril.add_mirror(mirror)
        self.assertEqual(list(self.uril), ["me/cows", "WI/cows"])
        self.uril.add_mirror(mirror, "foon/boon")
        self.assertUri(self.uril,
            ["me/cows", "WI/cows", "me/foon/boon", "WI/foon/boon"])

    def test_uris(self):
        self.uril.add_uri("blar")
        self.assertUri(self.uril, ["blar"])

    def test_combined(self):
        l = ["blarn", "me/cows", "WI/cows", "madison",
            "belleville/cows", "verona/cows"]
        self.uril.add_uri("blarn")
        self.uril.add_mirror(fetch.mirror(["me", "WI"], "asdf"))
        self.uril.add_uri("madison")
        self.uril.add_mirror(fetch.default_mirror(
            ["belleville", "verona"], "foon"))
        self.assertUri(self.uril, l)

    def test_nonzero(self):
        self.assertTrue(self.mk_uri_list("asdf"))
        self.assertFalse(self.mk_uri_list())
        self.assertFalse(self.mk_uri_list(fetch.mirror((), "mirror")))

    def test_len(self):
        self.assertLen(self.mk_uri_list(), 0)
        self.assertLen(self.mk_uri_list("fdas"), 1)
        self.assertLen(self.mk_uri_list(fetch.mirror((), "mirror")), 0)
        self.assertLen(self.mk_uri_list(fetch.mirror(("asdf",), "mirror")), 1)