def setUp(self): self.testrun_id = 666 self.client = ResponseClient("localhost", 666) self.conn = ConnectionStub() self.channel = ChannelStub() self.client.conn = self.conn self.client.channel = self.channel
class TestResponseClient(unittest.TestCase): """Unittests for ResponseClient class""" def setUp(self): self.testrun_id = 666 self.client = ResponseClient("localhost", 666) self.conn = ConnectionStub() self.channel = ChannelStub() self.client.conn = self.conn self.client.channel = self.channel def tearDown(self): pass def test_init(self): self.assertEquals(self.client.testrun_id, self.testrun_id) def test_predefined_response_queue(self): queue = "test_queue1" another_client = ResponseClient("localhost", 666, queue) self.assertEquals(another_client.response_queue, queue) def test_close(self): del self.client self.assertTrue(self.conn.close_called) self.assertTrue(self.channel.close_called) def test_set_error(self): error_info = "Flashing failed" error_code = "666" self.client.set_error(error_info, error_code) msg = self.channel.msg self.assertTrue(msg) content = loads(msg.body) self.assertTrue(isinstance(content, OTSException)) self.assertEquals(content.errno, error_code) self.assertEquals(content.strerror, error_info) def test_add_executed_packages(self): environment = "Flashing failed" packages = ["pkg1-tests", "pkg2-tests"] self.client.add_executed_packages(environment, packages) msg = self.channel.msg self.assertTrue(msg) executed_pkgs = loads(msg.body) self.assertEquals(executed_pkgs.environments[0], environment) self.assertEquals(executed_pkgs.packages(environment), packages) def test_add_result(self): filename = "result.xml" file_content = "<xm>foo</xml>" origin = "localhost" test_package = "dummy-tests" environment = "hardware" self.client.add_result(filename, file_content, origin, test_package, environment) msg = self.channel.msg self.assertTrue(msg) result = loads(msg.body) self.assertEquals(result.data.name, filename) self.assertEquals(result.data.read(), file_content) self.assertEquals(result.hostname, origin) self.assertEquals(result.package, test_package) self.assertEquals(result.environment, Environment(environment))
def test_predefined_response_queue(self): queue = "test_queue1" another_client = ResponseClient("localhost", 666, queue) self.assertEquals(another_client.response_queue, queue)
class TestResponseClient(unittest.TestCase): """Unittests for ResponseClient class""" def setUp(self): self.testrun_id = 666 self.client = ResponseClient("localhost", 666) self.conn = ConnectionStub() self.channel = ChannelStub() self.client.conn = self.conn self.client.channel = self.channel def tearDown(self): pass def test_init(self): self.assertEquals(self.client.testrun_id, self.testrun_id) def test_predefined_response_queue(self): queue = "test_queue1" another_client = ResponseClient("localhost", 666, queue) self.assertEquals(another_client.response_queue, queue) def test_close(self): del self.client self.assertTrue(self.conn.close_called) self.assertTrue(self.channel.close_called) def test_set_error(self): error_info = "Flashing failed" error_code = "666" self.client.set_error(error_info, error_code) msg = self.channel.msg self.assertTrue(msg) content = loads(msg.body) self.assertTrue(isinstance(content, OTSException)) self.assertEquals(content.errno, error_code) self.assertEquals(content.strerror, error_info) def test_add_executed_packages(self): environment = "Flashing failed" packages = ['pkg1-tests', 'pkg2-tests'] self.client.add_executed_packages(environment, packages) msg = self.channel.msg self.assertTrue(msg) executed_pkgs = loads(msg.body) self.assertEquals(executed_pkgs.environments[0], environment) self.assertEquals(executed_pkgs.packages(environment), packages) def test_add_result(self): filename = "result.xml" file_content = "<xm>foo</xml>" origin = "localhost" test_package = "dummy-tests" environment = "hardware" self.client.add_result(filename, file_content, origin, test_package, environment) msg = self.channel.msg self.assertTrue(msg) result = loads(msg.body) self.assertEquals(result.data.name, filename) self.assertEquals(result.data.read(), file_content) self.assertEquals(result.hostname, origin) self.assertEquals(result.package, test_package) self.assertEquals(result.environment, Environment(environment))