From e2d24a5e797a6f34c8d41aeb03608a853b5a2b64 Mon Sep 17 00:00:00 2001 From: Isabella Applen Date: Thu, 28 Mar 2019 16:37:07 -0700 Subject: [PATCH 1/2] adding test --- .../main_test.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 delete_multiple_resource_types_with_csv/main_test.py diff --git a/delete_multiple_resource_types_with_csv/main_test.py b/delete_multiple_resource_types_with_csv/main_test.py new file mode 100644 index 0000000..8398072 --- /dev/null +++ b/delete_multiple_resource_types_with_csv/main_test.py @@ -0,0 +1,61 @@ +import unittest +import requests +import sys +import csv +from unittest.mock import patch +sys.path.append('..') +import delete_features_with_csv + +class test_stuff(): + def __init__(self): + self.subdomain = "test_subdomain" + +class DeleteResourceTest(unittest.TestCase): + + def setUp(self): + delete_features_with_csv.options = { + 'subdomain': 'test_subdomain' + + } + + def test_construct_dictionary(self): + dictionary_should_be = { + "services": [ "P5G0L4E", "P26CKSR", "P9SOLH4"], + "escalation_policies":[ "P9M61GH", "P0REPRD", "PZ4YTZJ", "P7AQQGT"], + "schedules":[ "PZLRDOC", "PSCFBJM", "P0CTUZ1", "PWP3CZP"], + "teams":[ "P8O2THQ", "PDHGVLE"], + "users":[ "PW3C4JE", "POI33V1"] + } + + + + def test_get_name(self): + resource = "escalation_policies" + # the schema of an esclation policy is much longer than this, but this will do for testing purposes + subscript = { + "escalation_policy":{"id":"PAEILY8","type":"escalation_policy", + "summary":"SN:CAB Approval","self":"https://api.pagerduty.com/escalation_policies/PAEILY8", + "html_url":"https://pdt-isabella.pagerduty.com/escalation_policies/PAEILY8","name":"SN:CAB Approval", + } + } + + self.assertEqual(delete_features_with_csv.get_name(resource, subscript), "SN:CAB Approval") + + def test_make_plural(self): + self.assertEqual(delete_features_with_csv.make_plural("escalation_policy"), "escalation_policies") + self.assertEqual(delete_features_with_csv.make_plural("service"), "services") + + + + + def test_delete_resources_and_dependencies(self): + delete_features_with_csv.options.update({ + 'delete_dependencies': True + }) + + + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 9e3b7bf0bcab324200c57b68d5b1314d5f0ec62b Mon Sep 17 00:00:00 2001 From: Isabella Applen Date: Fri, 13 Aug 2021 16:14:09 -0700 Subject: [PATCH 2/2] made it so the request_body includes country_code by default; it was previously set on the condition that the contact method type was phone or sms, however, the include method was throwing an error and this extra condition seemed redundant. Also fixed how the script defaults to observer for team role --- import_users/import_users.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/import_users/import_users.rb b/import_users/import_users.rb index 9c20af7..6c8f464 100755 --- a/import_users/import_users.rb +++ b/import_users/import_users.rb @@ -97,11 +97,12 @@ def add_contact(user_id, type, address, country_code, label) :contact_method => { :type => type, :address => address, + :country_code => country_code, :label => label } } - request_body[:contact_method][:country_code] = country_code if ["sms_contact_method", "phone_contact_method"].include?(type) - post("/users/#{user_id}/contact_methods", request_body) + #request_body[:contact_method][:country_code] = country_code if ["sms_contact_method", "phone_contact_method"].include?(type) + #post("/users/#{user_id}/contact_methods", request_body) end def add_notification_rule(user_id, contact_method_id, contact_method_type, delay_in_minutes) @@ -268,8 +269,8 @@ def team_roles(record,team_index) #role must be one of the following manager,observer,responder in the csv file as per our API user_role = record.role - #return observer as fixed role if base role is one of the ready_only - return 'observer' if user_role.include?('read_only') + #return observer as fixed role if base role is observer or stakeholder + return 'observer' if user_role == 'read_only_limited_user' || user_role == 'restricted_access' || user_role == 'read_only_user' default_role = DEFAULT_TEAM_ROLES["#{user_role}".to_sym]