Exemplo n.º 1
0
    def test_opened_starts_reader(self):
        fake_request = MagicMock()
        fake_socket = MagicMock()

        s = WebSocket(fake_socket)
        s.request = fake_request
        s.opened()

        s.request.get_queue_reader.assert_called_once_with('annotations', ANY)
Exemplo n.º 2
0
class TestWebSocket(unittest.TestCase):
    def setUp(self):
        fake_request = MagicMock()
        fake_socket = MagicMock()

        self.s = WebSocket(fake_socket)
        self.s.request = fake_request

    def test_opened_starts_reader(self):
        self.s.opened()
        self.s.request.get_queue_reader.assert_called_once_with(
            'annotations', ANY)

    def test_filter_message_with_uri_gets_expanded(self):
        filter_message = json.dumps({
            'filter': {
                'actions': {},
                'match_policy':
                'include_all',
                'clauses': [{
                    'field': '/uri',
                    'operator': 'equals',
                    'value': 'http://example.com',
                }],
            }
        })

        with patch('h.api.uri.expand') as expand:
            expand.return_value = [
                'http://example.com', 'http://example.com/alter',
                'http://example.com/print'
            ]
            msg = MagicMock()
            msg.data = filter_message

            self.s.received_message(msg)

            uri_filter = self.s.filter.filter['clauses'][0]
            uri_values = uri_filter['value']
            assert len(uri_values) == 3
            assert 'http://example.com' in uri_values
            assert 'http://example.com/alter' in uri_values
            assert 'http://example.com/print' in uri_values
Exemplo n.º 3
0
class TestWebSocket(unittest.TestCase):
    def setUp(self):
        fake_request = MagicMock()
        fake_socket = MagicMock()

        self.s = WebSocket(fake_socket)
        self.s.request = fake_request

    def test_opened_starts_reader(self):
        self.s.opened()
        self.s.request.get_queue_reader.assert_called_once_with('annotations', ANY)

    def test_filter_message_with_uri_gets_expanded(self):
        filter_message = json.dumps({
            'filter': {
                'actions': {},
                'match_policy': 'include_all',
                'clauses': [{
                    'field': '/uri',
                    'operator': 'equals',
                    'value': 'http://example.com',
                }],
            }
        })

        with patch('h.api.uri.expand') as expand:
            expand.return_value = ['http://example.com',
                                   'http://example.com/alter',
                                   'http://example.com/print']
            msg = MagicMock()
            msg.data = filter_message

            self.s.received_message(msg)

            uri_filter = self.s.filter.filter['clauses'][0]
            uri_values = uri_filter['value']
            assert len(uri_values) == 3
            assert 'http://example.com' in uri_values
            assert 'http://example.com/alter' in uri_values
            assert 'http://example.com/print' in uri_values
Exemplo n.º 4
0
class TestWebSocket(unittest.TestCase):
    def setUp(self):
        fake_request = MagicMock()
        fake_socket = MagicMock()

        self.s = WebSocket(fake_socket)
        self.s.request = fake_request

    def test_opened_starts_reader(self):
        self.s.opened()
        self.s.request.get_queue_reader.assert_called_once_with("annotations", ANY)

    def test_filter_message_with_uri_gets_expanded(self):
        filter_message = json.dumps(
            {
                "filter": {
                    "actions": {},
                    "match_policy": "include_all",
                    "clauses": [{"field": "/uri", "operator": "equals", "value": "http://example.com"}],
                }
            }
        )

        with patch("h.api.uri.expand") as expand:
            expand.return_value = ["http://example.com", "http://example.com/alter", "http://example.com/print"]
            msg = MagicMock()
            msg.data = filter_message

            self.s.received_message(msg)

            uri_filter = self.s.filter.filter["clauses"][0]
            uri_values = uri_filter["value"]
            assert len(uri_values) == 3
            assert "http://example.com" in uri_values
            assert "http://example.com/alter" in uri_values
            assert "http://example.com/print" in uri_values
Exemplo n.º 5
0
    def setUp(self):
        fake_request = MagicMock()
        fake_socket = MagicMock()

        self.s = WebSocket(fake_socket)
        self.s.request = fake_request
Exemplo n.º 6
0
    def setUp(self):
        fake_request = MagicMock()
        fake_socket = MagicMock()

        self.s = WebSocket(fake_socket)
        self.s.request = fake_request