예제 #1
0
 def test_two_clients(self):
     self.server.action = lambda request: request
     with Client(CER_PATH, self.SERVER_ADDRESS) as c1:
         with Client(CER_PATH, self.SERVER_ADDRESS) as c2:
             response = c1.exchange({"field_1": "value_a"})
             self.assertEqual(response, {"field_1": "value_a"})
             response = c2.exchange({"field_1": "value_b"})
             self.assertEqual(response, {"field_1": "value_b"})
예제 #2
0
    def test_exception_is_logged(self):
        class MyException(Exception):
            pass

        def mock_action(data):
            raise MyException("BOOM!!!")

        self.server.action = mock_action
        self.assertNotIn("MyException: BOOM!!!", log_read())
        with Client(CER_PATH, self.SERVER_ADDRESS) as client:
            response = client.exchange(b'BOOM!!!')
        self.assertEqual(response, b'')
        self.assertIn("MyException: BOOM!!!", log_read())
예제 #3
0
    def test_exchange_json_utf8_data(self):
        def mock_json_action(request):
            def transform(value):
                return value.upper() if isinstance(value, str) else value

            return {k: transform(v) for k, v in request.items()}

        self.server.action = mock_json_action
        with Client(CER_PATH, self.SERVER_ADDRESS) as client:
            response = client.exchange({
                "field_a": "value_a_àì",
                "field_b": ["value_b_1", "value_b_2"]
            })
        self.assertEqual(response, {
            'field_a': 'VALUE_A_ÀÌ',
            'field_b': ['value_b_1', 'value_b_2']
        })
예제 #4
0
 def test_no_terminator_in_json(self):
     self.server.action = lambda request: request
     with Client(CER_PATH, self.SERVER_ADDRESS) as client:
         response = client.exchange({"field_a": "value \n with newline"})
     self.assertEqual(response, {"field_a": "value \n with newline"})
예제 #5
0
 def test_no_terminator_in_data(self):
     self.server.action = None
     with Client(CER_PATH, self.SERVER_ADDRESS) as client:
         with self.assertRaises(Exception) as ex:
             client.exchange(b'12345\n67890')
         self.assertIn("Terminator found", str(ex.exception))
예제 #6
0
 def test_huge_request(self):
     self.server.action = lambda data: data
     with Client(CER_PATH, self.SERVER_ADDRESS) as client:
         response = client.exchange((b'#' * 10000))
     self.assertEqual(response, b'#' * 10000)
예제 #7
0
 def test_echo_upper(self):
     self.server.action = lambda data: data.upper()
     with Client(CER_PATH, self.SERVER_ADDRESS) as client:
         response = client.exchange('dummy data'.encode('utf-8'))
     self.assertEqual(response, b'DUMMY DATA')
예제 #8
0
파일: watch.py 프로젝트: marriola/viewfs
    from win32.watch import Watch
else:
    from linux.watch import Watch

logging.basicConfig(level=logging.DEBUG if config.verbose else logging.INFO)
logger = logging.getLogger('watch')

# Start up viewfs in the background while we set up inotify for our collection
logger.info('setting up watch...')
watch = Watch(config.watch.collection_root)
logger.debug('done')

# Receive a randomly generated UUID from viewfs. This will be the name of the
# pseudo-file we query in order to trigger viewfs to update.

client = Client(config)
client.connect()
uuid = client.receive()
control_file = os.path.join(config.view.view_root, uuid)

writes = []
deletes = []
renames = []
last_update = None

for e in watch.event_gen(yield_nones=True):
    if not e:
        # No events. If any have been logged, send them to viewfs.

        if last_update and (time.time() - last_update
                            ) >= config.watch.batch_processing_delay: