2222
2323
2424@pytest .mark .smoke
25- class TestCSC (testlib .SDKTestCase ):
26- def test_eventing_app (self ):
27- app_name = "eventing_app"
25+ class TestEventingApp (testlib .SDKTestCase ):
26+ app_name = "eventing_app"
2827
28+ def test_metadata (self ):
2929 self .assertTrue (
30- app_name in self .service .apps , msg = "%s is not installed." % app_name
30+ TestEventingApp .app_name in self .service .apps ,
31+ msg = f"{ TestEventingApp .app_name } is not installed." ,
3132 )
3233
3334 # Fetch the app
34- app = self .service .apps [app_name ]
35+ app = self .service .apps [TestEventingApp . app_name ]
3536 app .refresh ()
3637
3738 # Extract app info
@@ -40,6 +41,8 @@ def test_eventing_app(self):
4041 state = app .state
4142
4243 # App info assertions
44+ self .assertEqual (state .title , TestEventingApp .app_name )
45+
4346 self .assertEqual (access .app , "system" )
4447 self .assertEqual (access .can_change_perms , "1" )
4548 self .assertEqual (access .can_list , "1" )
@@ -61,30 +64,51 @@ def test_eventing_app(self):
6164 self .assertEqual (content .version , "1.0.0" )
6265 self .assertEqual (content .visible , "1" )
6366
64- self .assertEqual (state .title , "eventing_app" )
65-
66- jobs = self .service .jobs
67- stream = jobs .oneshot (
68- 'search index="_internal" | head 4000 | eventingcsc status=200 | head 10' ,
69- output_mode = "json" ,
67+ def test_behavior (self ):
68+ makeresults_count = 20
69+ expected_results_count = 10
70+ expected_status = "200"
71+
72+ search_query = f"""
73+ | makeresults count={ makeresults_count }
74+ | streamstats count as row_num
75+ | eval status=case(
76+ (row_num % 2) == 1, 200,
77+ 1=1, 500
7078 )
71- result = results .JSONResultsReader (stream )
72- ds = list (result )
79+ | eventingcsc status={ expected_status }
80+ """
81+ stream = self .service .jobs .oneshot (search_query , output_mode = "json" )
82+
83+ results_reader = results .JSONResultsReader (stream )
84+ items = list (results_reader )
7385
74- self .assertEqual (result .is_preview , False )
75- self .assertTrue (isinstance (ds [0 ], (dict , results .Message )))
76- nonmessages = [d for d in ds if isinstance (d , dict )]
77- self .assertTrue (len (nonmessages ) <= 10 )
86+ self .assertFalse (results_reader .is_preview )
7887
79- def test_generating_app (self ):
80- app_name = "generating_app"
88+ # filter out informational messages and keep only search results
89+ actual_results = [
90+ item for item in items if not isinstance (item , results .Message )
91+ ]
8192
93+ self .assertTrue (len (actual_results ) == expected_results_count )
94+
95+ for res in actual_results :
96+ self .assertIn ("status" , res )
97+ self .assertEqual (res ["status" ], expected_status )
98+
99+
100+ @pytest .mark .smoke
101+ class TestGeneratingApp (testlib .SDKTestCase ):
102+ app_name = "generating_app"
103+
104+ def test_metadata (self ):
82105 self .assertTrue (
83- app_name in self .service .apps , msg = "%s is not installed." % app_name
106+ TestGeneratingApp .app_name in self .service .apps ,
107+ msg = f"{ TestGeneratingApp .app_name } is not installed." ,
84108 )
85109
86110 # Fetch the app
87- app = self .service .apps [app_name ]
111+ app = self .service .apps [TestGeneratingApp . app_name ]
88112 app .refresh ()
89113
90114 # Extract app info
@@ -93,6 +117,8 @@ def test_generating_app(self):
93117 state = app .state
94118
95119 # App info assertions
120+ self .assertEqual (state .title , TestGeneratingApp .app_name )
121+
96122 self .assertEqual (access .app , "system" )
97123 self .assertEqual (access .can_change_perms , "1" )
98124 self .assertEqual (access .can_list , "1" )
@@ -116,23 +142,27 @@ def test_generating_app(self):
116142 self .assertEqual (content .version , "1.0.0" )
117143 self .assertEqual (content .visible , "1" )
118144
119- self . assertEqual ( state . title , "generating_app" )
120-
121- jobs = self . service . jobs
122- stream = jobs . oneshot ( "| generatingcsc count=4" , output_mode = "json" )
145+ def test_behavior ( self ):
146+ stream = self . service . jobs . oneshot (
147+ "| generatingcsc count=4" , output_mode = "json"
148+ )
123149 result = results .JSONResultsReader (stream )
124150 ds = list (result )
125151 self .assertTrue (len (ds ) == 4 )
126152
127- def test_reporting_app (self ):
128- app_name = "reporting_app"
129153
154+ @pytest .mark .smoke
155+ class TestReportingApp (testlib .SDKTestCase ):
156+ app_name = "reporting_app"
157+
158+ def test_metadata (self ):
130159 self .assertTrue (
131- app_name in self .service .apps , msg = "%s is not installed." % app_name
160+ TestReportingApp .app_name in self .service .apps ,
161+ msg = f"{ TestReportingApp .app_name } is not installed." ,
132162 )
133163
134164 # Fetch the app
135- app = self .service .apps [app_name ]
165+ app = self .service .apps [TestReportingApp . app_name ]
136166 app .refresh ()
137167
138168 # Extract app info
@@ -141,6 +171,8 @@ def test_reporting_app(self):
141171 state = app .state
142172
143173 # App info assertions
174+ self .assertEqual (state .title , TestReportingApp .app_name )
175+
144176 self .assertEqual (access .app , "system" )
145177 self .assertEqual (access .can_change_perms , "1" )
146178 self .assertEqual (access .can_list , "1" )
@@ -164,11 +196,9 @@ def test_reporting_app(self):
164196 self .assertEqual (content .version , "1.0.0" )
165197 self .assertEqual (content .visible , "1" )
166198
167- self .assertEqual (state .title , "reporting_app" )
168-
199+ def test_behavior_all_entries_above_cutoff (self ):
169200 jobs = self .service .jobs
170201
171- # All above 150
172202 stream = jobs .oneshot (
173203 "| makeresults count=10 | eval math=100, eng=100, cs=100 | reportingcsc cutoff=150 math eng cs" ,
174204 output_mode = "json" ,
@@ -183,8 +213,8 @@ def test_reporting_app(self):
183213 no_of_students = int (list (ds [0 ].values ())[0 ])
184214 self .assertTrue (no_of_students == 10 )
185215
186- # All below 150
187- stream = jobs .oneshot (
216+ def test_behavior_all_entries_below_cutoff ( self ):
217+ stream = self . service . jobs .oneshot (
188218 "| makeresults count=10 | eval math=45, eng=45, cs=45 | reportingcsc cutoff=150 math eng cs" ,
189219 output_mode = "json" ,
190220 )
@@ -198,15 +228,19 @@ def test_reporting_app(self):
198228 no_of_students = int (list (ds [0 ].values ())[0 ])
199229 self .assertTrue (no_of_students == 0 )
200230
201- def test_streaming_app (self ):
202- app_name = "streaming_app"
203231
232+ @pytest .mark .smoke
233+ class TestStreamingApp (testlib .SDKTestCase ):
234+ app_name = "streaming_app"
235+
236+ def test_metadata (self ):
204237 self .assertTrue (
205- app_name in self .service .apps , msg = "%s is not installed." % app_name
238+ TestStreamingApp .app_name in self .service .apps ,
239+ msg = f"{ TestStreamingApp .app_name } is not installed." ,
206240 )
207241
208242 # Fetch the app
209- app = self .service .apps [app_name ]
243+ app = self .service .apps [TestStreamingApp . app_name ]
210244 app .refresh ()
211245
212246 # Extract app info
@@ -215,6 +249,8 @@ def test_streaming_app(self):
215249 state = app .state
216250
217251 # App info assertions
252+ self .assertEqual (state .title , TestStreamingApp .app_name )
253+
218254 self .assertEqual (access .app , "system" )
219255 self .assertEqual (access .can_change_perms , "1" )
220256 self .assertEqual (access .can_list , "1" )
@@ -238,11 +274,8 @@ def test_streaming_app(self):
238274 self .assertEqual (content .version , "1.0.0" )
239275 self .assertEqual (content .visible , "1" )
240276
241- self .assertEqual (state .title , "streaming_app" )
242-
243- jobs = self .service .jobs
244-
245- stream = jobs .oneshot (
277+ def test_behavior (self ):
278+ stream = self .service .jobs .oneshot (
246279 "| makeresults count=5 | eval celsius = 35 | streamingcsc" ,
247280 output_mode = "json" ,
248281 )
0 commit comments