Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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())
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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)