def test_clout_person(self): # TODO: mock follow() method since that is not what we are testing. clout = Clout() clout.follow('nancy', 'sid') clout_string = clout.clout('sid') expected_clout_string = "sid has 1 follower(s).\n" self.assertEqual(clout_string, expected_clout_string)
class CloutCli(cmd.Cmd): clout = Clout() def do_clout(self, person=None): """ Print the clout of the person if provided, else all the people. :param person: """ print self.clout.clout(name=person) def default(self, line): """ Handles follower following followee. Format: <follower name> follows <followee name> :param line: """ try: args = line.split(" follows ") follower = args[0] followee = args[1] follows = self.clout.follow(follower, followee) if follows: print "OK!" else: print "Nice try, buddy!" except IndexError: print ("That is not a valid command.\nEnter format: " "<follower name> follows <followee name>") return def do_EOF(self, line): return True
def test_follow_follows_self(self): clout = Clout() follows = clout.follow('nancy', 'nancy') self.assertFalse(follows) self.assertEqual(clout.get_person_by_name('nancy').score, 0)
def test_follow(self): clout = Clout() clout.follow('nancy', 'sid') self.assertEqual(clout.get_person_by_name('sid').score, 1) self.assertEqual(clout.get_person_by_name('nancy').score, 0)
def test_follow_from_example(self): clout = Clout() clout.follow('neymar', 'xavi') # neymar = 0, xavi = 1 clout.follow('neymar', 'messi') # neymar = 0, xavi = 0, messi = 1 clout.follow('messi', 'messi') # neymar = 0, xavi = 0, messi = 1 clout.follow('pique', 'victor') # neymar = 0, xavi = 0, messi = 1, pique = 0, victor = 1 clout.follow('jordi', 'pique') # neymar = 0, xavi = 0, messi = 1, pique = 1, victor = 2, jordi = 0 clout.follow('messi', 'victor') # neymar = 0, xavi = 0, messi = 1, pique = 0, victor = 4, jordi = 0 self.assertEqual(clout.get_person_by_name('victor').score, 4) self.assertEqual(clout.get_person_by_name('messi').score, 1) self.assertEqual(clout.get_person_by_name('pique').score, 1) self.assertEqual(clout.get_person_by_name('jordi').score, 0) self.assertEqual(clout.get_person_by_name('neymar').score, 0) self.assertEqual(clout.get_person_by_name('xavi').score, 0)