def test_are_friend(self): objectFriend = FriendShips() objectFriend.dict = {"Przemek": ["Ala", "Basia", "Piotrek"]} objectFriend.areFriends = MagicMock() objectFriend.areFriends.return_value = "Basia is friend Przemek" objectStorage = FriendStorage() objectStorage.storage = objectFriend result = objectStorage.areFriends("Basia", "Przemek") self.assertEqual(result, "Basia is friend Przemek")
def test_get_friends_list(self): objectFriend = FriendShips() objectFriend.dict = {"Przemek": ["Ala", "Basia", "Piotrek"]} objectFriend.getFriendsList = MagicMock() objectFriend.getFriendsList.return_value = ["Ala", "Basia", "Piotrek"] objectStorage = FriendStorage() objectStorage.storage = objectFriend result = objectStorage.getFriendsList("Przemek") self.assertEqual(result, ["Ala", "Basia", "Piotrek"])
class FriendStorage: def __init__(self): self.storage = FriendShips() def makeFriends(self, person1, person2): return self.storage.makeFriends(person1, person2) def getFriendsList(self, person): return self.storage.getFriendsList(person) def areFriends(self, person1, person2): return self.storage.areFriends(person1, person2)
def test_make_friend_bad_type(self): objectFriend = FriendShips() objectFriend.makeFriends = MagicMock() objectFriend.makeFriends.side_effect = TypeError( "People have to be type string") objectStorage = FriendStorage() objectStorage.storage = objectFriend result = objectStorage.makeFriends self.assertRaisesRegex(TypeError, "People have to be type string", result, "Maciek", False)
def test_get_friends_list_lack_person(self): objectFriend = FriendShips() objectFriend.dict = {"Przemek": ["Ala", "Basia", "Piotrek"]} objectFriend.areFriends = MagicMock() objectFriend.areFriends.side_effect = Exception( "This person not exist") objectStorage = FriendStorage() objectStorage.storage = objectFriend result = objectStorage.getFriendsList self.assertRaisesRegex(Exception, "This person not exist", result, "Adam")
def test_make_friends_add_friend(self): objectFriend = FriendShips() objectFriend.dict = {"Przemek": ["Ala"]} objectFriend.makeFriends = MagicMock() objectFriend.makeFriends.return_value = { "Przemek": ["Ala", "Bartek"], "Bartek": ["Przemek"] } objectStorage = FriendStorage() objectStorage.storage = objectFriend result = objectStorage.makeFriends("Przemek", "Bartek") self.assertEqual(result, { "Przemek": ["Ala", "Bartek"], "Bartek": ["Przemek"] }) objectStorage.storage.makeFriends.assert_called_with( "Przemek", "Bartek")
def __init__(self): self.storage = FriendShips()