def test_NoNetwork(self): import socket oldSocket = socket.socket def guard(*args, **kwargs): raise Exception("I told you not to use the Internet!") socket.socket = guard result = stooq.checkStock('stock|AMZN.US|main') socket.socket = oldSocket self.assertEqual(result, 'ERR: I told you not to use the Internet!')
def callback(ch, method, properties, body): data = body.decode("utf-8") res = stooq.checkStock(data) channel.basic_publish(exchange='my_exchange2', routing_key='test2', body=res)
def stock(): data = flask.request.args.get('ticker') return stooq.checkStock(data)
def test_TSLAStock(self): self.assertRegex(stooq.checkStock('stock|TSLA.US|main'), r'\w*.\w* quote is \$\d*.\d* per share')
def test_EmptyStock(self): self.assertEqual(stooq.checkStock('||main|'), 'ERR: Wrong No of parameters')
def test_EmptyMessage(self): self.assertEqual(stooq.checkStock(''), 'ERR: Input is missing')