def test_raid_can_not_be_ended_throws_exception(): mail_sender = MockMailNotifier() raid_repository = MockRaidRepository() outlaw_repository = MockOutlawRepository() outlaw_repository.add(Outlaw("1", "email", 1)) gang = Gang(1, "Gang") outlaw1 = Outlaw("2", "email", 2) outlaw2 = Outlaw("3", "email", 3) outlaws = [outlaw1, outlaw2] gang.add_members(outlaws) raid = Raid("amazing raid", outlaws, Sheriff("2", "email", 1), gang, "street 1, 05", date="2019-12-31 23:59:00") raid_repository.add(raid) request = EndRaidRequest(1, 100) end_raid = EndRaid(mail_sender, raid_repository, outlaw_repository) try: end_raid.execute(request) except Exception as e: assert ("Raid can not be finished until all outlaws have ranked it." == str(e))
def test_end_raid(): mail_sender = MockMailNotifier() raid_repository = MockRaidRepository() outlaw_repository = MockOutlawRepository() outlaw_repository.add(Outlaw("1", "email", 1)) gang = Gang(1, "Gang") outlaw1 = Outlaw("2", "email", 2) outlaw2 = Outlaw("3", "email", 3) outlaws = [outlaw1, outlaw2] gang.add_members(outlaws) raid = Raid("amazing raid", outlaws, Sheriff("1", "email", 1), gang, "street 1, 05", date="2019-12-31 23:59:00") raid.rates = list() raid.add_rate(10) raid.add_rate(9) raid_repository.add(raid) end_raid = EndRaid(mail_sender, raid_repository, outlaw_repository) request = EndRaidRequest(1, 100) result = end_raid.execute(request) assert result == \ "Gang's score: 0.0. Sheriff's score on raid 'amazing raid': 100"
def create_with_id(outlaw_id: int) -> Outlaw: """Method create, produces a Outlaw instance with just its Id. :param outlaw_id: Outlaw's Id. :type outlaw_id: Integer :return: The created Outlaw. :rtype: Outlaw """ return Outlaw(None, None, outlaw_id)
def all(self) -> List[Gang]: gang1 = Gang(1, "Gang1") gang2 = Gang(2, "Gang2") gang3 = Gang(3, "Gang3") outlaw1 = Outlaw("B1", "*****@*****.**", 1) outlaw2 = Outlaw("B2", "*****@*****.**", 2) outlaw3 = Outlaw("B3", "*****@*****.**", 3) members_gang1 = [outlaw1, outlaw2] members_gang2 = [outlaw2, outlaw3] members_gang3 = [outlaw1, outlaw3] gang1.add_members(members_gang1) gang2.add_members(members_gang2) gang3.add_members(members_gang3) return [gang1, gang2, gang3]
def add(self, new_outlaw: Outlaw) -> Outlaw: """Method add persists a new Outlaw to MySQL. :param new_outlaw: Object with the new Outlaw details :type new_outlaw: Outlaw :return: The persisted Outlaw. :rtype: Outlaw """ query = self.__outlaw_table.insert().values( name=new_outlaw.name, email=new_outlaw.email ) result = self.__connection.execute(query) new_outlaw.id = result.lastrowid return new_outlaw
def create(name: str, email: str, outlaw_id: Optional[int] = None) -> Outlaw: """Method create, produces an Outlaw instance. :param name: Outlaw's given name. :type name: String :param email: Outlaw's email. :type email: String :param outlaw_id: Optional, Outlaw's Id. :type outlaw_id: Integer :return: The produced Outlaw. :rtype: Outlaw """ return Outlaw(name, email, outlaw_id)
def test_invite_friend(): notifier = MockMailNotifier() outlaw_repository = MockOutlawRepository() outlaw = Outlaw("The gang chief", "*****@*****.**", 1) outlaw_repository.add(outlaw) receiver_email = "*****@*****.**" invite_friend = InviteFriend(outlaw_repository, notifier) request = InviteFriendRequest(outlaw.id, receiver_email) mail = invite_friend.execute(request) assert mail.sender == outlaw.email assert mail.receiver == receiver_email
def test_rate_raid(): outlaw_repository = MockOutlawRepository() outlaw = Outlaw("MockedOutLaw", "*****@*****.**", 1) outlaw_repository.add(outlaw) gang = Gang(2, "The Gang") sheriff = Sheriff("Sheriff", "*****@*****.**", 2) raid_repository = MockRaidRepository() raid = Raid("very nice restaurant", [], sheriff, gang, "Barcelona", "2019-12-31 23:59:00") raid_repository.add(raid) rate_request_1 = RateRaidRequest(1, 0, Score(5, 6, 7, 5.5)) rate_request_2 = RateRaidRequest(1, 0, Score(7, 8.5, 8, 9)) rate_raid = RateRaid(outlaw_repository, raid_repository) rate_raid.execute(rate_request_1) rate_raid.execute(rate_request_2) assert 2 == len(raid.rates) assert 5.875 == raid.rates[0] assert 8.125 == raid.rates[1]
def all(self) -> [Outlaw]: return [ Outlaw("Outlaw1", "*****@*****.**", 1), Outlaw("Outlaw2", "*****@*****.**", 2), Outlaw("Outlaw3", "*****@*****.**", 3) ]
def get_friends(self, outlaw_id: int) -> List[Outlaw]: outlaw_1 = Outlaw("Outlaw1", "*****@*****.**", 1) outlaw_2 = Outlaw("Outlaw2", "*****@*****.**", 2) outlaw_3 = Outlaw("Outlaw3", "*****@*****.**", 3) return [outlaw_1, outlaw_2, outlaw_3]