63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
import unittest
|
|
import json
|
|
from app import app, ADMIN_PASSWORD
|
|
|
|
class HiringCalculatorTestCase(unittest.TestCase):
|
|
def setUp(self):
|
|
self.app = app.test_client()
|
|
self.app.testing = True
|
|
|
|
def test_get_countries_public(self):
|
|
"""Test that public country list does NOT contain multipliers"""
|
|
response = self.app.get('/api/countries')
|
|
self.assertEqual(response.status_code, 200)
|
|
data = json.loads(response.data)
|
|
self.assertTrue(len(data) > 0)
|
|
first_country = data[0]
|
|
self.assertIn('Country', first_country)
|
|
self.assertIn('Currency', first_country)
|
|
self.assertNotIn('Multiplier', first_country)
|
|
self.assertNotIn('WorkingDays', first_country)
|
|
|
|
def test_calc_mgmt(self):
|
|
"""Test Management Fee calculation"""
|
|
payload = {
|
|
'sellAnnual': 150000,
|
|
'buyAnnual': 75000,
|
|
'country': 'United Kingdom'
|
|
}
|
|
response = self.app.post('/api/calculate/mgmt', json=payload)
|
|
self.assertEqual(response.status_code, 200)
|
|
data = json.loads(response.data)
|
|
# UK Multiplier is 1.1755
|
|
# CTC = 75000 * 1.1755 = 88162.5
|
|
# GP = 150000 - 88162.5 = 61837.5
|
|
self.assertAlmostEqual(data['ctc'], 88162.5)
|
|
self.assertAlmostEqual(data['gp'], 61837.5)
|
|
|
|
def test_admin_login_success(self):
|
|
"""Test Admin login with correct password"""
|
|
response = self.app.post('/api/admin/login', json={'password': ADMIN_PASSWORD})
|
|
self.assertEqual(response.status_code, 200)
|
|
data = json.loads(response.data)
|
|
self.assertTrue(data['success'])
|
|
|
|
def test_admin_login_fail(self):
|
|
"""Test Admin login with incorrect password"""
|
|
response = self.app.post('/api/admin/login', json={'password': 'wrong'})
|
|
self.assertEqual(response.status_code, 401)
|
|
|
|
def test_admin_data_access(self):
|
|
"""Test accessing admin data with and without auth"""
|
|
# Without auth
|
|
response = self.app.get('/api/admin/data')
|
|
self.assertEqual(response.status_code, 401)
|
|
|
|
# With auth
|
|
response = self.app.get('/api/admin/data', headers={'X-Admin-Password': ADMIN_PASSWORD})
|
|
self.assertEqual(response.status_code, 200)
|
|
data = json.loads(response.data)
|
|
self.assertIn('Multiplier', data[0])
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|