def test_already_streaming(self): stream = StreamFactory(source=Node.me()) TicketFactory(stream=stream, source=Node.me(), destination=Node.me()) tickets_before = Ticket.query.count() self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=""), self.stop) response = self.wait() eq_(response.code, 200) eq_(Ticket.query.count(), tickets_before)
def test_get_stream(self): stream = StreamFactory() response = self.fetch(stream.absolute_url()) eq_(response.code, 200) result = json.loads(response.body) ok_('stream' in result) eq_(result['stream']['slug'], stream.slug) eq_(result['stream']['name'], stream.name)
def test_bad_destination(self): stream = StreamFactory() self.http_client.fetch( HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=json.dumps({"destination_uuid": "foo"})), self.stop, ) response = self.wait() eq_(response.code, 404)
def test_none_available(self): mockito.when(TicketsAPI).create(mockito.any(), destination_uuid=mockito.any()).thenReturn(None) stream = StreamFactory() tickets_before = Ticket.query.count() self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=""), self.stop) response = self.wait() eq_(response.code, 412) eq_(Ticket.query.count(), tickets_before)
def test_resume_stream(self): stream = StreamFactory() session.commit() data = {'streaming': True} eq_(stream.streaming, False) self.http_client.fetch( HTTPRequest(self.get_url(stream.absolute_url()), 'PUT', body=json.dumps(data)), self.stop) response = self.wait() eq_(response.code, 200) eq_(stream.streaming, True)
def test_trigger_locally(self): stream = StreamFactory(source=Node.me()) self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=""), self.stop) response = self.wait() eq_(response.code, 200) result = json.loads(response.body) ok_("ticket" in result) eq_(result["ticket"]["stream"], stream.slug) eq_(result["ticket"]["source"], Node.me().uuid) ticket = Ticket.query.first() eq_(ticket.stream, stream) eq_(ticket.destination, Node.me())
def test_remote_source(self): node = Node.me() node.supernode = True remote_node = NodeFactory() mockito.when(TicketsAPI).create(mockito.any(), destination_uuid=mockito.any()).thenReturn( {"source": remote_node.uuid, "source_port": 42, "hops": 1} ) stream = StreamFactory() tickets_before = Ticket.query.count() self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=""), self.stop) response = self.wait() eq_(response.code, 200) eq_(Ticket.query.count(), tickets_before + 1)
def test_other_known_tickets(self): node = Node.me() node.supernode = True stream = StreamFactory() existing_ticket = TicketFactory(stream=stream, source=stream.source, hops=1) mockito.when(TicketsAPI).create(mockito.any(), destination_uuid=mockito.any()).thenReturn( {"source": existing_ticket.destination.uuid, "source_port": 42, "hops": 1} ) tickets_before = Ticket.query.count() self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=""), self.stop) response = self.wait() eq_(response.code, 200) eq_(Ticket.query.count(), tickets_before + 1) ticket = Ticket.query.filter_by(destination=Node.me()).first() eq_(ticket.source, existing_ticket.destination)
def test_create(self): stream = StreamFactory(source=Node.me()) node = NodeFactory() self.http_client.fetch( HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=json.dumps({"destination_uuid": node.uuid})), self.stop, ) response = self.wait() eq_(response.code, 200) result = json.loads(response.body) ok_("ticket" in result) eq_(result["ticket"]["stream"], stream.slug) eq_(result["ticket"]["source"], Node.me().uuid) ticket = Ticket.query.first() eq_(ticket.stream, stream) eq_(ticket.destination, node)
def test_get_streams(self): Node.me() [StreamFactory() for _ in range(3)] response = self.fetch('/streams') eq_(response.code, 200) result = json.loads(response.body) ok_('streams' in result) for stream in result['streams']: ok_(Stream.get_by(name=stream['name']))
def test_create_twice_locally(self): stream = StreamFactory(source=Node.me()) TicketFactory(stream=stream, source=Node.me(), destination=Node.me()) self.http_client.fetch(HTTPRequest(self.get_url(stream.tickets_url()), "POST", body=""), self.stop) response = self.wait() eq_(response.code, 200)