def test_sourceData_CurrentSeason(self): with Database(self.dbName, SQLite3Impl()) as db, \ db.transaction() as t: seasonMap = db.select(Source_Season_Map(98))[0] seasonMap.setActive(1) db.upsert(seasonMap) seasonMap = Source_Season_Map(98, 'season name TD2', \ 'source_season_map moniker TD2', \ 'source_season_map data_url TD2', 1) db.upsert(seasonMap) sourceData(self.mock_Logger, 'source name TD', True) self.mock_readCSVFileAsDict.assert_any_call( \ 'source_season_map data_url TD2') calls = ( call.info( 'Downloading data from source: source name TD'), call.debug('Opening database: ./db/test.db'), call.debug( "source : Keys {'id': 98} : Values {'name': " \ "'source name TD', 'fixtures_url': 'source " \ "fixtures_url TD', 'url': 'source url TD'}"), call.debug( "[source_season_map : Keys {'source_id': 98, "\ "'season': 'season name TD2'} : Values {'moniker'" \ ": 'source_season_map moniker TD2', 'data_url': " \ "'source_season_map data_url TD2', 'active': 1}]"), call.debug( "[source_league_map : Keys {'source_id': 98, " \ "'league': 'league mnemonic TD'} : Values " \ "{'moniker': 'source_league_map moniker TD'}]"), call.debug( "[team : Keys {'name': 'team name TD'} : Values " \ "{'league': 'league mnemonic TD'}, " \ "team : Keys {'name': 'team name TD2'} : Values " \ "{'league': 'league mnemonic TD2'}]"), call.info('Downloading...source_season_map data_url TD2'), ) self.mock_Logger.assert_has_calls(calls) with Database(self.dbName, SQLite3Impl()) as db: ht = db.select(Team('Coventry', 'league mnemonic TD'))[0] at = db.select(Team('Cardiff', 'league mnemonic TD'))[0] match = db.select(Match(201010191))[0] self.assertTrue(ht and at and match) self.assertEquals(match.getDate(), '2010-10-19') self.assertEquals(match.getLeague(), 'league mnemonic TD') self.assertEquals(match.getHome_Team(), 'Coventry') self.assertEquals(match.getAway_Team(), 'Cardiff') self.assertEquals(match.getResult(), 'A') self.assertEquals(match.getBest_Odds_H(), 3.12) self.assertEquals(match.getBest_Odds_D(), 3.4) self.assertEquals(match.getBest_Odds_A(), 2.4) self.assertEquals(match.getHome_Goals(), 1) self.assertEquals(match.getAway_Goals(), 2) self.assertEquals(match.getHome_Lp(), None) self.assertEquals(match.getAway_Lp(), None)
def test_init(self): m_pip_logger = Mock() m_pip_s_logger = Mock() def se_get_logger(lname): if lname == 'pip': return m_pip_logger if lname == 'pip.subprocessor': return m_pip_s_logger with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack: with patch('%s.logger' % pbm, autospec=True) as m_logger: with patch('%s.logging.getLogger' % pbm, autospec=True) as m_get_log: m_get_log.side_effect = se_get_logger cls = VersionFinder('foobar', package_file='/foo/bar/baz.py') assert m_stack.mock_calls == [] assert cls.package_name == 'foobar' assert cls.package_file == '/foo/bar/baz.py' assert cls.package_dir == '/foo/bar' assert m_logger.mock_calls == [ call.setLevel(logging.CRITICAL), call.debug('Finding package version for: %s', 'foobar'), call.debug('Explicit package file: %s', '/foo/bar/baz.py'), call.debug('package_dir: /foo/bar') ] assert m_get_log.mock_calls == [call('pip'), call('pip.subprocessor')] assert m_pip_logger.mock_calls == [call.setLevel(logging.CRITICAL)] assert m_pip_s_logger.mock_calls == []
def test_dry(self): logger: Logger = Mock() qe = DryRunQueryExecutor(logger) qe.execute_all(["sql1", "sql2"], stream="s") qe.commit() self.assertEqual([ call.debug('>>> Dry run: %s (args=%s, stream=%s)', 'sql1', None, 's'), call.debug('>>> Dry run: %s (args=%s, stream=%s)', 'sql2', None, 's'), call.debug('>>> Dry run: Commit') ], logger.mock_calls)
async def test_reader_worker(): rq_queue, w_queue, rst_queue = asyncio.Queue(), asyncio.Queue( ), asyncio.Queue() rq_queue.put_nowait(0) main.logging = Mock() await main.reader_worker(0, '', 1, rq_queue, w_queue, rst_queue, None, leader=True, only_one_loop=True) main.logging.assert_has_calls([ call.debug('reader0: reading 1 items from offset 1...'), call.error('Mailchimp api-read: HTTP Error 404: Not Found') ], any_order=True) rq_queue.put_nowait(0) main.logging = Mock() await main.reader_worker(0, '1a2d7ebf82', 1, rq_queue, w_queue, rst_queue, None, leader=True, only_one_loop=True) main.logging.assert_has_calls( [call.debug('reader0: reading 1 items from offset 1...')], any_order=True) assert w_queue.qsize() == 1 assert rq_queue.qsize() > 0 for s in main.logging.method_calls: if s.startswith('call.info(\'reader0: items [1, 1] of'): assert True elif s.startswith('call.info(\'reader0: adding all remaining'): assert True elif s == 'call.debug(\'reader0: reading 1 items from offset 1...\')': assert True else: assert False
def test_pjlinksettings_call_udp_listener(self, mock_tab_log, mock_pjlink_log, mock_check_settings): """ Test calling UDP listners in PJLink Settings tab """ # GIVEN: Initial setup tab_debug_calls = [ call('PJLink settings tab initialized'), call('PJLinkSettings: new callback list: dict_keys([4352])'), call('PJLinkSettings: Calling UDP listeners') ] pjlink_debug_calls = [call.debug('(UDP:4352) PJLinkUDP() Initialized')] pjlink_udp = PJLinkUDP() settings_tab = ProjectorTab(parent=None) settings_tab.add_udp_listener(port=pjlink_udp.port, callback=pjlink_udp.check_settings) # WHEN: calling UDP listener via registry settings_tab.call_udp_listener() # THEN: settings tab should have one entry assert len(settings_tab.udp_listeners) == 1 mock_check_settings.assert_called() mock_tab_log.debug.assert_has_calls(tab_debug_calls) mock_pjlink_log.assert_has_calls(pjlink_debug_calls)
def test_no_role_arn(self): m_sts = Mock() m_sts.assume_role.return_value = { 'Credentials': { 'AccessKeyId': 'AKID', 'SecretAccessKey': 'SKey', 'SessionToken': 'SToken', 'Expiration': datetime(2018, 10, 8, 12, 13, 14) }, 'AssumedRoleUser': { 'AssumedRoleId': 'ARid', 'Arn': 'UserARN' }, 'PackedPolicySize': 123 } m_sess = Mock() m_sess.client.return_value = m_sts with patch('%s.logger' % pbm, autospec=True) as mock_logger: with patch.dict(os.environ, {}, clear=True): with patch('%s.boto3.session.Session' % pbm) as mock_boto: mock_boto.return_value = m_sess assume_role(self.m_conf) assert os.environ == {} assert mock_boto.mock_calls == [] assert mock_logger.mock_calls == [ call.debug('No assume_role configuration; not assuming a role.') ]
def test_normal_send(self): """ Test normal messages sending """ socket_mock = Mock() logger_mock = Mock() output_wrapper = Output(socket_mock, logger_mock) output_wrapper.info('info(%s)', 'arg1') output_wrapper.debug('debug(%s)', 'arg2') output_wrapper.error('error(%s)', 'arg3') output_wrapper.error('no_args_error(%s)') output_wrapper.log('log(%s)', 'arg4') output_wrapper.say('say(%s)', 'arg5') output_wrapper.say('no_args_say(%s)') socket_mock.assert_has_calls([ call.send(b'{"text": "info(arg1)"}\x00'), call.send(b'{"error": "error(arg3)"}\x00'), call.send(b'{"error": "no_args_error(%s)"}\x00'), call.send(b'{"text": "log(arg4)"}\x00'), call.send(b'{"text": "say(arg5)"}\x00'), call.send(b'{"text": "no_args_say(%s)"}\x00'), ]) logger_mock.assert_has_calls([ call.info('info(%s)', 'arg1'), call.debug('debug(%s)', 'arg2'), call.error('error(%s)', 'arg3'), call.error('no_args_error(%s)'), call.info('log(%s)', 'arg4'), call.info('say(%s)', 'arg5'), call.info('no_args_say(%s)'), ])
def test_executemany(self): self.executor.executemany("a query") self.assertEqual([call.debug('%s (%s, %s)', 'a query', (), {})], self.logger.mock_calls) self.assertEqual([call.cursor(), call.cursor().executemany('a query')], self.connection.mock_calls)
def test_init_not_us_east_1(self): with patch('%s.logger' % pbm, autospec=True) as mock_logger: with patch('%s.jsonschema.validate' % pbm, autospec=True) as mock_validate: cls = ManheimConfig(foo='bar', baz=2, regions=['us-east-2'], config_path='manheim-c7n-tools.yml', account_id='1234', cleanup_notify=['*****@*****.**'], function_prefix='foo-') assert cls._config == { 'foo': 'bar', 'baz': 2, 'regions': ['us-east-2'], 'account_id': '1234', 'cleanup_notify': ['*****@*****.**'], 'function_prefix': 'foo-' } assert cls.config_path == 'manheim-c7n-tools.yml' assert mock_logger.mock_calls == [ call.debug('Validating configuration...') ] assert mock_validate.mock_calls == [ call( { 'foo': 'bar', 'baz': 2, 'regions': ['us-east-2'], 'account_id': '1234', 'cleanup_notify': ['*****@*****.**'], 'function_prefix': 'foo-' }, MANHEIM_CONFIG_SCHEMA) ]
def test_HTTPException_no_server_error(self, LOGGER): exc = HTTPNotFound() http_exc = exc_to_http_exc(exc) self.assertIs(http_exc, exc) self.assertEqual(http_exc.code, 404) self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY, 404), ])
def test_analyseMatches(self): analyseMatches(self.mock_Logger, 1, 'league mnemonic TD') calls = ( call.info('Analysing matches for league <league ' \ 'mnemonic TD> with algo <1>'), call.debug('Opening database: ./db/test.db'), call.debug('Last rating for match 99'), call.debug('7 matches found to mark'), ) self.mock_Logger.assert_has_calls(calls) with Database(self.dbName, SQLite3Impl()) as db: stats = db.select(Statistics()) ratings = db.select(Rating()) self.assertEquals(len(stats), 2) self.assertEquals(stats[0].getGeneration_Date(), \ str(datetime.now().date())) self.assertEquals(stats[0].getAlgo_Id(), 1) self.assertEquals(stats[0].getLeague(), 'league mnemonic TD') self.assertEquals(stats[0].getMark(), -3) self.assertEquals(stats[0].getMark_Freq(), 50.0) self.assertEquals(stats[0].getHome_Freq(), 100.0) self.assertEquals(stats[0].getAway_Freq(), 0.0) self.assertEquals(stats[0].getDraw_Freq(), 0.0) self.assertEquals(stats[1].getGeneration_Date(), \ str(datetime.now().date())) self.assertEquals(stats[1].getAlgo_Id(), 1) self.assertEquals(stats[1].getLeague(), 'league mnemonic TD') self.assertEquals(stats[1].getMark(), -2) self.assertEquals(stats[1].getMark_Freq(), 50.0) self.assertEquals(stats[1].getHome_Freq(), 100.0) self.assertEquals(stats[1].getAway_Freq(), 0.0) self.assertEquals(stats[1].getDraw_Freq(), 0.0) self.assertEquals(len(ratings), 2) self.assertEquals(ratings[0].getMatch_Oid(), 6) self.assertEquals(ratings[0].getAlgo_Id(), 1) self.assertEquals(ratings[0].getMark(), -3) self.assertEquals(ratings[1].getMatch_Oid(), 7) self.assertEquals(ratings[1].getAlgo_Id(), 1) self.assertEquals(ratings[1].getMark(), -2)
def test_archive_feed(self): with patch('oe_utils.scripts.archive_feed.log') as log_mock: responses.add( responses.POST, url="https://host.be/bron/atomfeed/archive", status=200) feed_list = [{ 'atom_feed_folder': fixture_directory, 'atom_feed_manager': TestAtomFeedManager, 'max_entries': 2, 'archive_feed_url': 'https://host.be/bron/atomfeed/archive' }] archive_feed.archive_entries(feed_list=feed_list, session=self.db, system_token='test_token') debug_calls = [ call.debug('Number of entries: 2'), call.debug('Archive current feed') ] self.assertEqual(log_mock.debug.mock_calls, debug_calls)
def test_ParamCleaningError(self, LOGGER): exc = ParamCleaningError(public_message='FOO') # custom public message http_exc = exc_to_http_exc(exc) self.assertIsInstance(http_exc, HTTPBadRequest) self.assertEqual(http_exc.code, 400) self.assertEqual(http_exc.detail, 'FOO') # detail == custom public message self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY), ])
def test_AuthorizationError(self, LOGGER): exc = AuthorizationError(public_message='FOO') # custom public message http_exc = exc_to_http_exc(exc) self.assertIsInstance(http_exc, HTTPForbidden) self.assertEqual(http_exc.code, 403) self.assertEqual(http_exc.detail, 'FOO') # detail == custom public message self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY), ])
def test_ParamCleaningError_2(self, LOGGER): exc = ParamCleaningError() # no specific public message http_exc = exc_to_http_exc(exc) self.assertIsInstance(http_exc, HTTPBadRequest) self.assertEqual(http_exc.code, 400) self.assertEqual( http_exc.detail, # detail == default public message ParamCleaningError.default_public_message) self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY), ])
def test_normal(self): logger: Logger = Mock() connection: Connection = Mock() qe = NormalQueryExecutor(logger, connection) qe.execute_all(["sql1", "sql2"], stream="s") qe.commit() self.assertEqual([ call.debug('Execute: %s (args=%s, stream=%s)', 'sql1', (), {'stream': 's'}), call.debug('Execute: %s (args=%s, stream=%s)', 'sql2', (), {'stream': 's'}), call.debug('Commit') ], logger.mock_calls) self.assertEqual([ call.cursor(), call.cursor().execute('sql1', stream='s'), call.cursor().execute('sql2', stream='s'), call.commit() ], connection.mock_calls)
def test_copy_stream(self): self.executor.copy_stream(SQLTable("table", [], []), BytesIO(b"data"), "utf-8", unix_dialect) self.assertEqual([ call.debug('%s (%s, %s)', 'INSERT INTO table VALUES ()', mock.ANY, {}) ], self.logger.mock_calls) self.assertEqual([ call.cursor(), call.cursor().executemany('INSERT INTO table VALUES ()', mock.ANY) ], self.connection.mock_calls)
def test_AuthorizationError_2(self, LOGGER): exc = AuthorizationError() # no specific public message http_exc = exc_to_http_exc(exc) self.assertIsInstance(http_exc, HTTPForbidden) self.assertEqual(http_exc.code, 403) self.assertEqual( http_exc.detail, # detail == default public message AuthorizationError.default_public_message) self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY), ])
def test_fetch_and_compare_versions_same(self, mock_log, get_mock): get_mock.return_value.json.return_value = {"info": {"version": "1.9.0"}} fetch_and_compare_versions() get_mock.assert_has_calls([call(AWS_SAM_CLI_PYPI_ENDPOINT, timeout=PYPI_CALL_TIMEOUT_IN_SECONDS)]) mock_log.assert_has_calls( [ call.debug("Installed version %s, current version %s", "1.9.0", "1.9.0"), ] )
def test_init_log_true(self): m_pip_logger = Mock() with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack: with patch('%s.logger' % pbm, autospec=True) as m_logger: with patch('%s.logging.getLogger' % pbm, autospec=True) as m_log_pip: m_log_pip.return_value = m_pip_logger cls = VersionFinder('foobar', log=True, package_file='/foo/bar/baz.py') assert m_stack.mock_calls == [] assert cls.package_name == 'foobar' assert cls.package_file == '/foo/bar/baz.py' assert cls.package_dir == '/foo/bar' assert m_logger.mock_calls == [ call.debug('Finding package version for: %s', 'foobar'), call.debug('Explicit package file: %s', '/foo/bar/baz.py'), call.debug('package_dir: /foo/bar') ] assert m_log_pip.mock_calls == [] assert m_pip_logger.mock_calls == []
async def test_writer_worker(): w_queue, rst_queue = asyncio.Queue(), asyncio.Queue() w_queue.put_nowait([]) main.logging = Mock() await main.writer_worker(0, w_queue, rst_queue, True) main.logging.assert_has_calls([ call.debug('writer0: writing 0 results.'), call.info('writer0: wrote 0 results with status "OK".') ], any_order=True)
def test_subclass_of_DataLookupError_3(self, LOGGER): class MyCustomError(DataLookupError): default_public_message = 'own_default' exc = MyCustomError(public_message='FOO') # custom public message http_exc = exc_to_http_exc(exc) self.assertIsInstance(http_exc, HTTPNotFound) self.assertEqual(http_exc.code, 404) self.assertEqual(http_exc.detail, 'FOO') # detail == custom public message self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY), ])
def test(self): logger: Logger = Mock() dp: DirectiveProcessor = Mock() source_script: SourceScript = Mock(relative_path="fname", script_path=file_path_mock( io.StringIO("some line")), export_funcs=True) target_dir: Path = Mock() target_dir.joinpath.side_effect = [Path('t')] sp = ScriptProcessor(logger, dp, source_script, target_dir) sp.parse_script() self.assertEqual([ call.debug('Parsing script: %s (%s)', 'fname', source_script), call.debug('Temp output script is: %s (%s)', Path('t'), []) ], logger.mock_calls) self.assertEqual([call.ignore_lines(), call.end()], dp.mock_calls) verify_open_path(self, source_script.script_path, 'r', encoding='utf-8')
def test_subclass_of_DataLookupError_2(self, LOGGER): class MyCustomError(DataLookupError): pass exc = MyCustomError() # no specific public message http_exc = exc_to_http_exc(exc) self.assertIsInstance(http_exc, HTTPNotFound) self.assertEqual(http_exc.code, 404) self.assertEqual( http_exc. detail, # detail == `DataLookupError.default public message` DataLookupError.default_public_message) self.assertEqual(LOGGER.mock_calls, [ call.debug(ANY, exc, ANY), ])
def test_assembling_decoder_mix_in_warning(): encoding = "utf-8" data_bytes = "🐷🐶.".encode(encoding) adm = AssemblingDecoderMixIn() with patch("datalad.runner.utils.logger") as logger_mock: result = adm.decode(1, data_bytes[0:1], encoding) assert_equal(result, '') del adm assert_in( call.warning("unprocessed data in AssemblingDecoderMixIn"), logger_mock.mock_calls) assert_in( call.debug( "unprocessed data in AssemblingDecoderMixIn:\n" "fd: 1, data: b'\\xf0'\n"), logger_mock.mock_calls)
def test_log_config(mock_makedirs, mock_getLogger, mock_get_handlers): mock_log = MagicMock(autospec=True) mock_getLogger.return_value = mock_log assert log_config( 'root', 'name', 'INFO', ) assert [ call.setLevel(20), call.debug('%s: %s %s\n=> %s', 'log_config', ('root', 'name', 'INFO'), {}, { 'console_handler': 'handler1', 'file_handler': 'handler2' }) ] == mock_log.mock_calls assert [call('root', exist_ok=True)] == mock_makedirs.mock_calls assert [call(), call('schmetterling.core.log')] == mock_getLogger.mock_calls assert call('root', 'name') == mock_get_handlers.mock_calls[0] assert ['handler1', 'handler2'] == mock_log.handlers
def test_destination_scripts(self, SSPMock): # mocks logger: Logger = Mock() sources: Sources = Mock() destinations: Destinations = Mock() source_scripts: List[SourceScript] = Mock() destination_script: DestinationScript = Mock() temp_script: TempScript = Mock() # play sources.get_src_scripts.return_value = source_scripts destinations.to_destination_scripts.return_value = [destination_script] SSPMock.return_value.process.return_value = [temp_script] h = OdsUpdaterHelper(logger, sources, destinations, "3.1") scripts = h.get_destination_scripts() # verify self.assertEqual([call.debug('Directives tree: %s', mock.ANY)], logger.mock_calls) self.assertEqual([destination_script], scripts) self.assertEqual([call.get_src_scripts(), call.get_module_names()], sources.mock_calls) self.assertEqual([call.to_destination_scripts([temp_script])], destinations.mock_calls)
def test_scan_file(self): """Test analysis of a single file. """ from os import stat_result from os.path import join from ..census import scan_file mock_os = Mock() fd = join(self.data_dir, 'test.module') intlink = join(self.data_dir, 'test.module.link') extlink = '/foo/bar/t/test.module' s = stat_result((33188, 83865343, 16777220, 1, 501, 20, 973, 1491428112, 1446143268, 1462630505)) # # Simulate a simple file. # calls = [ call.debug("os.stat('{0}')".format(fd)), call.warning("{0} does not have correct group id!".format(fd)) ] mock_log = Mock() with patch('desiutil.log.get_logger') as mock_get_logger: with patch.dict('sys.modules', { 'os': mock_os, 'os.path': mock_os.path }): mock_get_logger.return_value = mock_log mock_os.environ = dict() mock_os.stat.return_value = s mock_os.path.islink.return_value = False mock_os.path.join.return_value = fd f = scan_file(self.data_dir, 'test.module', 12345) self.assertListEqual(mock_log.mock_calls, calls) self.assertEqual(f.filename, fd) self.assertEqual(f.size, 973) self.assertEqual(f.year, 2016) # # Simulate an internal link. # calls = [ call.debug("os.stat('{0}')".format(fd)), call.warning("{0} does not have correct group id!".format(fd)), call.debug("os.lstat('{0}')".format(fd)), call.warning("{0} does not have correct group id!".format(fd)), call.debug("Found internal link {0} -> {0}.link.".format(fd)) ] mock_log = Mock() with patch('desiutil.log.get_logger') as mock_get_logger: with patch.dict('sys.modules', { 'os': mock_os, 'os.path': mock_os.path }): mock_get_logger.return_value = mock_log mock_os.environ = dict() mock_os.stat.return_value = s mock_os.lstat.return_value = s mock_os.path.commonpath.return_value = self.data_dir mock_os.path.islink.return_value = True mock_os.path.join.return_value = fd mock_os.path.realpath.return_value = intlink f = scan_file(self.data_dir, 'test.module', 12345) self.assertListEqual(mock_log.mock_calls, calls) self.assertEqual(f.filename, fd) self.assertEqual(f.size, 973) self.assertTrue(f.islink) self.assertFalse(f.isexternal) self.assertEqual(f.linkname, intlink) # # Simulate an external link. # calls = [ call.debug("os.stat('{0}')".format(fd)), call.warning("{0} does not have correct group id!".format(fd)), call.debug("os.lstat('{0}')".format(fd)), call.warning("{0} does not have correct group id!".format(fd)), call.debug("Found external link {0} -> {1}.".format(fd, extlink)) ] mock_log = Mock() with patch('desiutil.log.get_logger') as mock_get_logger: with patch.dict('sys.modules', { 'os': mock_os, 'os.path': mock_os.path }): mock_get_logger.return_value = mock_log mock_os.environ = dict() mock_os.stat.return_value = s mock_os.lstat.return_value = s mock_os.path.commonpath.return_value = '/' mock_os.path.islink.return_value = True mock_os.path.join.return_value = fd mock_os.path.realpath.return_value = extlink f = scan_file(self.data_dir, 'test.module', 12345) self.assertListEqual(mock_log.mock_calls, calls) self.assertEqual(f.filename, fd) self.assertEqual(f.size, 973) self.assertTrue(f.islink) self.assertTrue(f.isexternal) self.assertEqual(f.linkname, extlink)
def test_execute(self): self.executor.execute(["a query"]) self.assertEqual([call.debug("a query")], self.logger.mock_calls) self.assertEqual( [call.cursor(), call.cursor().execute('a query')], self.connection.mock_calls)
def test_commit(self): self.executor.commit() self.assertEqual([call.debug('commit')], self.logger.mock_calls) self.assertEqual([call.cursor(), call.commit()], self.connection.mock_calls)
def test_getBestOdds(self): row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('B365A', '2.4'), ('BWH', '2.75'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('IWA', '2.4'), ('LBH', '2.88'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHH', '3.1'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCH', '3.12'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.12, 3.4, 2.4)) row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('BWH', '2.75'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('IWA', '2.4'), ('LBH', '2.88'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHH', '3.1'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCH', '3.12'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.12, 3.4, 2.4)) row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('B365A', '2.4'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('IWA', '2.4'), ('LBH', '2.88'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHH', '3.1'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCH', '3.12'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.12, 3.4, 2.4)) row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('B365A', '2.4'), ('BWH', '2.75'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('LBH', '2.88'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHH', '3.1'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCH', '3.12'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.12, 3.4, 2.4)) row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('B365A', '2.4'), ('BWH', '2.75'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('IWA', '2.4'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHH', '3.1'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCH', '3.12'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.12, 3.4, 2.4)) row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('B365A', '2.4'), ('BWH', '2.75'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('IWA', '2.4'), ('LBH', '2.88'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCH', '3.12'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.12, 3.4, 2.4)) row = dict([('b"Div', 'E1'), ('Date', '19/10/10'), ('HomeTeam', 'Coventry'), ('AwayTeam', 'Cardiff'), ('FTHG', '1'), ('FTAG', '2'), ('FTR', 'A'), ('HTHG', '1'), ('HTAG', '1'), ('HTR', 'D'), ('Referee', 'J Linington'), ('HS', '12'), ('AS', '9'), ('HST', '5'), ('AST', '6'), ('HF', '12'), ('AF', '10'), ('HC', '5'), ('AC', '4'), ('HY', '2'), ('AY', '0'), ('HR', '0'), ('AR', '0'), ('B365H', '2.88'), ('B365D', '3.3'), ('B365A', '2.4'), ('BWH', '2.75'), ('BWD', '3.2'), ('BWA', '2.3'), ('GBH', '2.9'), ('GBD', '3.25'), ('GBA', '2.3'), ('IWH', '2.5'), ('IWD', '3.1'), ('IWA', '2.4'), ('LBH', '2.88'), ('LBD', '3.3'), ('LBA', '2.4'), ('SBH', '2.9'), ('SBD', '3.1'), ('SBA', '2.3'), ('WHH', '3.1'), ('WHD', '3.1'), ('WHA', '2.38'), ('SJH', '2.8'), ('SJD', '3.25'), ('SJA', '2.4'), ('VCD', '3.4'), ('VCA', '2.38'), ('BSH', '2.9'), ('BSD', '3.3'), ('BSA', '2.3'), ('Bb1X2', '36'), ('BbMxH', '3.22'), ('BbAvH', '2.94'), ('BbMxD', '3.44'), ('BbAvD', '3.26'), ('BbMxA', '2.4'), ('BbAvA', '2.34'), ('BbOU', '35'), ('BbMx>2.5', '2.07'), ('BbAv>2.5', '1.98'), ('BbMx<2.5', '1.87'), ('BbAv<2.5', '1.78'), ('BbAH', '23'), ('BbAHh', '0'), ('BbMxAHH', '2.27'), ('BbAvAHH', '2.16'), ('BbMxAHA', '1.72'), ('BbAvAHA', '1.66')]) odds = getBestOdds(self.mock_Logger, row) self.assertEqual(odds, (3.1, 3.3, 2.4)) calls = ( call.debug('No B365 data - skipping : 19/10/10 Coventry Cardiff'), call.debug('No BW data - skipping : 19/10/10 Coventry Cardiff'), call.debug('No IW data - skipping : 19/10/10 Coventry Cardiff'), call.debug('No WH data - skipping : 19/10/10 Coventry Cardiff'), call.debug('No VC data - skipping : 19/10/10 Coventry Cardiff')) self.mock_Logger.assert_has_calls(calls)