Esempio n. 1
0
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))
Esempio n. 2
0
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"
Esempio n. 3
0
    def create_with_id(gang_id: int) -> Gang:
        """Method create, produces a Gang instance with just its Id.

        :param gang_id: Gang's Id.
        :type gang_id: Integer
        :return: The created Gang.
        :rtype: Gang
        """
        return Gang(None, "", gang_id)
Esempio n. 4
0
    def add(self, new_gang: Gang) -> Gang:
        """Method add persists a new Gang to MySQL.

        :param new_gang: Object with the new Gang details.
        :type new_gang: Gang
        :return: The persisted Gang.
        :rtype: Gang
        """
        query = self.__gang_table.insert()\
            .values(owner_id=new_gang.owner_id, name=new_gang.name)
        result = self.__connection.execute(query)
        gang_id = result.lastrowid
        new_gang.id = gang_id
        return new_gang
Esempio n. 5
0
    def create(owner_id: int,
               name: str,
               gang_id: Optional[int] = None) -> Gang:
        """Method create, produces a Gang instance.

        :param owner_id: Outlaw's Id, who is creating the Gang.
        :type owner_id: Integer
        :param name: Given name of the Gang.
        :type name: String
        :param gang_id: Optional, Gang's Id.
        :type gang_id: Integer
        :return: The created Gang.
        :rtype: Gang
        """

        if name is None:
            raise Exception('Gang name required')

        return Gang(owner_id, name, gang_id)
Esempio n. 6
0
def test_grade_raid():
    sheriff = Sheriff("the sheriff", "*****@*****.**", 1)
    sheriff.update_score(22.0)

    gang = Gang(2, "The Gang")
    raid = Raid("very nice restaurant", [], sheriff, gang, "Fake ST 123",
                "2019-12-31 23:59:00")
    raid.rates = list()
    raid.add_rate(10)
    raid.add_rate(9)
    raid.add_rate(7)
    raid.add_rate(8)

    raid_repository = MockRaidRepository()
    raid_repository.add(raid)

    outlaw_repository = MockOutlawRepository()

    request = GradeRaidRequest(raid_id=1)
    result = GradeRaid(raid_repository, outlaw_repository).execute(request)

    assert 8.5 == result
    assert 30.5 == sheriff.get_score()
Esempio n. 7
0
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]
Esempio n. 8
0
    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]