def get_profiles_test(self): self.ds_handler = ch.DataStreamHandler(self.ds_filepath) profile_ids = self.ds_handler.get_profiles(self.ds_ids, self.chk_first_id) # When Benchmark doesn't contain Rules selected by default # the default Profile should not be present self.assertEqual(2, len(profile_ids)) self.assertEqual(self.profile1_id, profile_ids[0].id) self.assertEqual(self.profile2_id, profile_ids[1].id)
def get_profiles_with_default(self): self.ds_handler = ch.DataStreamHandler(self.ds_filepath) profile_ids = self.ds_handler.get_profiles(self.ds_ids, self.chk_second_id) # When Benchmark contains Rules selected by default # the default Profile should be present self.assertEqual(2, len(profile_ids)) self.assertEqual("default", profile_ids[0].id) self.assertEqual(self.profile3_id, profile_ids[1].id)
def get_checklists_test(self): expected_checklists = [self.chk_first_id, self.chk_second_id] self.ds_handler = ch.DataStreamHandler(self.ds_filepath) chk_ids = self.ds_handler.get_checklists(self.ds_ids) self.assertListEqual(expected_checklists, chk_ids)
def get_checklists_invalid_test(self): self.ds_handler = ch.DataStreamHandler(self.ds_filepath) with self.assertRaises(ch.DataStreamHandlingError) as e: chk_ids = self.ds_handler.get_checklists("invalid.id") self.assertIn("Invalid data stream id given", e.exception.message)
def get_data_streams_test(self): self.ds_handler = ch.DataStreamHandler(self.ds_filepath) ds_ids = self.ds_handler.get_data_streams() self.assertIn(self.ds_ids, ds_ids)
def get_data_streams_checklists_test(self): expected_ids = {self.ds_ids: [self.chk_first_id, self.chk_second_id]} self.ds_handler = ch.DataStreamHandler(self.ds_filepath) ds_ids = self.ds_handler.get_data_streams_checklists() self.assertDictEqual(expected_ids, ds_ids)
def init_not_scap_content_test(self): with self.assertRaises(ch.DataStreamHandlingError) as e: ch.DataStreamHandler("../testing_files/testing_ks.cfg") self.assertIn("not a valid SCAP content file", e.exception.message)
def init_xccdf_content_test(self): with self.assertRaises(ch.DataStreamHandlingError) as e: ch.DataStreamHandler("../testing_files/xccdf.xml") self.assertIn("not a data stream collection", e.exception.message)
def init_invalid_file_path_test(self): with self.assertRaises(ch.DataStreamHandlingError) as e: ch.DataStreamHandler("testing_ds.xml") self.assertIn("Invalid file path", e.exception.message)
def test_init_xccdf_content(): with pytest.raises(ch.DataStreamHandlingError) as excinfo: ch.DataStreamHandler(os.path.join(TESTING_FILES_PATH, "xccdf.xml")) assert "not a data stream collection" in str(excinfo.value)
def test_init_not_scap_content(): with pytest.raises(ch.DataStreamHandlingError) as excinfo: ch.DataStreamHandler(os.path.join(TESTING_FILES_PATH, "testing_ks.cfg")) assert "not a valid SCAP content file" in str(excinfo.value)
def test_init_invalid_file_path(): with pytest.raises(ch.DataStreamHandlingError) as excinfo: ch.DataStreamHandler("testing_ds.xmlll") assert "Invalid file path" in str(excinfo.value)
def ds_handler(): return ch.DataStreamHandler(DS_FILEPATH)