Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing import users script; .include? method implementation throwing errors #56

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions delete_multiple_resource_types_with_csv/main_test.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 5 additions & 4 deletions import_users/import_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]

Expand Down