def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('insee_code',
                            type=str,
                            help='Insee code',
                            action='append')
        parser.add_argument('postal_code',
                            type=str,
                            help='Postal code',
                            action='append')
        parser.add_argument('code_dept',
                            type=str,
                            help='Departement code',
                            action='append')
        args = parser.parse_args()

        postal_codes: Union[str, List[str], None] = args.get("postal_code")
        insee_code: Union[str, List[str], None] = args.get("insee_code")
        code_dept: Union[str, List[str], None] = args.get("code_dept")

        if postal_codes or insee_code:
            affairs = AffairService.list_affairs_by_insee_and_postal_codes(
                insee_code=insee_code,
                postal_code=postal_codes,
                code_dept=code_dept,
                uow=current_app.context)
        else:
            affairs = AffairService.list_affairs(uow=current_app.context)

        return {"data": affairs, "message": "success"}, 200
Exemple #2
0
 def delete(self, uuid, affair_uuid):
     AffairService.delete_affair_from_evenement(affair_id=affair_uuid,
                                                evenement_id=uuid,
                                                uow=current_app.context)
     return {
         "message":
         f"affair {affair_uuid} successfully deleted to evenement {uuid}"
     }, 201
Exemple #3
0
def test_add_affair(filename: pathlib.Path,
                    affair_repo: AbstractAffairRepository):
    with open(str(filename), 'r') as f:
        affair_xml_string = str(f.read())
        AffairService.add_affair_from_xml(xml_string=affair_xml_string,
                                          uow=affair_repo)
        with pytest.raises(AlreadyExistingAffairUuid):
            AffairService.add_affair_from_xml(xml_string=affair_xml_string,
                                              uow=affair_repo)
Exemple #4
0
def test_add_multiple_affair(affair_repo: AbstractAffairRepository):
    for filename in filenames:
        with open(str(filename), 'r') as f:
            affair_xml_string = str(f.read())
            AffairService.add_affair_from_xml(xml_string=affair_xml_string,
                                              uow=affair_repo)

    affairs = AffairService.list_affairs(repo=affair_repo)
    assert isinstance(affairs, list)
    assert isinstance(affairs[0], dict)
    assert len(affairs) == len(filenames)
Exemple #5
0
    def post(self):
        if request.headers['Content-Type'] in ["application/xml", 'text/xml']:
            current_app.logger.info("post message")
            xml = request.data.decode("utf-8")

            echange = EchangeSchema().load({
                'payload': xml
            })
            _ = EchangeService.add_echange(echange, uow=current_app.context)
            try:
                affair = AffairService.add_affair_from_xml(xml, uow=current_app.context)
                event_bus.publish(AffairCreatedEvent(data=affair))
                current_app.logger.info("Successfully create affairs")
                return {
                           "message": "success affair"
                       }, 200
            except Exception as e:
                current_app.logger.info(f"Failed to create affairs {e}")
                return {
                           "message": "success"
                       }, 200

        return {
                   "message": "error",
                   "contentType": request.headers['Content-Type']
               }, 200
Exemple #6
0
def test_affairs_service_with_know_code_chelles(
        affair_repo: AbstractAffairRepository):
    for filename in filenames:
        with open(str(filename), 'r') as f:
            affair_xml_string = str(f.read())
            AffairService.add_affair_from_xml(xml_string=affair_xml_string,
                                              uow=affair_repo)

    with (response_folder / "chelles.json").open() as f:
        chelles_response = json.load(f)

    with requests_mock.Mocker(real_http=True) as m:
        m.register_uri(
            'GET',
            'http://localhost:8083/decoupage-administratif/territoire/codes?codesInsee=77108',
            json=chelles_response)

        affairs = AffairService.list_affairs_by_insee_and_postal_codes(
            insee_code="77108", postal_code=None, repo=affair_repo)
    assert isinstance(affairs, list)
    assert len(affairs) == 4
 def post(self):
     if request.headers['Content-Type'] in ["application/xml", 'text/xml']:
         current_app.logger.info("post message")
         xml = request.data.decode("utf-8")
         affair = AffairService.add_affair_from_xml(xml, uow=current_app.context)
         event_bus.publish(AffairCreatedEvent(data=affair))
         return {
                "message": "success"
            }, 200
     return {
         "message": "error",
         "contentType": request.headers['Content-Type']
     }, 200
 def get_affairs_by_user_uuid(
         uuid: str, uow: AbstractUnitOfWork) -> List[Dict[str, Any]]:
     with uow:
         user: UserEntity = uow.user.get_by_uuid(uuid=uuid)
         code: str = user.position.group.location.external_id
         group_type: GroupType = user.position.group.type
         args = {
             "insee_code": code if group_type is GroupType.MAIRIE else None,
             "code_dept":
             code if group_type is GroupType.PREFECTURE else None,
             "postal_code": None,
         }
         return AffairService.list_affairs_by_insee_and_postal_codes(
             uow=uow, **args)
Exemple #9
0
 def get(self):
     return {
         "data": AffairService.get_random_list_affairs(self.random_repo),
         "message": "success"
     }, 200
Exemple #10
0
 def get(self):
     return {
         "affair": AffairService.get_random_affair(self.random_repo),
         "message": "success"
     }, 200
 def get(self, uuid):
     return {
         "data": AffairService.get_by_uuid(uuid, current_app.context),
         "message": "success"
     }, 200
Exemple #12
0
 def get(self, uuid):
     affairs = AffairService.list_affairs_by_evenement(
         uuid, current_app.context)
     return {"data": affairs, "message": "success"}, 201