From 7b7bd5f4e3f1194eb4762de6b837220e3028e9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Sat, 15 Apr 2017 23:54:55 +0300 Subject: [PATCH] Adding tests --- test/__init__.py | 17 +++++++++++ test/test_scoreboard.py | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/__init__.py create mode 100644 test/test_scoreboard.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..1987b55 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,17 @@ +""" + Author: Denis Nutiu + This file is part of scoreboard-benchmark. + + scoreboard-benchmark is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + scoreboard-benchmark is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with scoreboard-benchmark . If not, see . +""" \ No newline at end of file diff --git a/test/test_scoreboard.py b/test/test_scoreboard.py new file mode 100644 index 0000000..b6c44b0 --- /dev/null +++ b/test/test_scoreboard.py @@ -0,0 +1,67 @@ +""" + Author: Denis Nutiu + This file is part of scoreboard-benchmark. + + scoreboard-benchmark is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + scoreboard-benchmark is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with scoreboard-benchmark . If not, see . +""" +from src.models import db, Result +from src.application import create_app +import unittest +import json + + +class ScoreboardTestCase(unittest.TestCase): + + def setUp(self): + self.app = create_app('testing') + self.app_context = self.app.app_context() + self.app_context.push() + self.client = self.app.test_client(use_cookies=True) + + def tearDown(self): + db.drop_all() + self.app_context.pop() + + def test_index(self): + response = self.client.get("/") + self.assertEqual(response.status_code, 200) + + def test_not_found(self): + response = self.client.get("/404notfound") + self.assertEqual(response.status_code, 404) + + def test_entry(self): + response = self.client.get("/entry/1") + self.assertEqual(response.status_code, 404) + + data = Result(cpu="TestCPU", gpu="TestGPU", log="TestLOG") + db.session.add(data) + db.session.commit() + + response = self.client.get("/entry/1") + self.assertEqual(response.status_code, 200) + + def test_add_entry(self): + data = dict( + gpu="CpuTesting2", + cpu="GPUTesting2", + log="This is a logfile", + score=200 + ) + response = self.client.post('/upload', + data=json.dumps(data), + content_type='application/json') + + self.assertTrue("true" in response.get_data(as_text=True)) + self.assertEqual(response.status_code, 200)