def test_facts(add_fact): # The format the regex will use found = [('foo bar', 'is', '', 'this is the response')] add_fact.return_value = 'ok' assert 'ok' == facts.facts_match('', '', '', '', found) add_fact.assert_called_with('foo bar', 'foo bar is this is the response', '')
def test_facts_as_reply(add_fact): # The format the regex will use found = [('foo bar', 'is', '<reply>', 'this is the response')] add_fact.return_value = 'ok' assert 'ok' == facts.facts_match('', '', '', '', found) add_fact.assertCalledWith('foo bar', 'this is the response')
def test_facts_match_requires_nick(add_fact, settings): settings.FACTS_REQUIRE_NICKNAME = True client = stub(nickname='helga') # The format the regex will use found = [('foo bar', 'is', '', 'this is the response')] add_fact.return_value = 'ok' assert facts.facts_match(client, '', '', '', found) is None
def test_facts_match_with_nick(add_fact, settings): settings.FACTS_REQUIRE_NICKNAME = True client = stub(nickname='helga') # The format the regex will use found = [('helga: foo bar', 'is', '', 'this is the response')] add_fact.return_value = 'ok' assert 'ok' == facts.facts_match(client, '', '', '', found) add_fact.assert_called_with('foo bar', 'foo bar is this is the response', '')
def test_facts_match_handles_unicode(add_fact, settings): add_fact.return_value = 'ok' settings.FACTS_REQUIRE_NICKNAME = False client = stub(nickname='helga') snowman = u'☃' found_args = [ [(snowman, 'is', '', 'here is a snowman')], [(snowman, 'is', '<reply>', 'here is a snowman')], ] for args in found_args: assert 'ok' == facts.facts_match(client, '', '', '', args) # Handle unicode with nick checking settings.FACTS_REQUIRE_NICKNAME = True for args in found_args: # prepend the nick with_nick = [['helga ' + args[0][0]] + list(args[0][1:])] assert facts.facts_match(client, '', '', '', args) is None assert 'ok' == facts.facts_match(client, '', '', '', with_nick)
def test_facts_match_found_is_show_fact(): facts.show_fact = lambda s: s assert facts.facts_match(None, '', '', '', ['foo']) == 'foo' assert facts.facts_match(None, '', '', '', [u'☃']) == u'☃'