Skip to content

Commit

Permalink
Added support for RF_TEMPLATE_ID
Browse files Browse the repository at this point in the history
RF_TEMPLATE_ID will be different per org thus this needs to be defined
but the user running the script depending on what environment they
are using
  • Loading branch information
jamesgreen-moj committed Dec 12, 2023
1 parent baa859f commit 17d625a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
;ORG_ID=
;MIST_API_TOKEN=
;SITE_GROUP_IDS={"moj_wifi": "foo","gov_wifi": "bar"}
;RF_TEMPLATE_ID=
7 changes: 5 additions & 2 deletions src/juniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def juniper_script(
org_id=None,
mist_username=None,
mist_password=None,
site_group_ids=None
site_group_ids=None,
rf_template_id=None
):

# Configure True/False to enable/disable additional logging of the API response objects
Expand All @@ -108,6 +109,8 @@ def juniper_script(
raise ValueError('No authentication provided, provide mist username and password or API key')
if site_group_ids is None:
raise ValueError('Must provide site_group_ids for GovWifi & MoJWifi')
if rf_template_id is None:
raise ValueError('Must rf_template_id')

# Establish Mist session
admin = Admin(mist_api_token, mist_username, mist_password)
Expand All @@ -120,7 +123,7 @@ def juniper_script(
'address': d.get('Site Address', ''),
"latlng": {"lat": d.get('gps', '')[0], "lng": d.get('gps', '')[1]},
"country_code": d.get('country_code', ''),
"rftemplate_id": "8542a5fa-51e4-41be-83b9-acb416362cc0",
"rftemplate_id": rf_template_id,
"timezone": d.get('time_zone', ''),
"sitegroup_ids": check_if_we_need_to_append_gov_wifi_or_moj_wifi_site_groups(
gov_wifi=d.get('Enable GovWifi', ''),
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ def add_geocoding_to_json(data):
mist_password=os.environ.get('MIST_PASSWORD'),
site_group_ids=os.environ.get('SITE_GROUP_IDS'),
org_id=os.environ.get('ORG_ID'),
rf_template_id=os.environ.get('RF_TEMPLATE_ID'),
data=json_data_with_geocoding
)
17 changes: 15 additions & 2 deletions test/test_juniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def test_juniper_script(self, mock_put, mock_post, mock_successful_login):
data,
mist_api_token='your_token',
org_id='your_org_id',
site_group_ids='{"moj_wifi": "foo","gov_wifi": "bar"}'
site_group_ids='{"moj_wifi": "foo","gov_wifi": "bar"}',
rf_template_id='8542a5fa-51e4-41be-83b9-acb416362cc0'
)

# Assertions
Expand All @@ -50,12 +51,24 @@ def test_juniper_script(self, mock_put, mock_post, mock_successful_login):
})

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

self.assertEqual(str(cm.exception), 'Must provide site_group_ids for GovWifi & MoJWifi')

def test_juniper_script_missing_rf_template_id(self):
# Test when rf_template_id is missing
with self.assertRaises(ValueError) as cm:
juniper_script([],
org_id='your_org_id',
mist_api_token='token',
site_group_ids = {
'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904',
'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'
})

self.assertEqual(str(cm.exception), 'Must rf_template_id')

def test_juniper_script_missing_api_token(self):
# Test when mist_api_token is missing
with self.assertRaises(ValueError) as cm:
Expand Down

0 comments on commit 17d625a

Please sign in to comment.