From 3cd05013abd13782c65b1475f15fb5007d8d223f Mon Sep 17 00:00:00 2001 From: androiddrew Date: Thu, 19 Oct 2017 21:20:15 -0400 Subject: [PATCH] added stubs for authentication and CRUD tests --- config.ini | 2 +- cookie_api/auth.py | 1 - cookie_api/models/schema.py | 6 +-- tests.py | 21 ---------- tests/__init__.py | 0 tests/test_auth.py | 80 +++++++++++++++++++++++++++++++++++++ tests/test_cookies.py | 29 ++++++++++++++ 7 files changed, 113 insertions(+), 26 deletions(-) delete mode 100644 tests.py create mode 100644 tests/__init__.py create mode 100644 tests/test_auth.py create mode 100644 tests/test_cookies.py diff --git a/config.ini b/config.ini index 1140274..e345996 100644 --- a/config.ini +++ b/config.ini @@ -1,4 +1,4 @@ -; config.ini +# config.ini [user] BCRYPT_LOG_ROUNDS : 13 \ No newline at end of file diff --git a/cookie_api/auth.py b/cookie_api/auth.py index 9943f0c..7ed98b8 100644 --- a/cookie_api/auth.py +++ b/cookie_api/auth.py @@ -1,5 +1,4 @@ import datetime as dt -import json from apistar import Component, Settings, http, Route, Include from apistar.backends.sqlalchemy_backend import Session from apistar_jwt.authentication import get_jwt diff --git a/cookie_api/models/schema.py b/cookie_api/models/schema.py index 4085400..18058e2 100644 --- a/cookie_api/models/schema.py +++ b/cookie_api/models/schema.py @@ -9,9 +9,9 @@ from sqlalchemy.ext.compiler import compiles from sqlalchemy.types import DateTime as DateTimeType cfg = ConfigParser() -cfg.read('/Users/Drewbednar/PycharmProjects/apistar_tut/config.ini') +cfg.read('config.ini') -BCRYPT_LOG_ROUNDS = cfg.get('user', 'BCRYPT_LOG_ROUNDS') +BCRYPT_LOG_ROUNDS = int(cfg.get('user', 'BCRYPT_LOG_ROUNDS')) # can be moved to models util? @@ -62,7 +62,7 @@ class User(DBMixin, Base): def __init__(self, email, password, admin=False): self.email = email - self.password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(11)).decode() + self.password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(BCRYPT_LOG_ROUNDS)).decode() self.admin = admin def check_password(self, password): diff --git a/tests.py b/tests.py deleted file mode 100644 index a944f6c..0000000 --- a/tests.py +++ /dev/null @@ -1,21 +0,0 @@ -from app import welcome - -from apistar.test import TestClient - - -def test_welcome(): - """ - Testing a view directly. - """ - data = welcome() - assert data == {'message': 'Welcome to API Star!'} - - -def test_http_request(): - """ - Testing a view, using the test client. - """ - client = TestClient() - response = client.get('http://localhost/') - assert response.status_code == 200 - assert response.json() == {'message': 'Welcome to API Star!'} diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 0000000..9ddd92f --- /dev/null +++ b/tests/test_auth.py @@ -0,0 +1,80 @@ +# JWT Token +def test_encode_auth_token(): + """Test JWT token encoding""" + pass + + +def test_decode_auth_token(): + """Test JWT token decode""" + pass + + +# Register + +def test_registration(): + """ Test for user registration """ + pass + + +def test_registered_with_already_registered_user(): + """ Test registration with already registered email""" + pass + + +def test_registered_user_login(): + """ Test for login of registered-user login """ + pass + + +def test_non_registered_user_login(): + """ Test for login of non-registered user """ + pass + + +# Test Login + +def test_registered_user_login(self): + """ Test for login of registered-user login """ + pass + + +def test_non_registered_user_login(): + """ Test for login of non-registered user """ + pass + + +# Test Logout + +def test_valid_logout(): + """ Test for logout before token expires """ + pass + + +def test_invalid_logout(): + """ Testing logout after the token expires """ + pass + + +# User status + +def test_user_status(): + """ Test for user status """ + + +"""In order to get the user details of the currently logged in user, the auth token must be sent with the request within the header.""" + + +def test_user_status_malformed_bearer_token(): + """ Test for user status with malformed bearer token""" + pass + + +# Blacklist + +def test_valid_blacklisted_token_logout(): + """ Test for logout after a valid token gets blacklisted """ + pass + + +def test_valid_blacklisted_token_user(self): + """ Test for user status with a blacklisted valid token """ diff --git a/tests/test_cookies.py b/tests/test_cookies.py new file mode 100644 index 0000000..e4dd9ca --- /dev/null +++ b/tests/test_cookies.py @@ -0,0 +1,29 @@ +# CRUD Cookies + + +def test_get_cookies(): + pass + + +def test_get_cookie(): + pass + + +def test_valid_create_cookie(): + pass + + +def test_invalid_create_cookie(): + pass + + +def test_valid_update_cookie(): + pass + + +def test_invalid_update_cookie(): + pass + + +def test_delete_cookie(): + pass