Skip to content

Commit

Permalink
Merge branch 'docker-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
jrabbit committed May 18, 2016
2 parents 06c1e5f + bd37a59 commit c988181
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 0 additions & 2 deletions post_test.sh

This file was deleted.

3 changes: 0 additions & 3 deletions pre_test.sh

This file was deleted.

1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-py==1.8.1
5 changes: 3 additions & 2 deletions taskc/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def __init__(self, port=53589):
def manage_connection(f):
def conn_wrapper(self, *args, **kwargs):
self._connect()
f(self, *args, **kwargs) # noqa
x = f(self, *args, **kwargs) # noqa
self._close()
return x
return conn_wrapper

@classmethod
Expand Down Expand Up @@ -157,7 +158,7 @@ def put(self, tasks):
"""
Push all our tasks to server
tasks: taskjson list
tasks: flat formatted taskjson according to spec
"""

msg = transaction.mk_message(self.group, self.username, self.uuid)
Expand Down
29 changes: 24 additions & 5 deletions taskc/simple_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import unittest
import os
import time
# import logging

from docker import Client

from simple import TaskdConnection


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

def setUp(self):
# logging.basicConfig(level=logging.DEBUG)
self.docker = Client(base_url='unix://var/run/docker.sock')
host_config = self.docker.create_host_config(publish_all_ports=True)
self.container = self.docker.create_container("jrabbit/taskd", name="taskc_test", host_config=host_config)
self.docker.start(self.container["Id"])
our_exec = self.docker.exec_create(self.container["Id"], "taskd add user Public test_user")
self.tc = TaskdConnection()
o = self.docker.exec_start(our_exec['Id'])
# print o
self.tc.uuid = o.split('\n')[0].split()[-1]
# print self.tc.uuid
self.tc.server = "localhost"
self.tc.port = 9001
self.tc.uuid = os.getenv("TEST_UUID")
c = self.docker.inspect_container("taskc_test")

self.tc.port = int(c['NetworkSettings']['Ports']['53589/tcp'][0]['HostPort'])
# self.tc.uuid = os.getenv("TEST_UUID")
self.tc.group = "Public"
self.tc.username = "test_user"
self.tc.client_cert = "taskc/fixture/pki/client.cert.pem"
self.tc.client_key = "taskc/fixture/pki/client.key.pem"
self.tc.cacert_file = "taskc/fixture/pki/ca.cert.pem"

time.sleep(2)
def test_connect(self):

self.tc._connect()
# print self.tc.conn.getpeername()
self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', 9001))
self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port))
# make sure we're on TLS v2 per spec
self.assertEqual(self.tc.conn.context.protocol, 2)
self.tc.conn.close()
# from IPython import embed
# embed()

def test_put(self):

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

# class TestStringIO(unittest.TestCase):
# def setUp(self):
Expand Down

0 comments on commit c988181

Please sign in to comment.