diff options
author | 2018-03-29 04:52:29 -0400 | |
---|---|---|
committer | 2018-03-29 09:52:29 +0100 | |
commit | 1889f3248ae83cc773a5443c6ba0f62834d73b7b (patch) | |
tree | 7603d1da7f64006075cf3a8b58548e1a49ca6840 /app_test.py | |
parent | Reorder resources.json (diff) |
Oauth (#45)
* Creating a OAUTH login for the site. We still need to have a way to fill in credentials however.
Signed-off-by: Zwork101 <[email protected]>
* How ya like me now Travis?
Signed-off-by: Zwork101 <[email protected]>
* Fix slight error in database insertion
* Revert "Fix slight error in database insertion" (wrong branch)
This reverts commit 9ac6cbb
* Don't have snekchek working, but I'll try again.
Signed-off-by: Zwork101 <[email protected]>
* Please enter the commit message for your changes. Lines starting
* Adding Oauth2 login to site.
* Add prefix
* Add prefix
* This never happened
* Flipping Travis
I still can't get snekchek to work locally.
* Added a whole bunch of stuff, ready to be used.
Signed-off-by: Zwork101 <[email protected]>
* Making sessions more secure, and future safe.
Signed-off-by: Zwork101 <[email protected]>
* Adding some quick stuff
Signed-off-by: Zwork101 <[email protected]>
* Appease the flake8 gods
Signed-off-by: Zwork101 <[email protected]>
* Appease the flake8 gods
Signed-off-by: Zwork101 <[email protected]>
* Whoops
Signed-off-by: Zwork101 <[email protected]>
* Add comments, fix user_data function.
Signed-off-by: Zwork101 <[email protected]>
* Whooops, forgot to flake :/
Signed-off-by: Zwork101 <[email protected]>
* Make it look nicer, thanks Aperture.
Signed-off-by: Zwork101 <[email protected]>
* Fixing login issues and added button
* Add a OauthMixin to allow for easy data access. Clean stuff up.
Signed-off-by: Zwork101 <[email protected]>
* Fix a test, and use self.assertEqual rather then self.assertEquals!
Signed-off-by: Zwork101 <[email protected]>
* Please don't ask how that happened.
Signed-off-by: Zwork101 <[email protected]>
* Added some tests, moved a bunch of stuff around. Mainly cleaned
stuff up.
Signed-off-by: Zwork101 <[email protected]>
* Add a ton of tests, try to please the coverall gods :D, moved some
code into a function for testing.
Signed-off-by: Zwork101 <[email protected]>
* Just some stupid stuff I missed.
Signed-off-by: Zwork101 <[email protected]>
* Fix an issue with the test, and add docs
Signed-off-by: Zwork101 <[email protected]>
* Remove pointless function. (join_user)
Signed-off-by: Zwork101 <[email protected]>
* Fix test consistency
Diffstat (limited to 'app_test.py')
-rw-r--r-- | app_test.py | 125 |
1 files changed, 112 insertions, 13 deletions
diff --git a/app_test.py b/app_test.py index 2176fe08..31acf12d 100644 --- a/app_test.py +++ b/app_test.py @@ -5,6 +5,7 @@ from flask import Blueprint from flask_testing import TestCase from app import manager +from pysite.constants import DISCORD_OAUTH_REDIRECT, DISCORD_OAUTH_AUTHORIZED manager.app.tests_blueprint = Blueprint("tests", __name__) manager.load_views(manager.app.tests_blueprint, "pysite/views/tests") @@ -33,7 +34,7 @@ class RootEndpoint(SiteTest): """ Test cases for the root endpoint and error handling """ def test_index(self): - """ Check the root path reponds with 200 OK """ + """ Check the root path responds with 200 OK """ response = self.client.get('/', 'http://pytest.local') self.assertEqual(response.status_code, 200) @@ -79,23 +80,38 @@ class RootEndpoint(SiteTest): self.assertEqual(response.status_code, 302) def test_ws_test(self): - """ check ws_test responds """ + """ Check ws_test responds """ response = self.client.get('/ws_test') self.assertEqual(response.status_code, 200) + def test_oauth_redirects(self): + """ Check oauth redirects """ + response = self.client.get(DISCORD_OAUTH_REDIRECT) + self.assertEqual(response.status_code, 302) + + def test_oauth_logout(self): + """ Check oauth redirects """ + response = self.client.get('/auth/logout') + self.assertEqual(response.status_code, 302) + + def test_oauth_authorized(self): + """ Check oauth authorization """ + response = self.client.get(DISCORD_OAUTH_AUTHORIZED) + self.assertEqual(response.status_code, 302) + def test_datadog_redirect(self): """ Check datadog path redirects """ response = self.client.get('/datadog') self.assertEqual(response.status_code, 302) def test_500_easter_egg(self): - """Check the status of the /500 page""" + """ Check the status of the /500 page""" response = self.client.get("/500") self.assertEqual(response.status_code, 500) class ApiEndpoints(SiteTest): - """ test cases for the api subdomain """ + """ Test cases for the api subdomain """ def test_api_unknown_route(self): """ Check api unknown route """ response = self.client.get('/', app.config['API_SUBDOMAIN']) @@ -240,7 +256,7 @@ class Utilities(SiteTest): ev = pysite.base_route.ErrorView() try: - ev.setup('sdf', 'sdfsdf') + ev.setup(manager, 'sdfsdf') except RuntimeError: return True raise Exception('Expected runtime error on setup() when giving wrongful arguments') @@ -259,9 +275,9 @@ class Utilities(SiteTest): return True - class MixinTests(SiteTest): """ Test cases for mixins """ + def test_dbmixin_runtime_error(self): """ Check that wrong values for error view setup raises runtime error """ from pysite.mixins import DBMixin @@ -280,7 +296,7 @@ class MixinTests(SiteTest): try: dbm = DBMixin() dbm.table_name = 'Table' - self.assertEquals(dbm.table, 'Table') + self.assertEqual(dbm.table, 'Table') except AttributeError: pass @@ -299,7 +315,7 @@ class MixinTests(SiteTest): rv = RouteView() try: - rv.setup('sdf', 'sdfsdf') + rv.setup(manager, 'sdfsdf') except RuntimeError: return True raise Exception('Expected runtime error on setup() when giving wrongful arguments') @@ -307,10 +323,54 @@ class MixinTests(SiteTest): def test_route_manager(self): """ Check route manager """ from pysite.route_manager import RouteManager + os.environ['WEBPAGE_SECRET_KEY'] = 'super_secret' rm = RouteManager() self.assertEqual(rm.app.secret_key, 'super_secret') + def test_oauth_property(self): + """ Make sure the oauth property works""" + from flask import Blueprint + + from pysite.route_manager import RouteView + from pysite.oauth import OauthBackend + + class TestRoute(RouteView): + name = "test" + path = "/test" + + tr = TestRoute() + tr.setup(manager, Blueprint("test", "test_name")) + self.assertIsInstance(tr.oauth, OauthBackend) + + def test_user_data_property(self): + """ Make sure the user_data property works""" + from flask import Blueprint + + from pysite.route_manager import RouteView + + class TestRoute(RouteView): + name = "test" + path = "/test" + + tr = TestRoute() + tr.setup(manager, Blueprint("test", "test_name")) + self.assertIs(tr.user_data, None) + + def test_logged_in_property(self): + """ Make sure the user_data property works""" + from flask import Blueprint + + from pysite.route_manager import RouteView + + class TestRoute(RouteView): + name = "test" + path = "/test" + + tr = TestRoute() + tr.setup(manager, Blueprint("test", "test_name")) + self.assertIs(tr.logged_in, False) + class DecoratorTests(SiteTest): def test_decorator_api_json(self): @@ -352,22 +412,22 @@ class DatabaseTests(SiteTest): rdb = RethinkDB() # Create table name and expect it to work result = rdb.create_table(generated_table_name) - self.assertEquals(result, True) + self.assertEqual(result, True) # Create the same table name and expect it to already exist result = rdb.create_table(generated_table_name) - self.assertEquals(result, False) + self.assertEqual(result, False) # Drop table and expect it to work result = rdb.drop_table(generated_table_name) - self.assertEquals(result, True) + self.assertEqual(result, True) # Drop the same table and expect it to already be gone result = rdb.drop_table(generated_table_name) - self.assertEquals(result, False) + self.assertEqual(result, False) # This is to get some more code coverage - self.assertEquals(rdb.teardown_request('_'), None) + self.assertEqual(rdb.teardown_request('_'), None) class TestWebsocketEcho(SiteTest): @@ -380,3 +440,42 @@ class TestWebsocketEcho(SiteTest): ew.on_open() ew.on_message('message') ew.on_close() + + +class TestOauthBackend(SiteTest): + """ Test cases for the oauth.py file """ + + def test_get(self): + """ Make sure the get function returns nothing """ + self.assertIs(manager.oauth_backend.get(), None) + + def test_delete(self): + """ Make sure the delete function returns nothing """ + self.assertIs(manager.oauth_backend.delete(None), None) + + def test_logout(self): + """ Make sure at least apart of logout is working :/ """ + self.assertIs(manager.oauth_backend.logout(), None) + + def test_add_user(self): + """ Make sure function adds values to database and session """ + from flask import session + + from pysite.constants import OAUTH_DATABASE + + sess_id = "hey bro wazup" + fake_token = {"access_token": "access_token", "id": sess_id, "refresh_token": "refresh_token", "expires_at": 5} + fake_user = {"id": "1235678987654321", "username": "Zwacky", "discriminator": "#6660", "email": "[email protected]"} + manager.db.conn = manager.db.get_connection() + manager.oauth_backend.add_user(fake_token, fake_user, sess_id) + + self.assertEqual(sess_id, session["session_id"]) + fake_token["snowflake"] = fake_user["id"] + fake_user["user_id"] = fake_user["id"] + del fake_user["id"] + self.assertEqual(fake_token, manager.db.get(OAUTH_DATABASE, sess_id)) + self.assertEqual(fake_user, manager.db.get("users", fake_user["user_id"])) + + manager.db.delete(OAUTH_DATABASE, sess_id) + manager.db.delete("users", fake_user["user_id"]) + manager.db.teardown_request(None) |