11import unittest
22import os
3+ import time
4+ # import logging
5+
6+ from docker import Client
7+
38from simple import TaskdConnection
49
510
@@ -24,36 +29,50 @@ def test_rc(self):
2429class 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