Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 194 lines (142 sloc) 6.406 kB
b272e27 @paddyforan Removed old examples, updated iron_worker_pip to just be iron_worker.
paddyforan authored
1 from iron_worker import *
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
2 import unittest
3 import ConfigParser
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
4 import time
5
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
6
a1c61d3 @paddyforan Removed all references to Pip.
paddyforan authored
7 class TestIronWorker(unittest.TestCase):
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
8
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
9 def setUp(self):
10 config = ConfigParser.RawConfigParser()
11 config.read('config.ini')
12 self.token = config.get("IronWorker", "token")
13 self.project_id = config.get("IronWorker", "project_id")
14 self.new_project_id = "New Project Id"
15
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
16 self.code_name = "test%d" % time.time()
17
6bc0a98 @paddyforan Updated to fix #17. Fixed tests.
paddyforan authored
18 self.worker = IronWorker(token=self.token, project_id=self.project_id)
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
19
ee9ed78 @paddyforan Put an end to those annoying errors.
paddyforan authored
20 IronWorker.zipDirectory(destination="test.zip", overwrite=True,
21 directory="testDir")
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
22 response = self.worker.postCode(name=self.code_name,
ee9ed78 @paddyforan Put an end to those annoying errors.
paddyforan authored
23 runFilename="testDir/hello.py", zipFilename="test.zip")
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
24
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
25 def test_setProject(self):
26 self.assertNotEqual(self.worker.project_id, self.new_project_id)
27
28 self.worker.setProject(self.new_project_id)
29 self.assertEqual(self.worker.project_id, self.new_project_id)
30
31 self.worker.setProject(self.project_id)
32 self.assertEqual(self.worker.project_id, self.project_id)
33
34 def test_headers(self):
35 self.assertEqual(self.worker.headers['Accept'], "application/json")
36 self.assertEqual(self.worker.headers['Accept-Encoding'],
37 "gzip, deflate")
38 self.assertEqual(self.worker.headers['User-Agent'],
a1c61d3 @paddyforan Removed all references to Pip.
paddyforan authored
39 "IronWorker Python v0.3")
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
40
41 def test_postCode(self):
893db9e @paddyforan Updated tests to upload directories, as well, to avoid problems like …
paddyforan authored
42 IronWorker.createZip(destination="test.zip", overwrite=True,
43 files=["testDir/hello.py"])
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
44 response = self.worker.postCode(name=self.code_name,
893db9e @paddyforan Updated tests to upload directories, as well, to avoid problems like …
paddyforan authored
45 runFilename="testDir/hello.py", zipFilename="test.zip")
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
46
47 codes = self.worker.getCodes()
48 code_names = []
49 for code in codes:
50 code_names.append(code["name"])
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
51 self.assertIn(self.code_name, code_names)
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
52
893db9e @paddyforan Updated tests to upload directories, as well, to avoid problems like …
paddyforan authored
53 def test_postZip(self):
54 IronWorker.zipDirectory(directory="testDir", destination="test.zip",
55 overwrite=True)
56 response = self.worker.postCode(name=self.code_name,
57 runFilename="testDir/hello.py", zipFilename="test.zip")
58
59 codes = self.worker.getCodes()
60
61 code = self.worker.getCodeDetails(code_id=codes[0]['id'])
62 self.assertEqual(codes[0]['id'], code['id'])
63
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
64 def test_getCodeDetails(self):
65 IronWorker.createZip(destination="test.zip", files=["test.py"],
66 overwrite=True)
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
67 response = self.worker.postCode(name=self.code_name,
68 runFilename="test.py", zipFilename="test.zip")
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
69
70 codes = self.worker.getCodes()
71
72 code = self.worker.getCodeDetails(code_id=codes[0]['id'])
73 self.assertEqual(codes[0]['id'], code['id'])
74
75 def test_postTask(self):
76 payload = {
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
77 "dict": {"a": 1, "b": 2},
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
78 "var": "alpha",
79 "list": ['apples', 'oranges', 'bananas']
80 }
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
81 resp = self.worker.postTask(name=self.code_name, payload=payload)
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
82
83 self.assertEqual(len(resp['tasks']), 1)
84
85 task_id = resp['tasks'][0]['id']
86
87 tasks = self.worker.getTasks()
88 task_ids = []
89 for task in tasks:
90 task_ids.append(task['id'])
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
91
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
92 self.assertIn(task_id, task_ids)
93
94 def test_getTaskDetails(self):
95 payload = {
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
96 "dict": {"a": 1, "b": 2},
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
97 "var": "alpha",
98 "list": ['apples', 'oranges', 'bananas']
99 }
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
100 resp = self.worker.postTask(name=self.code_name, payload=payload)
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
101
102 self.assertEqual(len(resp['tasks']), 1)
103
104 task_id = resp['tasks'][0]['id']
105
106 tasks = self.worker.getTasks()
107 task_ids = []
108 for task in tasks:
109 task_ids.append(task['id'])
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
110
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
111 self.assertIn(task_id, task_ids)
112
113 tasks = self.worker.getTasks()
114 task_id = tasks[0]['id']
115
116 task = self.worker.getTaskDetails(task_id=task_id)
117
118 self.assertEqual(task_id, task['id'])
119
61795e8 @paddyforan Updated to reflect the new API endpoints--cancelling tasks and schedu…
paddyforan authored
120 def test_cancelTask(self):
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
121 tasks = self.worker.getTasks()
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
122
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
123 for task in tasks:
61795e8 @paddyforan Updated to reflect the new API endpoints--cancelling tasks and schedu…
paddyforan authored
124 self.worker.cancelTask(task_id=task['id'])
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
125
126 new_tasks = self.worker.getTasks()
127 real_tasks = []
128 for task in new_tasks:
129 if task['status'] not in ['cancelled', 'error']:
130 real_tasks.append(task)
131 self.assertEqual(len(real_tasks), 0)
132
133 def test_postSchedule(self):
cff207c @paddyforan Updated to append timestamp to code ID, so it doesn't fail when the c…
paddyforan authored
134 schedule_id = self.worker.postSchedule(name=self.code_name, delay=120)
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
135
136 schedules = self.worker.getSchedules()
137 schedule_ids = []
138 for schedule in schedules:
139 schedule_ids.append(schedule['id'])
140
141 self.assertIn(schedule_id, schedule_ids)
142
1398f8f @paddyforan Added fix for #9 and a test to check scheduled tasks with and without…
paddyforan authored
143 def test_postScheduleAndPayload(self):
144 schedule_id = self.worker.postSchedule(name=self.code_name, delay=120,
145 payload={"foo": "bar"})
146
147 schedules = self.worker.getSchedules()
148 schedule_ids = []
149 for schedule in schedules:
150 schedule_ids.append(schedule['id'])
151
152 self.assertIn(schedule_id, schedule_ids)
153
9182e4f @paddyforan Added advanced scheduling features and a test to check for them. Fixe…
paddyforan authored
154 def test_postAdvancedSchedule(self):
155 start_at = time.gmtime(time.time() + 3600) # one hour from now
156 schedule_id = self.worker.postSchedule(
157 name="advanced_%s" % self.code_name,
158 payload={"schedule": "AWESOME SCHEDULE!"},
159 code_name=self.code_name, start_at=start_at, run_every=3600,
160 run_times=8)
161
162 schedules = self.worker.getSchedules()
163 schedule_ids = []
164 for schedule in schedules:
165 schedule_ids.append(schedule['id'])
166
167 self.assertIn(schedule_id, schedule_ids)
168
61795e8 @paddyforan Updated to reflect the new API endpoints--cancelling tasks and schedu…
paddyforan authored
169 def test_cancelSchedule(self):
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
170 schedules = self.worker.getSchedules()
171
172 for schedule in schedules:
61795e8 @paddyforan Updated to reflect the new API endpoints--cancelling tasks and schedu…
paddyforan authored
173 self.worker.cancelSchedule(schedule_id=schedule['id'])
8ac18cf @paddyforan Fixed some lingering bugs in iron_Worker_pip. Added a full set of uni…
paddyforan authored
174
175 new_schedules = self.worker.getSchedules()
176 real_schedules = []
177 for schedule in new_schedules:
178 if schedule['status'] not in ['cancelled', 'error']:
179 real_schedules.append(schedule)
180
181 self.assertEqual(len(real_schedules), 0)
182
183 def test_deleteCode(self):
184 codes = self.worker.getCodes()
185
186 for code in codes:
187 self.worker.deleteCode(code_id=code['id'])
188
189 new_codes = self.worker.getCodes()
190 self.assertEqual(len(new_codes), 0)
191
192 if __name__ == '__main__':
193 unittest.main()
Something went wrong with that request. Please try again.