import os import tempfile import unittest from tornado.testing import AsyncTestCase, gen_test from pyapd import ctl, config, app class TestCtlServerCommands(AsyncTestCase): def setUp(self): super().setUp() self.tempdir = tempfile.TemporaryDirectory() test_app = app.App(config.Config('tests/data/test_config.yaml')) test_app.config.ctl_socket = os.path.join( self.tempdir.name, 'pyapd.sock' ) self.ctl_server = ctl.CtlServer(test_app) @gen_test def test_ping_command(self): res = yield self.ctl_server.get_command('{"command": "ping"}') self.assertIn('pong', res) @gen_test @unittest.skip("Broken by the refactoring, needs further work.") def test_add_object_command(self): self.assertEqual(len(self.ctl_server.app.store.objects), 0) obj = ''' { "id": "http://example.org/123456", "type": "object" } ''' res = yield (self.ctl_server.get_command(''' {{ "command": "add_object", "obj": {obj} }} '''.format(obj=obj) )) self.assertIn('ok', res) self.assertEqual(len(self.ctl_server.app.store.objects), 1)