@@ -640,7 +640,6 @@ def test_create_calendar_schedule(schedule_internal_api_setup, make_user_auth_he
640
640
"type" : 0 ,
641
641
"name" : "created_calendar_schedule" ,
642
642
"time_zone" : "UTC" ,
643
- "slack_channel_id" : None ,
644
643
"user_group" : None ,
645
644
"team" : None ,
646
645
"warnings" : [],
@@ -671,7 +670,6 @@ def test_create_ical_schedule(schedule_internal_api_setup, make_user_auth_header
671
670
"ical_url_overrides" : None ,
672
671
"name" : "created_ical_schedule" ,
673
672
"type" : 1 ,
674
- "slack_channel_id" : None ,
675
673
"user_group" : None ,
676
674
"team" : None ,
677
675
"warnings" : [],
@@ -706,7 +704,6 @@ def test_create_web_schedule(schedule_internal_api_setup, make_user_auth_headers
706
704
"name" : "created_web_schedule" ,
707
705
"type" : 2 ,
708
706
"time_zone" : "UTC" ,
709
- "slack_channel_id" : None ,
710
707
"user_group" : None ,
711
708
"team" : None ,
712
709
"warnings" : [],
@@ -2459,6 +2456,90 @@ def test_team_not_updated_if_not_in_data(
2459
2456
assert schedule .team == team
2460
2457
2461
2458
2459
+ # we don't need to validate the ical URL when creating an ical schedule.. so just patch that functionality
2460
+ @patch ("apps.api.serializers.schedule_ical.ScheduleICalSerializer.validate_ical_url_primary" , return_value = ICAL_URL )
2461
+ @pytest .mark .parametrize (
2462
+ "schedule_type,other_create_data" ,
2463
+ [
2464
+ (0 , {}),
2465
+ (1 , {"ical_url_primary" : ICAL_URL }),
2466
+ (2 , {}),
2467
+ ],
2468
+ )
2469
+ @pytest .mark .django_db
2470
+ def test_can_update_slack_channel (
2471
+ _mock_validate_ical_url_primary ,
2472
+ make_organization_and_user_with_plugin_token ,
2473
+ make_slack_team_identity ,
2474
+ make_slack_channel ,
2475
+ make_user_auth_headers ,
2476
+ schedule_type ,
2477
+ other_create_data ,
2478
+ ):
2479
+ organization , user , token = make_organization_and_user_with_plugin_token ()
2480
+ auth_headers = make_user_auth_headers (user , token )
2481
+ slack_team_identity = make_slack_team_identity ()
2482
+ organization .slack_team_identity = slack_team_identity
2483
+ organization .save ()
2484
+
2485
+ slack_channel1 = make_slack_channel (slack_team_identity )
2486
+ slack_channel2 = make_slack_channel (slack_team_identity )
2487
+
2488
+ client = APIClient ()
2489
+
2490
+ # we can set it when creating
2491
+ response = client .post (
2492
+ reverse ("api-internal:schedule-list" ),
2493
+ {
2494
+ "name" : "created_schedule" ,
2495
+ "type" : schedule_type ,
2496
+ "slack_channel_id" : slack_channel1 .public_primary_key ,
2497
+ ** other_create_data ,
2498
+ },
2499
+ format = "json" ,
2500
+ ** auth_headers ,
2501
+ )
2502
+
2503
+ assert response .status_code == status .HTTP_201_CREATED
2504
+
2505
+ response_data = response .json ()
2506
+ schedule_id = response_data ["id" ]
2507
+ url = reverse ("api-internal:schedule-detail" , kwargs = {"pk" : schedule_id })
2508
+
2509
+ # NOTE: the response returned by the POST/PUT endpoint currently doesn't include slack_channel_id
2510
+ # as it's not used by the UI.. additionally, there was already a bug in it that despite specifying it, it
2511
+ # would return null.. the proper way to refactor this is to change the name of slack_channel_id used in the
2512
+ # request (as this clashes with the slack_channel_id db column)
2513
+ def _assert_slack_channel_updated (new_slack_channel ):
2514
+ response = client .get (url , ** auth_headers )
2515
+
2516
+ assert response .status_code == status .HTTP_200_OK
2517
+ assert response .json ()["slack_channel" ] == new_slack_channel
2518
+
2519
+ # we can update it
2520
+ response = client .patch (
2521
+ url ,
2522
+ data = {
2523
+ "slack_channel_id" : slack_channel2 .public_primary_key ,
2524
+ },
2525
+ format = "json" ,
2526
+ ** auth_headers ,
2527
+ )
2528
+ assert response .status_code == status .HTTP_200_OK
2529
+ _assert_slack_channel_updated (
2530
+ {
2531
+ "id" : slack_channel2 .public_primary_key ,
2532
+ "display_name" : slack_channel2 .name ,
2533
+ "slack_id" : slack_channel2 .slack_id ,
2534
+ }
2535
+ )
2536
+
2537
+ # we can unset it
2538
+ response = client .patch (url , data = {"slack_channel_id" : None }, format = "json" , ** auth_headers )
2539
+ assert response .status_code == status .HTTP_200_OK
2540
+ _assert_slack_channel_updated (None )
2541
+
2542
+
2462
2543
@patch .object (SlackUserGroup , "can_be_updated" , new_callable = PropertyMock )
2463
2544
@pytest .mark .django_db
2464
2545
def test_can_update_user_groups (
0 commit comments