15
root_dir = opd(opd(opd((os.path.abspath(__file__)))))
18
class AmuletDeployment(object):
19
"""Fixture for a deployed set of juju services from a deployer config"""
21
def __init__(self, deployer_cfg, juju_env=None, sentries=False):
22
self.deployment = amulet.Deployment(juju_env, sentries=sentries)
23
with open(deployer_cfg) as f:
24
jd_script = yaml.safe_load(f.read())
25
# Use juju_env given or defaulted above rather than taking the name
26
# from the deployer config and assuming an env of that name exists
27
script = {self.deployment.juju_env: jd_script.values()[0]}
28
self.deployment.load(script)
31
self.deployment.setup()
34
class PPAAssignerTest(unittest.TestCase):
35
"""Integration tests for ppa-assigner service run on a juju deployment"""
38
super(PPAAssignerTest, self).setUp()
39
self.deployer = AmuletDeployment(os.path.join(root_dir,
41
'ticket_system.yaml'))
44
def get_ip_and_port(self):
45
self.status = amulet.waiter.status(self.deployer.deployment.juju_env)
46
units = self.status['services']['ts-django']['units']
47
ip = units['ts-django/0']['public-address']
48
port, _ = units['ts-django/0']['open-ports'][0].split('/')
51
def get_server_status_and_content(self, url):
52
final_url = url.format(*self.get_ip_and_port())
54
# Issue a simple command against the ticket API
55
client = httplib2.Http()
56
resp, content = client.request(final_url, 'GET')
57
jcontent = json.loads(content)
60
def create_ticket(self, ticket_content):
61
url = 'http://{}:{}/api/v1/ticket/'
62
final_url = url.format(*self.get_ip_and_port())
64
client = httplib2.Http()
65
resp, content = client.request(
68
headers={'Content-Type': 'application/json'},
69
body=json.dumps(ticket_content),
73
def test_ticket_sys_api(self):
74
url = 'http://{}:{}/api/v1/ticket'
75
resp, content = self.get_server_status_and_content(url)
77
self.assertEqual('200', resp['status'])
79
def test_create_ticket(self):
80
ticket_content = {"owner": "create@example.com",
81
"title": "Created ticket",
82
"description": "This ticket is for. \
85
"added_binaries": "binary-1,binary-2",
86
"removed_binaries": "binary-3,binary-4"}
87
resp, content = self.create_ticket(ticket_content)
88
self.assertEqual('201', resp['status'])
90
def test_prohibit_delete(self):
91
ticket_content = {'owner': "dont_delete@example.com",
92
"title": "Delete test ticket",
93
"description": "Attempt to delete ticket details",
95
"added_binaries": "binary-4-delete-1",
96
"removed_binaries": "binary-4-delete-2"}
97
resp, content = self.create_ticket(ticket_content)
98
self.assertEqual('201', resp['status'])
99
ticket_loc = resp['location']
101
client = httplib2.Http()
102
resp, content = client.request(
106
self.assertEqual('405', resp['status'])
108
def test_prihibit_change_ticket_details(self):
109
ticket_content = {'owner': "before_change@example.com",
110
"title": "Change test ticket",
111
"description": "Attempt to change ticket details",
113
"added_binaries": "binary-4-change-1",
114
"removed_binaries": "binary-4-change-2"}
115
resp, content = self.create_ticket(ticket_content)
116
self.assertEqual('201', resp['status'])
117
ticket_loc = resp['location']
119
client = httplib2.Http()
120
resp, content = client.request(
123
headers={'Content-Type': 'application/json'},
124
body=json.dumps({'owner': "after_changed@example.com"}),
126
self.assertEqual('405', resp['status'])
128
if __name__ == "__main__":