This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Crear asalto use case + entity business logic * Extract crear asalto params to crear asalto request * cambios en caso de uso llamada desde controller * refactor variable * WIP: Ajustes en caso de uso y pruebas con pytest * WIP: crear asalto + tests * WIP: crear asalto cambios en todas las capas * FIX: Added tests to test_crear_asalto changes on test_calificar_asalto, test_puntuar_asalto changes on mysql_asalto_repository * Raid modificaciones en entidad para integrar caso de uso create_raid all tests passed * WIP: banda_mock_repo deleted, test_crear_asalto deleted * DOC: create_raid examples * FEAT: create_raid (all tests passed) * Deleted non used files * limpieza de código Co-authored-by: Diego Zavaleta <diegozav92@gmail.com>
- Loading branch information
1 parent
d036f0d
commit 658305b
Showing
11 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"raid": { | ||
"id": 1, | ||
"name": "Asalto 1", | ||
"date": "2019-12-31 23:59:00", | ||
"location": "Barcelona", | ||
"gang": {}, | ||
"sheriff": {}, | ||
"outlaws": [], | ||
"rates": [] | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from tests.mock_gang_repository import MockGangRepository | ||
from tests.mock_outlaw_repository import MockOutlawRepository | ||
from tests.mock_raid_repository import MockRaidRepository | ||
from thesheriff.application.raid.create_raid import CreateRaid | ||
from thesheriff.application.raid.create_raid_request import CreateRaidRequest | ||
from thesheriff.domain.outlaw.outlaw import Outlaw | ||
|
||
|
||
def test_create_raid(): | ||
name = 'Asalto test' | ||
date = '2019-12-24 23:59:00' | ||
location = 'Barcelona' | ||
gang_id = 1 | ||
sheriff_id = 3 | ||
outlaw_ids = [1, 2, 3] | ||
|
||
request = CreateRaidRequest(name, date, location, gang_id, sheriff_id, outlaw_ids) | ||
|
||
outlaw_repository = MockOutlawRepository() | ||
outlaw_repository.outlaw = Outlaw(3, 'Sheriff', 'sheriff@banda.com') | ||
|
||
gang_repository = MockGangRepository() | ||
gang_repository.gang = gang_repository.all()[0] | ||
|
||
service = CreateRaid(outlaw_repository, gang_repository, MockRaidRepository()) | ||
|
||
raid = service.execute(request) | ||
|
||
assert raid.name == name | ||
assert raid.sheriff.id == sheriff_id |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from datetime import datetime | ||
|
||
from thesheriff.application.raid.create_raid_request import CreateRaidRequest | ||
from thesheriff.domain.gang.gang import Gang | ||
from thesheriff.domain.gang.repository.gang_repository import GangRepository | ||
from thesheriff.domain.outlaw.outlaw import Outlaw | ||
from thesheriff.domain.outlaw.repository.outlaw_repository \ | ||
import OutlawRepository | ||
from thesheriff.domain.outlaw.sheriff import Sheriff | ||
from thesheriff.domain.raid.raid import Raid, DEFAULT_DATETIME_FORMAT | ||
from thesheriff.domain.raid.repository.raid_repository import RaidRepository | ||
|
||
|
||
class CreateRaid: | ||
def __init__( | ||
self, | ||
outlaw_repository: OutlawRepository, | ||
gang_repository: GangRepository, | ||
raid_repository: RaidRepository | ||
): | ||
self.__outlaw_repository = outlaw_repository | ||
self.__gang_repository = gang_repository | ||
self.__raid_repository = raid_repository | ||
|
||
def execute(self, request: CreateRaidRequest): | ||
sheriff = self.get_sheriff_or_fail(request) | ||
gang = self.get_gang_or_fail(request) | ||
outlaws = self.get_outlaws_or_fail(request) | ||
|
||
date = datetime.strptime(request.date, DEFAULT_DATETIME_FORMAT) | ||
raid_id = 0 | ||
|
||
raid = Raid( | ||
request.name, | ||
request.location, | ||
sheriff, | ||
gang, | ||
date, | ||
raid_id, | ||
outlaws | ||
) | ||
|
||
self.__raid_repository.add(raid) | ||
|
||
return raid | ||
|
||
def get_sheriff_or_fail(self, request: CreateRaidRequest) -> Sheriff: | ||
sheriff = self.__outlaw_repository.of_id(request.sheriff_id) | ||
if sheriff is None: | ||
raise Exception('Sheriff with id: {0} does not exist.' | ||
.format(request.sheriff_id)) | ||
sheriff = Sheriff(sheriff) | ||
return sheriff | ||
|
||
def get_gang_or_fail(self, request: CreateRaidRequest) -> Gang: | ||
gang = self.__gang_repository.of_id(request.gang_id) | ||
if gang is None: | ||
raise Exception('Gang with id: {0} does not exist.' | ||
.format(request.gang_id)) | ||
return gang | ||
|
||
def get_outlaws_or_fail(self, request: CreateRaidRequest) -> [Outlaw]: | ||
outlaws = [] | ||
all_outlaws = self.__outlaw_repository.all() | ||
if outlaws is None or len(all_outlaws) < 1: | ||
raise Exception('Outlaws does not exist') | ||
|
||
for outlaw in all_outlaws: | ||
if outlaw.id in request.outlaw_ids: | ||
outlaws.append(outlaw) | ||
|
||
return outlaws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from datetime import datetime | ||
|
||
|
||
class CreateRaidRequest: | ||
def __init__(self, | ||
name: str, | ||
date: datetime, | ||
location: str, | ||
gang_id: str, | ||
sheriff_id: int, | ||
outlaw_ids: list | ||
): | ||
self.name = name | ||
self.date = date | ||
self.location = location | ||
self.gang_id = gang_id | ||
self.sheriff_id = sheriff_id | ||
self.outlaw_ids = outlaw_ids |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters