Beispiel #1
0
    def test_subscription_good_query(self):
        # Arrange
        app = Mock(ui_methods={}, ui_modules={}, async_db={"tests": None})
        query_request = Mock()
        query_request.arguments = dict(
            query=['{ "name": "test", "ts": { "gte": 145 } }'])
        handler = SubscriptionHandler(app, query_request)

        manager_mock = Mock()

        handler._manager = Mock()
        handler.write_message = Mock(side_effects=ValueError)
        handler._manager = manager_mock

        # Act
        handler.open(resource_type="test")

        # Assert
        self.assertTrue(manager_mock.createChannel.called)
        self.assertEqual(manager_mock.createChannel.call_args[0][0], {
            "name": "test",
            "ts": {
                "gte": 145
            }
        })
    def test_blank_subscription(self, listen_mock):
        # Arrange
        app = Mock(ui_methods = {}, ui_modules = {}, async_db = {"tests": None})
        handler = SubscriptionHandler(app, Mock())
        handler._manager = Mock()
        
        # Act
        handler.open()

        # Assert
        self.assertFalse(listen_mock.called)
        self.assertFalse(handler.listening)
Beispiel #3
0
    def test_blank_subscription(self, listen_mock):
        # Arrange
        app = Mock(ui_methods={}, ui_modules={}, async_db={"tests": None})
        handler = SubscriptionHandler(app, Mock())
        handler._manager = Mock()

        # Act
        handler.open()

        # Assert
        self.assertFalse(listen_mock.called)
        self.assertFalse(handler.listening)
    def test_resource_id_subscription(self):
        # Arrange
        app = Mock(ui_methods = {}, ui_modules = {}, async_db = {"tests": None})
        resource_mock = Mock()
        resource_mock.arguments = dict()
        handler = SubscriptionHandler(app, resource_mock)
        handler._manager = Mock()
        
        # Act
        handler.open(resource_type = "test", resource_id="1")

        # Assert
        self.assertEqual(handler._manager.createChannel.call_args[0][0], { "id": "1" })
Beispiel #5
0
    def test_resource_id_subscription(self):
        # Arrange
        app = Mock(ui_methods={}, ui_modules={}, async_db={"tests": None})
        resource_mock = Mock()
        resource_mock.arguments = dict()
        handler = SubscriptionHandler(app, resource_mock)
        handler._manager = Mock()

        # Act
        handler.open(resource_type="test", resource_id="1")

        # Assert
        self.assertEqual(handler._manager.createChannel.call_args[0][0],
                         {"id": "1"})
    def test_resource_subscription(self, listen_mock):
        # Arrange
        app = Mock(ui_methods = {}, ui_modules = {}, async_db = {"tests": None})
        resource_mock = Mock()
        resource_mock.arguments = dict()
        handler = SubscriptionHandler(app, resource_mock)
        handler._manager = Mock()

        # Act
        handler.open(resource_type = "test")

        # Assert
        self.assertTrue(listen_mock.called)
        self.assertEqual(handler._manager.createChannel.call_count, 1)
        self.assertEqual(handler._manager.createChannel.call_args[0][1], "test")
 def test_subscription_good_fields(self):
     # Arrange
     app = Mock(ui_methods = {}, ui_modules = {}, async_db = {"tests": None})
     fields_request = Mock()
     fields_request.arguments = dict(fields = ["name,ts"])
     
     manager_mock = Mock()
     
     handler = SubscriptionHandler(app, fields_request)
     handler._manager = manager_mock
     
     # Act
     handler.open(resource_type = "test")
     
     # Assert
     self.assertEqual(manager_mock.createChannel.call_args[0][2], ["name", "ts"])
Beispiel #8
0
    def test_resource_subscription(self, listen_mock):
        # Arrange
        app = Mock(ui_methods={}, ui_modules={}, async_db={"tests": None})
        resource_mock = Mock()
        resource_mock.arguments = dict()
        handler = SubscriptionHandler(app, resource_mock)
        handler._manager = Mock()

        # Act
        handler.open(resource_type="test")

        # Assert
        self.assertTrue(listen_mock.called)
        self.assertEqual(handler._manager.createChannel.call_count, 1)
        self.assertEqual(handler._manager.createChannel.call_args[0][1],
                         "test")
Beispiel #9
0
    def test_subscription_good_fields(self):
        # Arrange
        app = Mock(ui_methods={}, ui_modules={}, async_db={"tests": None})
        fields_request = Mock()
        fields_request.arguments = dict(fields=["name,ts"])

        manager_mock = Mock()

        handler = SubscriptionHandler(app, fields_request)
        handler._manager = manager_mock

        # Act
        handler.open(resource_type="test")

        # Assert
        self.assertEqual(manager_mock.createChannel.call_args[0][2],
                         ["name", "ts"])
Beispiel #10
0
    def test_subscription_bad_query(self):
        # Arrange
        app = Mock(ui_methods = {}, ui_modules = {}, async_db = { "tests": None})
        query_request = Mock()
        query_request.arguments = dict(query = ["{ name: 'test', ts: { gte: 145 }"])

        manager_mock = Mock()
        
        handler = SubscriptionHandler(app, query_request)
        handler._manager = manager_mock
        handler.write_message = Mock(side_effects = ValueError)
        
        # Act
        handler.open(resource_type = "test")

        # Assert
        self.assertFalse(handler.client)
        self.assertFalse(manager_mock.createChannel.called)
Beispiel #11
0
 def test_subscription_good_query(self):
     # Arrange
     app = Mock(ui_methods = {}, ui_modules = {}, async_db = {"tests": None})
     query_request = Mock()
     query_request.arguments = dict(query = ['{ "name": "test", "ts": { "gte": 145 } }'])
     handler = SubscriptionHandler(app, query_request)
     
     manager_mock = Mock()
     
     handler._manager = Mock()
     handler.write_message = Mock(side_effects = ValueError)
     handler._manager = manager_mock
     
     # Act
     handler.open(resource_type = "test")
     
     # Assert
     self.assertTrue(manager_mock.createChannel.called)
     self.assertEqual(manager_mock.createChannel.call_args[0][0], { "name": "test", "ts": { "gte": 145 } })
Beispiel #12
0
    def test_subscription_bad_query(self):
        # Arrange
        app = Mock(ui_methods={}, ui_modules={}, async_db={"tests": None})
        query_request = Mock()
        query_request.arguments = dict(
            query=["{ name: 'test', ts: { gte: 145 }"])

        manager_mock = Mock()

        handler = SubscriptionHandler(app, query_request)
        handler._manager = manager_mock
        handler.write_message = Mock(side_effects=ValueError)

        # Act
        handler.open(resource_type="test")

        # Assert
        self.assertFalse(handler.client)
        self.assertFalse(manager_mock.createChannel.called)