1-
21from unittest .mock import call , patch
32
43from django .core .management import call_command
54from django .test import TestCase
65
76
8- class MembershipOperationsCommandTests (TestCase ):
9- def test_command_runs_all_membership_jobs (self ) -> None :
7+ class OperationsDailyCommandTests (TestCase ):
8+ def test_command_runs_daily_jobs (self ) -> None :
109 with (
11- patch ("core.management.commands.membership_operations .call_command" ) as cc ,
12- self .assertLogs ("core.management.commands.membership_operations " , level = "INFO" ) as logs ,
10+ patch ("core.management.commands.operations_daily .call_command" ) as cc ,
11+ self .assertLogs ("core.management.commands.operations_daily " , level = "INFO" ) as logs ,
1312 ):
14- call_command ("membership_operations " )
13+ call_command ("operations_daily " )
1514
1615 self .assertEqual (
1716 cc .mock_calls ,
@@ -21,21 +20,20 @@ def test_command_runs_all_membership_jobs(self) -> None:
2120 call ("freeipa_membership_reconcile" , report = True , dry_run = False ),
2221 call ("membership_pending_requests" , force = False , dry_run = False ),
2322 call ("membership_embargoed_members" , force = False , dry_run = False ),
24- call ("membership_mirror_validation" , force = False , dry_run = False ),
2523 call ("selfservice_lifecycle_cleanup" , dry_run = False ),
2624 call ("account_invitations_refresh" ),
2725 ],
2826 )
2927 self .assertTrue (
30- any ("membership_operations " in line for line in logs .output ),
31- f"Expected membership operations logs, got: { logs .output } " ,
28+ any ("operations_daily " in line for line in logs .output ),
29+ f"Expected daily operations logs, got: { logs .output } " ,
3230 )
3331
3432 def test_force_is_passed_through (self ) -> None :
3533 with patch (
36- "core.management.commands.membership_operations .call_command" ,
34+ "core.management.commands.operations_daily .call_command" ,
3735 ) as cc :
38- call_command ("membership_operations " , "--force" )
36+ call_command ("operations_daily " , "--force" )
3937
4038 self .assertEqual (
4139 cc .mock_calls ,
@@ -45,17 +43,16 @@ def test_force_is_passed_through(self) -> None:
4543 call ("freeipa_membership_reconcile" , report = True , dry_run = False ),
4644 call ("membership_pending_requests" , force = True , dry_run = False ),
4745 call ("membership_embargoed_members" , force = True , dry_run = False ),
48- call ("membership_mirror_validation" , force = True , dry_run = False ),
4946 call ("selfservice_lifecycle_cleanup" , dry_run = False ),
5047 call ("account_invitations_refresh" ),
5148 ],
5249 )
5350
5451 def test_dry_run_is_passed_through (self ) -> None :
5552 with patch (
56- "core.management.commands.membership_operations .call_command" ,
53+ "core.management.commands.operations_daily .call_command" ,
5754 ) as cc :
58- call_command ("membership_operations " , "--dry-run" )
55+ call_command ("operations_daily " , "--dry-run" )
5956
6057 self .assertEqual (
6158 cc .mock_calls ,
@@ -65,8 +62,53 @@ def test_dry_run_is_passed_through(self) -> None:
6562 call ("freeipa_membership_reconcile" , report = True , dry_run = True ),
6663 call ("membership_pending_requests" , force = False , dry_run = True ),
6764 call ("membership_embargoed_members" , force = False , dry_run = True ),
68- call ("membership_mirror_validation" , force = False , dry_run = True ),
6965 call ("selfservice_lifecycle_cleanup" , dry_run = True ),
7066 call ("account_invitations_refresh" ),
7167 ],
7268 )
69+
70+
71+ class OperationsHourlyCommandTests (TestCase ):
72+ def test_command_runs_hourly_jobs (self ) -> None :
73+ with (
74+ patch ("core.management.commands.operations_hourly.call_command" ) as cc ,
75+ self .assertLogs ("core.management.commands.operations_hourly" , level = "INFO" ) as logs ,
76+ ):
77+ call_command ("operations_hourly" )
78+
79+ self .assertEqual (
80+ cc .mock_calls ,
81+ [
82+ call ("membership_mirror_validation" , force = False , dry_run = False ),
83+ ],
84+ )
85+ self .assertTrue (
86+ any ("operations_hourly" in line for line in logs .output ),
87+ f"Expected hourly operations logs, got: { logs .output } " ,
88+ )
89+
90+ def test_force_is_passed_through (self ) -> None :
91+ with patch (
92+ "core.management.commands.operations_hourly.call_command" ,
93+ ) as cc :
94+ call_command ("operations_hourly" , "--force" )
95+
96+ self .assertEqual (
97+ cc .mock_calls ,
98+ [
99+ call ("membership_mirror_validation" , force = True , dry_run = False ),
100+ ],
101+ )
102+
103+ def test_dry_run_is_passed_through (self ) -> None :
104+ with patch (
105+ "core.management.commands.operations_hourly.call_command" ,
106+ ) as cc :
107+ call_command ("operations_hourly" , "--dry-run" )
108+
109+ self .assertEqual (
110+ cc .mock_calls ,
111+ [
112+ call ("membership_mirror_validation" , force = False , dry_run = True ),
113+ ],
114+ )
0 commit comments