Exemplo n.º 1
0
    def testDatagramStream(self):
        client = self._registry.create('test:value',
                                       project='test',
                                       prefix='foo/bar',
                                       coordinator_host='example.appspot.com')
        with client.datagram('mystream') as fd:
            self.assertEqual(
                fd.path,
                streamname.StreamPath(prefix='foo/bar', name='mystream'))
            self.assertEqual(
                fd.get_viewer_url(),
                'https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fmystream'
            )
            fd.send('datagram0')
            fd.send('dg1')
            fd.send('')
            fd.send('dg3')

        conn = client.last_conn
        self.assertTrue(conn.closed)

        header, data = conn.interpret()
        self.assertEqual(header, {'name': 'mystream', 'type': 'datagram'})
        self.assertEqual(list(self._split_datagrams(data)),
                         ['datagram0', 'dg1', '', 'dg3'])
 def testParseValidPath(self):
     for path in (
             'foo/+/bar',
             'foo/bar/+/baz',
     ):
         prefix, name = path.split('/+/')
         parsed = streamname.StreamPath.parse(path)
         self.assertEqual(parsed,
                          streamname.StreamPath(prefix=prefix, name=name))
         self.assertEqual(str(parsed), path)
    def testLogDogViewerUrl(self):
        for project, path, url in (
            ('test', streamname.StreamPath(prefix='foo', name='bar/baz'),
             'https://example.appspot.com/v/?s=test%2Ffoo%2F%2B%2Fbar%2Fbaz'),
            ('test', streamname.StreamPath(prefix='foo', name='bar/**'),
             'https://example.appspot.com/v/?s=test%2Ffoo%2F%2B%2Fbar%2F%2A%2A'
             ),
            ('test', streamname.StreamPath(prefix='**', name='**'),
             'https://example.appspot.com/v/?s=test%2F%2A%2A%2F%2B%2F%2A%2A'),
        ):
            self.assertEqual(
                streamname.get_logdog_viewer_url('example.appspot.com',
                                                 project, path), url)

        # Multiple streams.
        self.assertEqual(
            streamname.get_logdog_viewer_url(
                'example.appspot.com',
                'test',
                streamname.StreamPath(prefix='foo', name='bar/baz'),
                streamname.StreamPath(prefix='qux', name='**'),
            ),
            ('https://example.appspot.com/v/?s=test%2Ffoo%2F%2B%2Fbar%2Fbaz&'
             's=test%2Fqux%2F%2B%2F%2A%2A'))
Exemplo n.º 4
0
  def testBinaryStream(self):
    client = self._registry.create('test:value',
                                   project='test',
                                   prefix='foo/bar',
                                   coordinator_host='example.appspot.com')
    with client.binary('mystream') as fd:
      self.assertEqual(
          fd.path,
          streamname.StreamPath(prefix='foo/bar', name='mystream'))
      self.assertEqual(
          fd.get_viewer_url(),
          'https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fmystream')
      fd.write('\x60\x0d\xd0\x65')

    conn = client.last_conn
    self.assertTrue(conn.closed)

    header, data = conn.interpret()
    self.assertEqual(header, {'name': 'mystream', 'type': 'binary'})
    self.assertEqual(data, '\x60\x0d\xd0\x65')