Best Python code snippet using lisa_python
test_ingestion_config.py
Source:test_ingestion_config.py
1#!/usr/bin/env python32"""3This file includes test scenarios and test cases for code regarding ingestion.4Pytest is the preferred test framework.5"""6from code.test.utils.utils import (assert_object_in_yaml,7 assert_object_is_correct_type)8pytest_plugins = ["code.test.pytest_fixtures"]9configuration_objects = [('url', str),10 ('repo_url', str),11 ('sink', str),12 ('user', str),13 ('repo', str),14 ('batch_size', int),15 ('file_size', int),16 ('save_tree', bool),17 ('use_cached', bool),18 ('file_path', str),19 ('download_method', str),20 ('use_api', bool)]21task = 'ingest'22def test_configuration_contains_ingestion(get_configuration) -> None:23 """24 Tests whether the configuration contains an entry for task 1.25 :param get_configuration: The configuration yaml file.26 :return: None27 """28 assert get_configuration.ingestion is not None, "'task1 is not in configuration file"29 for object_name, type_def in configuration_objects:30 assert_object_in_yaml(object_name, get_configuration.ingestion, "ingest")31 assert_object_is_correct_type(object_name, get_configuration.ingestion, type_def)32def test_configuration_fails_on_wrong_object_name(get_configuration) -> None:33 """34 Tests whether the configuration contains an entry for task 1.35 :param get_configuration: The configuration yaml file.36 :return: None37 """38 assert get_configuration.ingestion is not None, "'task1 is not in configuration file"39 configuration_objects.append(("not_an_object", str))40 try:41 for object_name, type_def in configuration_objects:42 assert_object_in_yaml(object_name, get_configuration.ingestion, "ingest")43 assert_object_is_correct_type(object_name, get_configuration.ingestion, type_def)44 except AssertionError:45 return46 raise AssertionError("Test failed")47def test_configuration_fails_on_wrong_object_type(get_configuration) -> None:48 """49 Tests whether the configuration contains an entry for task 1.50 :param get_configuration: The configuration yaml file.51 :return: None52 """53 assert get_configuration.ingestion is not None, "'task1 is not in configuration file"54 configuration_objects[-1] = ("use_api", str)55 try:56 for object_name, type_def in configuration_objects:57 assert_object_in_yaml(object_name, get_configuration.ingestion, "ingest")58 assert_object_is_correct_type(object_name, get_configuration.ingestion, type_def)59 except AssertionError:60 return61 raise AssertionError("Test failed")62def test_batch_tree_contains_batches(get_cached_batch_tree) -> None:63 keys = list(get_cached_batch_tree.keys())64 batches = list(map(lambda x: x.split('_')[0], keys))65 numbers = list(map(lambda x: x.split('_')[1], keys))66 assert all(number.isdigit() for number in numbers)...
test_constants.py
Source:test_constants.py
...5 def setUp(self):6 self.constants = constants7 self.config = config8 def test_constants(self):9 self.assertEqual(self.constants.PUBLISH_OPTIONS, self.config.get_configuration('PUBLISH_OPTIONS'))10 self.assertEqual(self.constants.OBJAVI_URL, self.config.get_configuration('OBJAVI_URL'))11 self.assertEqual(self.constants.ESPRI_URL, self.config.get_configuration('ESPRI_URL'))12 self.assertNotEqual(self.constants.THIS_BOOKI_SERVER, self.config.get_configuration('THIS_BOOKI_SERVER'))13 self.assertEqual(self.constants.CREATE_BOOK_VISIBLE, self.config.get_configuration('CREATE_BOOK_VISIBLE'))14 self.assertEqual(self.constants.CREATE_BOOK_LICENSE, self.config.get_configuration('CREATE_BOOK_LICENSE'))15 self.assertEqual(self.constants.FREE_REGISTRATION, self.config.get_configuration('FREE_REGISTRATION'))16 self.assertEqual(self.constants.ADMIN_CREATE_BOOKS, self.config.get_configuration('ADMIN_CREATE_BOOKS'))17 self.assertEqual(self.constants.ADMIN_IMPORT_BOOKS, self.config.get_configuration('ADMIN_IMPORT_BOOKS'))18 self.assertEqual(self.constants.BOOKTYPE_MAX_USERS, self.config.get_configuration('BOOKTYPE_MAX_USERS'))19 self.assertEqual(self.constants.BOOKTYPE_MAX_BOOKS, self.config.get_configuration('BOOKTYPE_MAX_BOOKS'))20 self.assertEqual(self.constants.BOOKTYPE_CSS_BOOK, self.config.get_configuration('BOOKTYPE_CSS_BOOK'))21 self.assertEqual(self.constants.BOOKTYPE_CSS_BOOKJS, self.config.get_configuration('BOOKTYPE_CSS_BOOKJS'))22 self.assertEqual(self.constants.BOOKTYPE_CSS_EBOOK, self.config.get_configuration('BOOKTYPE_CSS_EBOOK'))23 self.assertEqual(self.constants.BOOKTYPE_CSS_PDF, self.config.get_configuration('BOOKTYPE_CSS_PDF'))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!