hiring_calculator/test_sso.py

34 lines
1.3 KiB
Python

import unittest
import json
from app import app
class SSOTestCase(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
self.app.testing = True
def test_get_countries_unauthorized(self):
"""Test that /api/countries requires auth"""
response = self.app.get('/api/countries')
self.assertEqual(response.status_code, 401)
data = json.loads(response.data)
self.assertEqual(data['error'], 'Missing or invalid token')
def test_calc_mgmt_unauthorized(self):
"""Test that calculation endpoints require auth"""
payload = {'sellAnnual': 100000, 'buyAnnual': 50000, 'country': 'United Kingdom'}
response = self.app.post('/api/calculate/mgmt', json=payload)
self.assertEqual(response.status_code, 401)
def test_admin_login_unauthorized(self):
"""Test that admin login requires auth (SSO token first)"""
response = self.app.post('/api/admin/login', json={'password': 'password'})
self.assertEqual(response.status_code, 401)
def test_admin_data_unauthorized(self):
"""Test that admin data requires auth"""
response = self.app.get('/api/admin/data')
self.assertEqual(response.status_code, 401)
if __name__ == '__main__':
unittest.main()