Skip to content

Commit

Permalink
added scripts to test juniper module
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgreen-moj committed Dec 1, 2023
1 parent 7982980 commit 317bd26
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/test_juniper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest
from unittest.mock import patch, MagicMock
from src.juniper import juniper_script, Admin

class TestJuniperScript(unittest.TestCase):

@patch('src.juniper.Admin.post')
@patch('src.juniper.Admin.put')
def test_juniper_script(self, mock_put, mock_post):
# Mock Mist API responses
mock_post.return_value = {'id': '123', 'name': 'TestSite'}
mock_put.return_value = {'status': 'success'}

# Sample input data
data = [
{'Site Name': 'TestSite', 'Site Address': '123 Main St',
'gps': [1.23, 4.56], 'country_code': 'US', 'time_zone': 'UTC',
'Enable GovWifi': 'true', 'Enable MoJWifi': 'false',
'Wired NACS Radius Key': 'key1', 'GovWifi Radius Key': 'key2'}
]

# Call the function
juniper_script(data, mist_api_token='your_token', org_id='your_org_id')

# Assertions
mock_post.assert_called_once_with('/api/v1/orgs/your_org_id/sites', {
'name': 'TestSite',
'address': '123 Main St',
'latlng': {'lat': 1.23, 'lng': 4.56},
'country_code': 'US',
'timezone': 'UTC'
})

mock_put.assert_called_once_with('/api/v1/sites/123/setting', {
'vars': {
'Enable GovWifi': 'true',
'Enable MoJWifi': 'false',
'Wired NACS Radius Key': 'key1',
'GovWifi Radius Key': 'key2'
}
})

def test_juniper_script_missing_token(self):
# Test when mist_api_token is missing
with self.assertRaises(SystemExit) as cm:
juniper_script([], org_id='your_org_id')

self.assertEqual(cm.exception.code, 1)

def test_juniper_script_missing_org_id(self):
# Test when org_id is missing
with self.assertRaises(SystemExit) as cm:
juniper_script([], mist_api_token='your_token')

self.assertEqual(cm.exception.code, 1)

0 comments on commit 317bd26

Please sign in to comment.