Skip to content

Commit c988181

Browse files
committed
Merge branch 'docker-tests'
2 parents 06c1e5f + bd37a59 commit c988181

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

post_test.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

pre_test.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker-py==1.8.1

taskc/simple.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ def __init__(self, port=53589):
2020
def manage_connection(f):
2121
def conn_wrapper(self, *args, **kwargs):
2222
self._connect()
23-
f(self, *args, **kwargs) # noqa
23+
x = f(self, *args, **kwargs) # noqa
2424
self._close()
25+
return x
2526
return conn_wrapper
2627

2728
@classmethod
@@ -157,7 +158,7 @@ def put(self, tasks):
157158
"""
158159
Push all our tasks to server
159160
160-
tasks: taskjson list
161+
tasks: flat formatted taskjson according to spec
161162
"""
162163

163164
msg = transaction.mk_message(self.group, self.username, self.uuid)

taskc/simple_test.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import unittest
22
import os
3+
import time
4+
# import logging
5+
6+
from docker import Client
7+
38
from simple import TaskdConnection
49

510

@@ -24,36 +29,50 @@ def test_rc(self):
2429
class TestConnection(unittest.TestCase):
2530

2631
def setUp(self):
32+
# logging.basicConfig(level=logging.DEBUG)
33+
self.docker = Client(base_url='unix://var/run/docker.sock')
34+
host_config = self.docker.create_host_config(publish_all_ports=True)
35+
self.container = self.docker.create_container("jrabbit/taskd", name="taskc_test", host_config=host_config)
36+
self.docker.start(self.container["Id"])
37+
our_exec = self.docker.exec_create(self.container["Id"], "taskd add user Public test_user")
2738
self.tc = TaskdConnection()
39+
o = self.docker.exec_start(our_exec['Id'])
40+
# print o
41+
self.tc.uuid = o.split('\n')[0].split()[-1]
42+
# print self.tc.uuid
2843
self.tc.server = "localhost"
29-
self.tc.port = 9001
30-
self.tc.uuid = os.getenv("TEST_UUID")
44+
c = self.docker.inspect_container("taskc_test")
45+
46+
self.tc.port = int(c['NetworkSettings']['Ports']['53589/tcp'][0]['HostPort'])
47+
# self.tc.uuid = os.getenv("TEST_UUID")
3148
self.tc.group = "Public"
3249
self.tc.username = "test_user"
3350
self.tc.client_cert = "taskc/fixture/pki/client.cert.pem"
3451
self.tc.client_key = "taskc/fixture/pki/client.key.pem"
3552
self.tc.cacert_file = "taskc/fixture/pki/ca.cert.pem"
36-
53+
time.sleep(2)
3754
def test_connect(self):
3855

3956
self.tc._connect()
4057
# print self.tc.conn.getpeername()
41-
self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', 9001))
58+
self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port))
4259
# make sure we're on TLS v2 per spec
4360
self.assertEqual(self.tc.conn.context.protocol, 2)
4461
self.tc.conn.close()
4562
# from IPython import embed
4663
# embed()
4764

4865
def test_put(self):
49-
66+
assert self.tc.uuid
5067
self.tc.put("")
5168
tasks = """{"description":"hang up posters","entry":"20141130T081652Z","status":"pending","uuid":"0037aa92-45e5-44a6-8f34-2f92989f173a"}
5269
{"description":"make pb ramen","entry":"20141130T081700Z","status":"pending","uuid":"dd9b71db-f51c-4026-9e46-bb099df8dd3f"}
5370
{"description":"fold clothes","entry":"20141130T081709Z","status":"pending","uuid":"d0f53865-2f01-42a8-9f9e-3652c63f216d"}"""
5471
resp = self.tc.put(tasks)
5572
self.assertEqual(resp.status_code, 200)
5673
# might not be correct depends on state of taskd
74+
def tearDown(self):
75+
self.docker.remove_container(self.container['Id'], force=True)
5776

5877
# class TestStringIO(unittest.TestCase):
5978
# def setUp(self):

0 commit comments

Comments
 (0)