def test_del(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') dty1 = db.add_device_type(dty_id='x10.switch', dty_name='x10 Switch', dty_description='desc1', dt_id=dt1.id) du1 = db.add_device_usage('du1_id', 'du1') du2 = db.add_device_usage('du2_id', 'du2') device1 = db.add_device(d_name='device1', d_address='A1', d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1') device2 = db.add_device(d_name='device2', d_address='A2', d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1') db.add_device_stat(make_ts(2010, 04, 9, 12, 0), 'val2', 1, device2.id) db.add_device_stat(make_ts(2010, 04, 9, 12, 1), 'val1', 2, device2.id) assert len(db.list_device_stats(device2.id)) == 2 device3 = db.add_device(d_name='device3', d_address='A3', d_type_id=dty1.id, d_usage_id=du1.id) device_del = device2 device2_id = device2.id db.del_device(device2.id) # Check cascade deletion assert len(db.list_device_stats(device2.id)) == 0 assert len(db.list_devices()) == 2 for dev in db.list_devices(): assert dev.address in ('A1', 'A3') assert device_del.id == device2.id try: db.del_device(12345678910) TestCase.fail(self, "Device does not exist, an exception should have been raised") except DbHelperException: pass
def run_and_compare_output(name: str, test_case: unittest.TestCase) -> None: """ Converts the onnx-model to dml, runs systemds with the dml-wrapper and compares the resulting output with the reference output. :param name: The name of the test-case (also used for finding onnx-model, dml-wrapper and reference output) :param test_case: The testcase """ try: onnx2systemds("tests/onnx_systemds/test_models/" + name + ".onnx", "tests/onnx_systemds/dml_output/" + name + ".dml") ret = invoke_systemds("tests/onnx_systemds/dml_wrapper/" + name + "_wrapper.dml") test_case.assertEqual(ret, 0, "systemds failed") # We read the file content such that pytest can present the actual difference between the files with open("tests/onnx_systemds/output_reference/" + name + "_reference.out") as reference_file: reference_content = reference_file.read() with open("tests/onnx_systemds/output_test/" + name + ".out") as output_file: test_content = output_file.read() test_case.assertEqual( test_content, reference_content, "generated output differed from reference output") except KeyError as e: if "SYSTEMDS_ROOT" in os.environ: test_case.fail("SYSTEMDS Key was set and the test failed anyway.")
def test_del(self): person1 = db.add_person(p_first_name='Marc', p_last_name='SCHNEIDER', p_birthdate=datetime.date(1973, 4, 24)) person2 = db.add_person(p_first_name='Monthy', p_last_name='PYTHON', p_birthdate=datetime.date(1981, 4, 24)) person3 = db.add_person(p_first_name='Alberto', p_last_name='MATE', p_birthdate=datetime.date(1947, 8, 6)) user1 = db.add_user_account(a_login='******', a_password='******', a_person_id=person1.id) user2 = db.add_user_account(a_login='******', a_password='******', a_person_id=person2.id) user3 = db.add_user_account(a_login='******', a_password='******', a_person_id=person3.id) user3_id = user3.id user_acc_del = db.del_user_account(user3.id) assert user_acc_del.id == user3_id assert len(db.list_persons()) == 3 l_user = db.list_user_accounts() assert len(l_user) == 2 for user in l_user: assert user.login != 'domo' person1_id = person1.id person_del = db.del_person(person1.id) assert person_del.id == person1_id assert len(db.list_persons()) == 2 assert len(db.list_user_accounts()) == 1 try: db.del_person(12345678910) TestCase.fail(self, "Person does not exist, an exception should have been raised") except DbHelperException: pass try: db.del_user_account(12345678910) TestCase.fail(self, "User account does not exist, an exception should have been raised") except DbHelperException: pass
def _check_actual_contents( self, put: unittest.TestCase, value: StringSourceContents, message_builder: asrt.MessageBuilder, ): # ARRANGE # expectation = self._expectation model_to_check__w_lines_check = StringSourceContentsThatThatChecksLines( put, value) for case in self._contents_getters_cases: case_msg_builder = message_builder.for_sub_component(case.name) # ACT & ASSERT # try: actual = case.value(model_to_check__w_lines_check) except HardErrorException as ex: if expectation.hard_error is None: err_msg = case_msg_builder.apply( 'Unexpected HARD_ERROR: ' + str(ex)) put.fail(err_msg) return else: expectation.hard_error.apply( put, ex.error, case_msg_builder.for_sub_component( 'HARD_ERROR message'), ) raise asrt.StopAssertion() if expectation.hard_error is not None: put.fail(case_msg_builder.apply('HARD_ERROR not raised')) else: expectation.contents.apply(put, actual, case_msg_builder)
def test_update(self): person = db.add_person(p_first_name='Marc', p_last_name='SCHNEIDER', p_birthdate=datetime.date(1973, 4, 24)) person_u = db.update_person(p_id=person.id, p_first_name='Marco', p_last_name='SCHNEIDERO', p_birthdate=datetime.date(1981, 4, 24)) assert str(person_u.birthdate) == str(datetime.date(1981, 4, 24)) assert person_u.last_name == 'SCHNEIDERO' assert person_u.first_name == 'Marco' user_acc = db.add_user_account(a_login='******', a_password='******', a_person_id=person_u.id, a_is_admin=True) assert not db.change_password(999999999, 'IwontGiveIt', 'foo') assert db.change_password(user_acc.id, 'IwontGiveIt', 'OkIWill') assert not db.change_password(user_acc.id, 'DontKnow', 'foo') user_acc_u = db.update_user_account(a_id=user_acc.id, a_new_login='******', a_is_admin=False) assert not user_acc_u.is_admin try: db.update_user_account(a_id=user_acc.id, a_person_id=999999999) TestCase.fail(self, "An exception should have been raised : person id does not exist") except DbHelperException: pass user_acc_u = db.update_user_account_with_person(a_id=user_acc.id, a_login='******', p_first_name='Bob', p_last_name='Marley', p_birthdate=datetime.date(1991, 4, 24), a_is_admin=True, a_skin_used='skins/crocodile') assert user_acc_u.login == 'mschneider3' assert user_acc_u.person.first_name == 'Bob' assert user_acc_u.person.last_name == 'Marley' assert str(user_acc_u.person.birthdate) == str(datetime.date(1991, 4, 24)) assert user_acc_u.is_admin assert user_acc_u.skin_used == 'skins/crocodile'
def test_status_raises_exception(self): try: self.presto_cli.status(self.mock_env) except Exception as e: self.assertEqual(repr(e), 'ClientComponentHasNoStatus()') return TestCase.fail(self)
def _do_freeze(self, put: unittest.TestCase, source: StringSource): try: source.freeze() except HardErrorException as ex: put.fail( self._message_builder.for_sub_component('freeze').apply( 'freeze raised HardErrorException: ' + str(ex)))
def call_module(test: unittest.TestCase, output_size: int, *args: str, filter_empty: bool = True) -> List[str]: """ :param output_size: The exact allowed number of items in the output result list. :param test: The context of the current test case. :param args: The parameters to pass to the imported module. :param filter_empty: Filter empty strings out of the output list. Defaults to 'True'. :return: The output of the imported module (print()). """ try: script_path = os.path.join(os.getcwd(), '..', 'task.py') output = check_output([sys.executable, script_path], input='\n'.join(args), universal_newlines=True) output_list = output.split("\n") if filter_empty: filtered_output_list = list(filter(lambda x: x != '', output_list)) else: filtered_output_list = output_list number_of_filtered_outputs = len(filtered_output_list) if number_of_filtered_outputs != output_size: test.fail( f'The number of outputs are not correct ({output_size} expected, but got {number_of_filtered_outputs}).' ) else: return filtered_output_list except CalledProcessError: test.fail('Could not execute the code, please fix any errors!')
def test_fill_with_bad_operator(self): try: self._obj.fill({'operator': "bad"}) except: pass else: TestCase.fail(self, "Operator 'bad' doesn't exist, exception should be raised")
def fail(self, msg = None): try: TestCase.fail(self, msg) except: self.kmod.stop() self.kmod.save_logs(self.destdir) raise
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder): try: self.assertion.apply(put, value, message_builder) except put.failureException: pass else: put.fail(message_builder.apply('NOT ' + self.assertion_name))
def run(self, put: unittest.TestCase, arguments: List[str]) -> SubProcessResult: if self._main_program_path is None: put.fail('Cannot find executable "%s" in path.' % self._executable_file_name_base) cmd_and_args = [self._main_program_path] + arguments stdin_contents = '' return run_subprocess(cmd_and_args, stdin_contents)
def wrapper(value, *args, **kw): if not hasattr(value, self.attributeNeeded): TestCase.fail( value, 'You MUST invoke %s first, BEFORE performing any validations!' % self.methodToInvoke) else: return method(value, *args, **kw)
def test_fill_with_bad_operator(self): try: self._obj.fill({'operator': "bad"}) except: pass else: TestCase.fail( self, "Operator 'bad' doesn't exist, exception should be raised")
def _apply(self, put: unittest.TestCase, value, message_builder: MessageBuilder): put.assertIsInstance(value, sh.SuccessOrHardError) if not value.is_success: from exactly_lib.util.simple_textstruct.file_printer_output import to_string put.fail('\n'.join([ 'Expected: success', 'Actual : hard_error: ' + to_string.major_blocks(value.failure_message.render_sequence()) ]))
def assert_file_contains(filename: str, search_string: str, test_case: unittest.TestCase): with open(filename, 'r') as file: current_line = "\n" while current_line: current_line = file.readline() if search_string in current_line: return test_case.fail(f"{search_string} not found in {filename}")
def _apply(self, put: unittest.TestCase, value: str, message_builder: asrt.MessageBuilder): reg_ex = re.compile(self._reg_ex) match = reg_ex.fullmatch(value) if match is None: put.fail( message_builder.apply('Do not match pattern [{}]: [{}]'.format( repr(self._reg_ex), value, )))
def _apply(self, put: unittest.TestCase, value, message_builder: asrt.MessageBuilder): if isinstance(value, CrossReferenceId): cross_reference_id_va.is_any.apply_with_message( put, value, str(CrossReferenceId)) elif isinstance(value, struct.SeeAlsoUrlInfo): is_see_also_url_info.apply_with_message(put, value, str(struct.SeeAlsoUrlInfo)) else: put.fail('Not a {}: {}'.format(SeeAlsoTarget, value))
def _apply(self, put: unittest.TestCase, value, message_builder: MessageBuilder): put.assertIsInstance(value, sh.SuccessOrHardError) if not value.is_success: put.fail('\n'.join([ 'Expected: success', 'Actual : hard_error: ' + str(value.failure_message) ]))
def _is_known_sub_class(self, put: unittest.TestCase, value: LineObject, message_builder: MessageBuilder): if isinstance(value, PreFormattedStringLineObject): return if isinstance(value, StringLineObject): return if isinstance(value, StringLinesObject): return msg = 'Not a know sub class of {}: {}'.format(LineObject, value) put.fail(message_builder.apply(msg))
def _apply(self, put: unittest.TestCase, value, message_builder: MessageBuilder): put.assertIsInstance(value, svh.SuccessOrValidationErrorOrHardError) if not value.is_success: put.fail('\n'.join([ 'Expected: ' + svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS.name, 'Actual : {st}: {msg}'.format( st=value.status.name, msg=repr(value.failure_message)) ]))
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder): try: self._method_that_should_raise(value) put.fail('HardErrorException not raised') except HardErrorException as ex: asrt_text_doc.is_any_text().apply( put, ex.error, message_builder.for_sub_component('error message'), ) raise asrt.StopAssertion()
def assert_files_not_equal(filename_a: str, filename_b: str, test_case: unittest.TestCase): with open(filename_a, 'r') as file_a, open(filename_b, 'r') as file_b: a_curr = "\n" b_curr = a_curr while a_curr and b_curr: a_curr = file_a.readline() b_curr = file_b.readline() if a_curr != b_curr: return test_case.fail( f"{filename_a} and {filename_b} have the same contents")
def test_update(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') dt2 = db.add_device_technology('plcbus', 'PLCBus', 'desc dt2') dty = db.add_device_type(dty_id='x10.switch', dty_name='Switch', dty_description='desc1', dt_id=dt1.id) try: db.update_device_type(dty_id=dty.id, dty_name='x10 Dimmer', dt_id=u'99999999999') TestCase.fail(self, "An exception should have been raised : device techno id does not exist") except DbHelperException: pass dty_u = db.update_device_type(dty_id=dty.id, dty_name='x10 Dimmer', dt_id=dt2.id, dty_description='desc2') assert dty_u.name == 'x10 Dimmer' assert dty_u.description == 'desc2' assert dty_u.device_technology_id == dt2.id
def test_del(self): du1 = db.add_device_usage(du_id='du1_id', du_name='du1') du2 = db.add_device_usage(du_id='du2_id', du_name='du2') du2_id = du2.id du_del = db.del_device_usage(du2.id) assert self.has_item(db.list_device_usages(), ['du1']) assert not self.has_item(db.list_device_usages(), ['du2']) assert du_del.id == du2_id try: db.del_device_usage(12345678910) TestCase.fail(self, "Device usage does not exist, an exception should have been raised") except DbHelperException: pass
def _apply(self, put: unittest.TestCase, value, message_builder: MessageBuilder): put.assertIsInstance(value, svh.SuccessOrValidationErrorOrHardError) if not value.is_success: put.fail('\n'.join([ 'Expected: ' + svh.SuccessOrValidationErrorOrHardErrorEnum.SUCCESS.name, 'Actual : {st}: {msg}'.format( st=value.status.name, msg=repr( render_to_str.print_major_blocks( value.failure_message.render_sequence()))) ]))
def compare_sensors_content(context: TestCase, gt_sensors: List[ManagerObjSensor], new_sensors: List[ManagerObjSensor]): """ Compares two lists of Sensor objects. :param context: :param gt_sensors: :param new_sensors: """ if len(new_sensors) != len(gt_sensors): context.fail("Wrong number of objects.") already_processed = [] for stored_sensor in new_sensors: found = False for gt_sensor in gt_sensors: if stored_sensor.nodeId == gt_sensor.nodeId and stored_sensor.sensorId == gt_sensor.sensorId: found = True # Check which objects we already processed to see if we hold an object with # duplicated values. if gt_sensor in already_processed: context.fail("Duplicated object.") already_processed.append(gt_sensor) # Only the content of the object should have changed, not the object itself. if stored_sensor == gt_sensor: context.fail( "Changed ground truth object, not content of existing object." ) if (stored_sensor.clientSensorId != gt_sensor.clientSensorId or stored_sensor.description != gt_sensor.description or stored_sensor.alertDelay != gt_sensor.alertDelay or stored_sensor.lastStateUpdated != gt_sensor.lastStateUpdated or stored_sensor.state != gt_sensor.state or stored_sensor.dataType != gt_sensor.dataType or stored_sensor.data != gt_sensor.data or any( map(lambda x: x not in gt_sensor.alertLevels, stored_sensor.alertLevels)) or any( map(lambda x: x not in stored_sensor.alertLevels, gt_sensor.alertLevels))): context.fail("New object does not have correct content.") break if not found: context.fail("Not able to find modified Sensor object.")
def test_del(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') dty1 = db.add_device_type(dty_id='x10.switch', dty_name='Switch', dt_id=dt1.id) dty2 = db.add_device_type(dty_id='x10.dimmer', dty_name='Dimmer', dt_id=dt1.id) dty2_id = dty2.id dty_del = db.del_device_type(dty2.id) assert self.has_item(db.list_device_types(), ['Switch']) assert not self.has_item(db.list_device_usages(), ['x10 Dimmer']) assert dty_del.id == dty2_id try: db.del_device_type(12345678910) TestCase.fail(self, "Device type does not exist, an exception should have been raised") except DbHelperException: pass
def _apply(self, put: unittest.TestCase, value, message_builder: MessageBuilder): put.assertIsInstance(value, ErrorDescription, message_builder.apply('object type')) assert isinstance(value, ErrorDescription) # Type info for IDE checker = _CheckAnyErrorDescription(put, message_builder) try: checker.visit(value) except TypeError: put.fail('Not a known sub class of {}: {}'.format( ErrorDescription, value))
def _apply(self, put: unittest.TestCase, value: T, message_builder: MessageBuilder): failures = [] for assertion in self.assertions: assert isinstance(assertion, ValueAssertion) try: assertion.apply(put, value, message_builder) return except put.failureException as ex: failures.append(' ' + str(ex)) put.fail(message_builder.apply('OR: ' + self.assertion_name) + ':' + os.linesep + os.linesep.join(failures))
def test_lot_not_present(setup): parking_store = setup lot = "abcdefghijklmnopqrstuvwxyz" try: parking_store.increase_spots(lot) parking_store.decrease_spots(lot) parking_store.get_capacity(lot) parking_store.get_spots(lot) parking_store.remove_lot(lot) except: TestCase.fail()
def _is_known_sub_class(put: unittest.TestCase, value: Detail, message_builder: MessageBuilder): if isinstance(value, StringDetail): return if isinstance(value, PreFormattedStringDetail): return if isinstance(value, HeaderAndValueDetail): return if isinstance(value, TreeDetail): return if isinstance(value, IndentedDetail): return msg = 'Not a know sub class of {}: {}'.format(Detail, value) put.fail(message_builder.for_sub_component('Detail class').apply(msg))
def compare_alert_levels_content(context: TestCase, gt_alert_levels: List[ManagerObjAlertLevel], new_alert_levels: List[ManagerObjAlertLevel]): """ Compares two lists of AlertLevel objects. :param context: :param gt_alert_levels: :param new_alert_levels: """ if len(new_alert_levels) != len(gt_alert_levels): context.fail("Wrong number of objects.") already_processed = [] for stored_alert_level in new_alert_levels: found = False for gt_alert_level in gt_alert_levels: if stored_alert_level.level == gt_alert_level.level: found = True # Check which objects we already processed to see if we hold an object with # duplicated values. if gt_alert_level in already_processed: context.fail("Duplicated object.") already_processed.append(gt_alert_level) # Only the content of the object should have changed, not the object itself. if stored_alert_level == gt_alert_level: context.fail( "Changed ground truth object, not content of existing object." ) if (stored_alert_level.name != gt_alert_level.name or any( map(lambda x: x not in gt_alert_level.profiles, stored_alert_level.profiles)) or any( map(lambda x: x not in stored_alert_level.profiles, gt_alert_level.profiles)) or stored_alert_level.instrumentation_active != gt_alert_level.instrumentation_active or stored_alert_level.instrumentation_cmd != gt_alert_level.instrumentation_cmd or stored_alert_level.instrumentation_timeout != gt_alert_level.instrumentation_timeout): context.fail("New object does not have correct content.") break if not found: context.fail("Not able to find modified Alert Level object.")
def _apply(self, put: unittest.TestCase, value, message_builder: asrt.MessageBuilder): if isinstance(value, CrossReferenceId): cross_reference_id_va.is_any.apply_with_message(put, value, str(CrossReferenceId)) elif isinstance(value, struct.SeeAlsoUrlInfo): is_see_also_url_info.apply_with_message(put, value, str(struct.SeeAlsoUrlInfo)) else: put.fail('Not a {}: {}'.format(SeeAlsoTarget, value ))
def test_add(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') try: db.add_device_type(dty_id='x10.switch', dty_name='Switch', dty_description='desc1', dt_id=u'99999999999') TestCase.fail(self, "An exception should have been raised : device techno id does not exist") except DbHelperException: pass dty1 = db.add_device_type(dty_id='x10.switch', dty_name='Switch', dty_description='desc1', dt_id=dt1.id) print(dty1) assert dty1.name == 'Switch' assert dty1.description == 'desc1' assert dty1.device_technology_id == dt1.id dty2 = db.add_device_type(dty_id='x10.dimmer', dty_name='Dimmer', dty_description='desc2', dt_id=dt1.id) assert len(db.list_device_types()) == 2 assert self.has_item(db.list_device_types(), ['Switch', 'Dimmer'])
def test_del(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') dt2 = db.add_device_technology('1wire', '1-Wire', 'desc dt2') dt_del = dt2 dt2_id = dt2.id dt3 = db.add_device_technology('plcbus', 'PLCBus', 'desc dt3') db.del_device_technology(dt2.id) assert self.has_item(db.list_device_technologies(), ['x10', 'PLCBus']) assert not self.has_item(db.list_device_technologies(), ['1-Wire']) assert dt_del.id == dt2_id try: db.del_device_technology(12345678910) TestCase.fail(self, "Device technology does not exist, an exception should have been raised") except DbHelperException: pass
def _set_timer(ctx: TestCase, desc: str, timeout: int): """ Internal function used to have timeout if we are in a blocking function. :param ctx: context of the test case :param desc: description of the timeout :param timeout: timeout in seconds """ for i in range(timeout): with Timer._running_timers_lock: if not Timer._running_timers[desc]: return time.sleep(1) ctx.fail("Timeout: %s" % desc)
def _check(put: unittest.TestCase, arrangement: Arrangement, expectation: Expectation): actual = sut.parse_from_parse_source(arrangement.grammar, arrangement.source) if expectation.expression != actual: put.fail('Unexpected expression.\nExpected: {}\nActual : {}'.format( str(expectation.expression), str(actual), )) put.assertEqual(expectation.expression, actual, 'parsed expression: ' + str(actual)) expectation.source.apply_with_message(put, arrangement.source, 'source after parse')
def test_add(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') du1 = db.add_device_usage('du1_id', 'du1') dty1 = db.add_device_type(dty_id='x10.switch', dty_name='Switch', dty_description='desc1', dt_id=dt1.id) try: db.add_device(d_name='device1', d_address = 'A1', d_type_id = u'9999999999', d_usage_id = du1.id) TestCase.fail(self, "Device type does not exist, an exception should have been raised") db.add_device(d_name='device1', d_address = 'A1', d_type_id = dty1.id, d_usage_id = u'9999999999999') TestCase.fail(self, "Device usage does not exist, an exception should have been raised") except DbHelperException: pass device1 = db.add_device(d_name='device1', d_address='A1', d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1') assert device1.name == 'device1' and device1.description == 'desc1' print(device1) assert len(db.list_devices()) == 1 device2 = db.add_device(d_name='device2', d_address='A2', d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1') assert len(db.list_devices()) == 2
def fail_if_test_case_does_not_pass(put: unittest.TestCase, root_file_path_argument: Path, tc_definition: TestCaseDefinitionForMainProgram, ): # SETUP # command_line_arguments = [ str(root_file_path_argument), ] # ACT & ASSERT # sub_process_result = run_main_program_and_collect_process_result( command_line_arguments, main_program_config(tc_definition) ) if sub_process_result.exitcode != 0: put.fail('Exit code is non zero. Error message: ' + sub_process_result.stderr)
def _check_stdout(self, put: unittest.TestCase, root_path: pathlib.Path, actual_result: SubProcessResult): expected_lines = self.expected_stdout_lines(root_path) if expected_lines is not None: actual_lines = self._translate_actual_stdout_before_assertion(actual_result.stdout).splitlines() line_number = 0 for expected_line, actual_line in zip(expected_lines, actual_lines): if isinstance(expected_line, str): put.assertEqual(expected_line, actual_line, 'Output of line ' + str(line_number)) else: match = expected_line.fullmatch(actual_line) if match is None: put.fail('Expecting match of "%s" (actual: "%s")' % (str(expected_line), actual_line)) put.assertEqual(len(expected_lines), len(actual_lines), 'Expecting ' + str(len(expected_lines)) + ' lines')
def test_add(self): person1 = db.add_person(p_first_name='Marc', p_last_name='SCHNEIDER', p_birthdate=datetime.date(1973, 4, 24)) assert person1.last_name == 'SCHNEIDER' print(person1) default_user = db.add_default_user_account() assert default_user is not None # Make sure we can't add twice a default account assert db.add_default_user_account() is None password = '******' user1 = db.add_user_account(a_login='******', a_password=password, a_person_id=person1.id, a_is_admin=True) print(user1) assert user1.person.first_name == 'Marc' assert db.authenticate('mschneider', password) assert not db.authenticate('mschneider', 'plop') assert not db.authenticate('hello', 'boy') try: db.add_user_account(a_login='******', a_password='******', a_person_id=person1.id) TestCase.fail(self, "It shouldn't have been possible to add login %s. It already exists!" % 'mschneider') except DbHelperException: pass try: db.add_user_account(a_login='******', a_password='******', a_person_id=999999999) TestCase.fail(self, "It shouldn't have been possible to add login %s. : associated person does not exist") except DbHelperException: pass person2 = db.add_person(p_first_name='Marc', p_last_name='DELAMAIN', p_birthdate=datetime.date(1981, 4, 24)) user2 = db.add_user_account(a_login='******', a_password='******', a_person_id=person2.id, a_is_admin=True) person3 = db.add_person(p_first_name='Ali', p_last_name='CANTE') assert len(db.list_persons()) == 4 user3 = db.add_user_account(a_login='******', a_password='******', a_person_id=person3.id, a_is_admin=True) user4 = db.add_user_account_with_person( a_login='******', a_password='******', a_person_first_name='John', a_person_last_name='STEED', a_person_birthdate=datetime.date(1931, 4, 24), a_is_admin=True, a_skin_used='skins/hat') assert user4.login == 'jsteed' assert user4.person.first_name == 'John' assert user4.person.last_name == 'STEED' assert len(db.list_user_accounts()) == 5
def test_update(self): dt1 = db.add_device_technology('x10', 'x10', 'desc dt1') dty1 = db.add_device_type(dty_id='x10.switch', dty_name='x10 Switch', dty_description='desc1', dt_id=dt1.id) du1 = db.add_device_usage('du1_id', 'du1') device1 = db.add_device(d_name='device1', d_address='A1', d_type_id=dty1.id, d_usage_id=du1.id, d_description='desc1') device_id = device1.id try: db.update_device(d_id=device1.id, d_usage_id=u'9999999999999') TestCase.fail(self, "Device usage does not exist, an exception should have been raised") except DbHelperException: pass device1 = db.update_device(d_id=device1.id, d_description='desc2', d_reference='A1') device1 = db.get_device(device_id) assert device1.description == 'desc2' assert device1.reference == 'A1' assert device1.device_usage_id == du1.id du2 = db.add_device_usage('du2_id', 'du2') device1 = db.update_device(d_id=device1.id, d_reference='', d_usage_id=du2.id) assert device1.reference == None assert device1.device_usage_id == du2.id
def assert_interpreter_is_available(puc: unittest.TestCase): if not sys.executable: puc.fail('Cannot execute test since the name of the Python 3 interpreter is not found in sys.executable.')
def _apply(self, put: unittest.TestCase, value: Any, message_builder: MessageBuilder): if not self.result: put.fail(message_builder.apply(self._message))