Skip to content

Commit

Permalink
include verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
almenscorner committed Feb 15, 2024
1 parent 9e821fb commit dd02aaa
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/IntuneCD/run_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,15 @@ def start():
help="The scopes to use when obtaining an access token interactively separated by space. Only used when using interactive auth. Default is: DeviceManagementApps.ReadWrite.All, DeviceManagementConfiguration.ReadWrite.All, DeviceManagementManagedDevices.Read.All, DeviceManagementServiceConfig.ReadWrite.All, DeviceManagementRBAC.ReadWrite.All, Group.Read.All, Policy.ReadWrite.ConditionalAccess, Policy.Read.All",
nargs="+",
)
parser.add_argument(
"-v", "--verbose", help="Prints verbose output", action="store_true"
)

args = parser.parse_args()

if args.verbose:
os.environ["VERBOSE"] = "True"

def devtoprod():
return "devtoprod"

Expand Down Expand Up @@ -302,6 +308,9 @@ def run_backup(path, output, exclude, token, prefix, append_id):
else:
print("Please enter a valid output format, json or yaml")

if "VERBOSE" in os.environ:
del os.environ["VERBOSE"]


if __name__ == "__main__":
start()
9 changes: 9 additions & 0 deletions src/IntuneCD/run_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@ def start():
help="The scopes to use when obtaining an access token interactively separated by space. Only used when using interactive auth. Default is: DeviceManagementApps.ReadWrite.All, DeviceManagementConfiguration.ReadWrite.All, DeviceManagementManagedDevices.Read.All, DeviceManagementServiceConfig.ReadWrite.All, DeviceManagementRBAC.ReadWrite.All, Group.Read.All, Policy.ReadWrite.ConditionalAccess, Policy.Read.All",
nargs="+",
)
parser.add_argument(
"-v", "--verbose", help="Prints verbose output", action="store_true"
)

args = parser.parse_args()

if args.verbose:
os.environ["VERBOSE"] = "True"

def devtoprod():
return "devtoprod"

Expand Down Expand Up @@ -309,6 +315,9 @@ def run_update(path, token, assignment, exclude, report, create_groups, remove):
args.remove,
)

if "VERBOSE" in os.environ:
del os.environ["VERBOSE"]


if __name__ == "__main__":
start()
51 changes: 50 additions & 1 deletion tests/test_graph_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This module tests the graph_batch module.
"""

import os
import unittest
from unittest.mock import patch

Expand All @@ -22,6 +23,7 @@ class TestGraphBatch(unittest.TestCase):

def setUp(self):
self.token = "token"
os.environ["VERBOSE"] = "True"
self.batch_request_data = ["1", "2", "3"]
self.batch_assignment_data = {"value": [{"id": "0"}]}
self.batch_intents_data = {
Expand Down Expand Up @@ -119,6 +121,7 @@ def tearDown(self):
self.batch_intents.stop()
self.batch_assignment.stop()
self.batch_request.stop()
del os.environ["VERBOSE"]

def test_batch_request(self):
"""The batch request function should return the expected result."""
Expand Down Expand Up @@ -162,7 +165,53 @@ def test_batch_request_429(self):
{
"id": "2",
"status": 200,
"headers": {"Retry-After": 1},
"headers": {},
"body": {
"odata.count": 1,
"value": [{"id": "1", "displayName": "test"}],
},
},
]
},
{
"responses": [
{
"id": "1",
"status": 200,
"headers": {},
"body": {
"odata.count": 1,
"value": [{"id": "0", "displayName": "test"}],
},
}
]
},
)
self.result = batch_request(self.batch_request_data, "test", "test", self.token)

self.assertEqual(self.makeapirequestPost.call_count, 2)
self.assertEqual(self.result, self.expected_result)

def test_batch_request_503(self):
"""The batch request function should return the expected result."""

self.expected_result = [
{"odata.count": 1, "value": [{"displayName": "test", "id": "1"}]},
{"odata.count": 1, "value": [{"displayName": "test", "id": "0"}]},
]
self.makeapirequestPost.side_effect = (
{
"responses": [
{
"id": "1",
"status": 503,
"headers": {},
"body": {},
},
{
"id": "2",
"status": 200,
"headers": {},
"body": {
"odata.count": 1,
"value": [{"id": "1", "displayName": "test"}],
Expand Down

0 comments on commit dd02aaa

Please sign in to comment.