-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import tornado.web | ||
import os.path | ||
from ....ui.handlers.accounts import ServerAccountsHandler | ||
from mock import MagicMock | ||
|
||
|
||
class TestAccounts: | ||
def setup(self): | ||
settings = { | ||
"debug": "True", | ||
"template_path": os.path.join(os.path.dirname(__file__), '../', '../', '../', 'ui', 'assets', 'templates'), | ||
} | ||
|
||
self.app = tornado.web.Application(**settings) | ||
self.app._transforms = [] | ||
|
||
def test_AccountsHandler(self): | ||
req = MagicMock() | ||
req.body = '' | ||
x = ServerAccountsHandler(self.app, req, trading_engine=MagicMock(), psp_kwargs={}) | ||
x.te._ex.accounts = MagicMock() | ||
x.te._ex.accounts.return_value = [MagicMock()] | ||
x.te._ex.accounts.return_value[0].to_dict = MagicMock() | ||
x.te._ex.accounts.return_value[0].to_dict.return_value = {'test': 1} | ||
|
||
x._transforms = [] | ||
x.get() | ||
|
||
assert len(x._write_buffer) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import tornado.web | ||
import os.path | ||
from ....ui.handlers.base import HTTPHandler | ||
from mock import MagicMock | ||
|
||
|
||
class TestBase: | ||
def setup(self): | ||
settings = { | ||
"debug": "True", | ||
"template_path": os.path.join(os.path.dirname(__file__), '../', '../', '../', 'ui', 'assets', 'templates'), | ||
} | ||
self.app = tornado.web.Application(**settings) | ||
self.app._transforms = [] | ||
|
||
def test_validate(self): | ||
req = MagicMock() | ||
req.body = '' | ||
x = HTTPHandler(self.app, req) | ||
x._transforms = [] | ||
x.render_template('404.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import tornado.web | ||
import os.path | ||
from ....ui.handlers.html import HTMLHandler, HTMLOpenHandler | ||
from mock import MagicMock | ||
from tornado.web import HTTPError | ||
|
||
|
||
class TestHTML: | ||
def setup(self): | ||
settings = { | ||
"debug": "True", | ||
"template_path": os.path.join(os.path.dirname(__file__), '../', '../', '../', 'ui', 'assets', 'templates'), | ||
} | ||
self.app = tornado.web.Application(**settings) | ||
self.app._transforms = [] | ||
|
||
def test_HTMLOpenHandler(self): | ||
req = MagicMock() | ||
req.body = '' | ||
x = HTMLOpenHandler(self.app, req, template='404.html') | ||
x._transforms = [] | ||
x.get_current_user = lambda: False | ||
|
||
x.template = '404.html' | ||
x.get() | ||
|
||
x = HTMLOpenHandler(self.app, req, template=None) | ||
x._transforms = [] | ||
x.get_current_user = lambda: False | ||
x.get() | ||
|
||
def test_HTMLHandler(self): | ||
req = MagicMock() | ||
req.body = '' | ||
x = HTMLHandler(self.app, req, template='404.html') | ||
x._transforms = [] | ||
x.get_current_user = lambda: False | ||
|
||
x.template = '404.html' | ||
try: | ||
x.get() | ||
assert False | ||
except HTTPError: | ||
pass | ||
|
||
x = HTMLHandler(self.app, req, template=None) | ||
x._transforms = [] | ||
x.get_current_user = lambda: True | ||
x.get() | ||
|
||
x = HTMLHandler(self.app, req, template='404.html') | ||
x._transforms = [] | ||
x.get_current_user = lambda: b'test' | ||
x.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import tornado.web | ||
import os.path | ||
from ....ui.handlers.messages import ServerMessagesMixin, ServerMessagesHandler, ServerMessagesWSHandler | ||
from mock import MagicMock | ||
import tornado.websocket | ||
|
||
|
||
class TestMessages: | ||
def setup(self): | ||
settings = { | ||
"debug": "True", | ||
"template_path": os.path.join(os.path.dirname(__file__), '../', '../', 'ui', 'assets', 'templates'), | ||
} | ||
self.app = tornado.web.Application(**settings) | ||
self.app._transforms = [] | ||
|
||
def test_ServerMessagesMixin(self): | ||
req = MagicMock() | ||
req.body = '' | ||
|
||
x = ServerMessagesMixin() | ||
x._transforms = [] | ||
|
||
x.te = MagicMock() | ||
x.te._ex = MagicMock() | ||
x.te._ex.messages = MagicMock() | ||
x.te._ex.messages.return_value = [MagicMock()] | ||
x.te._ex.messages.return_value[0].to_dict = MagicMock() | ||
x.te._ex.messages.return_value[0].to_dict.return_value = {'test': 1, 'instrument': {'underlying': 'test'}} | ||
|
||
x.get_data() | ||
x.get_data('test') | ||
x.get_data(None, None, 0, 'BTCUSD') | ||
|
||
x.te._ex.messages.return_value = {'TRADE': [MagicMock()]} | ||
x.te._ex.messages.return_value['TRADE'][0].to_dict = MagicMock() | ||
x.te._ex.messages.return_value['TRADE'][0].to_dict.return_value = {'test': 1} | ||
|
||
x.get_data(type='TRADE') | ||
x.get_data(type='TRADE', page=0, pairtype='test') | ||
x.get_data(type='TRADE', page=0, pairtype='BTCUSD') | ||
x.get_data(type='TRADE', page=0, pairtype='BTCUSD') | ||
|
||
def test_ServerMessages(self): | ||
req = MagicMock() | ||
req.body = '' | ||
|
||
x = ServerMessagesHandler(self.app, req, trading_engine=MagicMock(), psp_kwargs={}) | ||
x._transforms = [] | ||
|
||
x.te._ex.messages = MagicMock() | ||
x.te._ex.messages.return_value = [MagicMock()] | ||
x.te._ex.messages.return_value[0].to_dict = MagicMock() | ||
x.te._ex.messages.return_value[0].to_dict.return_value = {'test': 1, 'instrument': {'underlying': 'test'}} | ||
x.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from mock import MagicMock | ||
|
||
|
||
class TestExecution: | ||
def setup(self): | ||
pass | ||
# setup() before each test method | ||
|
||
def teardown(self): | ||
pass | ||
# teardown() after each test method | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
pass | ||
# setup_class() before any methods in this class | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
pass | ||
# teardown_class() after any methods in this class | ||
|
||
def test_init(self): | ||
from ...ui.server import ServerApplication | ||
s = ServerApplication(MagicMock()) | ||
assert s |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@font-face { | ||
font-family: 'Ubuntu'; | ||
font-style: normal; | ||
font-weight: 400; | ||
src: local('Ubuntu Regular'), local('Ubuntu-Regular'), url(https://fonts.gstatic.com/s/ubuntu/v11/4iCs6KVjbNBYlgoKfw7z.ttf) format('truetype'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<html> | ||
<p>Not found...</p> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="stylesheet" type="text/css" href="/static/css/fonts.css"> | ||
<link href="/static/css/root.css" rel="stylesheet"> | ||
<link href="/static/css/base.css" rel="stylesheet"> | ||
<title>{{ title }}</title> | ||
|
||
{% block header %} | ||
{% endblock %} | ||
|
||
</head> | ||
<body> | ||
{% block main %} | ||
{% endblock %} | ||
</body> | ||
|
||
{% block script %} | ||
{% endblock %} | ||
</html> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import tornado.web | ||
from perspective import PerspectiveHTTPMixin | ||
|
||
|
||
class ServerAccountsHandler(PerspectiveHTTPMixin, tornado.web.RequestHandler): | ||
'''Server Handler | ||
Extends: | ||
tornado.web.RequestHandler | ||
''' | ||
|
||
def initialize(self, trading_engine, **psp_kwargs): | ||
self.te = trading_engine | ||
self.psp_kwargs = psp_kwargs | ||
|
||
def get(self): | ||
try: | ||
self.psp_kwargs['data'] = [a.to_dict(True) for ex in self.te.exchanges().values() for a in ex.accounts()] | ||
self.loadData(**self.psp_kwargs) | ||
self.write(self.getData()) | ||
except Exception as e: | ||
self.write(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import tornado.ioloop | ||
import tornado.web | ||
import tornado.websocket | ||
from jinja2 import Environment, FileSystemLoader, TemplateNotFound | ||
|
||
|
||
class HTTPHandler(tornado.web.RequestHandler): | ||
'''Just a default handler''' | ||
def initialize(self, *args, **kwargs): | ||
'''Initialize the server competition registry handler | ||
This handler is responsible for managing competition | ||
registration. | ||
Arguments: | ||
competitions {dict} -- a reference to the server's dictionary of competitions | ||
''' | ||
super(HTTPHandler, self).initialize(*args, **kwargs) | ||
|
||
def render_template(self, template, **kwargs): | ||
if hasattr(self, 'template_dirs'): | ||
template_dirs = self.template_dirs | ||
else: | ||
template_dirs = [] | ||
|
||
if self.settings.get('template_path', ''): | ||
template_dirs.append( | ||
self.settings["template_path"] | ||
) | ||
env = Environment(loader=FileSystemLoader(template_dirs)) | ||
|
||
try: | ||
template = env.get_template(template) | ||
except TemplateNotFound: | ||
raise TemplateNotFound(template) | ||
|
||
kwargs['current_user'] = self.current_user.decode('utf-8') if self.current_user else '' | ||
content = template.render(**kwargs) | ||
return content | ||
|
||
|
||
class WebSocketHandler(tornado.websocket.WebSocketHandler): | ||
'''Just a default handler''' | ||
def initialize(self, *args, **kwargs): | ||
'''Initialize the server competition registry handler | ||
This handler is responsible for managing competition | ||
registration. | ||
Arguments: | ||
competitions {dict} -- a reference to the server's dictionary of competitions | ||
''' | ||
super(WebSocketHandler, self).initialize(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import tornado.web | ||
from .base import HTTPHandler | ||
|
||
|
||
class HTMLOpenHandler(HTTPHandler): | ||
def initialize(self, template=None, template_kwargs=None, **kwargs): | ||
super(HTMLOpenHandler, self).initialize() | ||
self.template = template | ||
self.template_kwargs = template_kwargs or {} | ||
|
||
def get(self, *args): | ||
'''Get the login page''' | ||
if not self.template: | ||
self.redirect('/') | ||
else: | ||
if self.request.path == '/logout': | ||
self.clear_cookie("user") | ||
template = self.render_template(self.template, **self.template_kwargs) | ||
self.write(template) | ||
|
||
|
||
class HTMLHandler(HTMLOpenHandler): | ||
@tornado.web.authenticated | ||
def get(self, *args): | ||
'''Get the login page''' | ||
if not self.template: | ||
self.redirect('/') | ||
else: | ||
template = self.render_template(self.template, **self.template_kwargs) | ||
self.write(template) |
Oops, something went wrong.