forked from juju/python-libjuju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_origin.py
96 lines (69 loc) · 3.13 KB
/
test_origin.py
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
import unittest
from juju.origin import Channel, Origin, Platform, Risk, Source
class TestRisk(unittest.TestCase):
def test_valid_risk(self):
self.assertTrue(Risk.valid("stable"))
def test_invalid_risk(self):
self.assertFalse(Risk.valid("maybe"))
class TestChannel(unittest.TestCase):
def test_parse_risk_only(self):
ch = Channel.parse("stable")
self.assertEqual(ch, Channel(None, "stable"))
def test_parse_track_only(self):
ch = Channel.parse("2.0.1")
self.assertEqual(ch, Channel("2.0.1", "stable"))
def test_parse(self):
ch = Channel.parse("latest/stable")
self.assertEqual(ch, Channel("latest", "stable"))
def test_parse_numeric(self):
ch = Channel.parse("2.0.7/stable")
self.assertEqual(ch, Channel("2.0.7", "stable"))
def test_parse_then_normalize(self):
ch = Channel.parse("latest/stable").normalize()
self.assertEqual(ch, Channel("latest", "stable"))
def test_str_risk_only(self):
ch = Channel.parse("stable")
self.assertEqual(str(ch), "stable")
def test_str_track_only(self):
ch = Channel.parse("2.0.1")
self.assertEqual(str(ch), "2.0.1/stable")
def test_str(self):
ch = Channel.parse("latest/stable")
self.assertEqual(str(ch), "latest/stable")
def test_str_numeric(self):
ch = Channel.parse("2.0.7/stable")
self.assertEqual(str(ch), "2.0.7/stable")
def test_str_then_normalize(self):
ch = Channel.parse("latest/stable").normalize()
self.assertEqual(str(ch), "latest/stable")
class TestPlatform(unittest.TestCase):
def test_parse_arch_only(self):
p = Platform.parse("architecture")
self.assertEqual(p, Platform("architecture"))
def test_parse_arch_and_series(self):
p = Platform.parse("architecture/series")
self.assertEqual(p, Platform("architecture", "series"))
def test_parse(self):
p = Platform.parse("architecture/os/series")
self.assertEqual(p, Platform("architecture", "series", "os"))
def test_parse_with_unknowns(self):
p = Platform.parse("architecture/unknown/unknown")
self.assertEqual(p, Platform("architecture", "unknown", "unknown"))
def test_parse_with_unknowns_after_normalize(self):
p = Platform.parse("architecture/unknown/unknown").normalize()
self.assertEqual(p, Platform("architecture"))
def test_str_arch_only(self):
p = Platform.parse("architecture")
self.assertEqual(str(p), "architecture")
def test_str_arch_and_series(self):
p = Platform.parse("architecture/series")
self.assertEqual(str(p), "architecture/series")
def test_str(self):
p = Platform.parse("architecture/os/series")
self.assertEqual(str(p), "architecture/os/series")
class TestOrigin(unittest.TestCase):
def test_origin(self):
ch = Channel.parse("latest/stable")
p = Platform.parse("amd64/ubuntu/focal")
o = Origin(Source.CHARM_HUB, ch, p)
self.assertEqual(str(o), "origin using source charm-hub for channel latest/stable and platform amd64/ubuntu/focal")