Ejemplo n.º 1
0
 def test_get_by_transaction_id(self):
     transaction = TransactionManager.get_by_transaction_id(
         self.transaction.transaction_id)
     self.assertEqual(self.transaction.transaction_id,
                      transaction.transaction_id)
     self.assertEqual(self.transaction.transaction_amount,
                      transaction.transaction_amount)
Ejemplo n.º 2
0
 def get_detail_transaction(transaction_id: str) -> Dict:
     data = TransactionManager.get_by_transaction_id(transaction_id=transaction_id)
     if data:
         data = TransactionSerializer(instance=data, many=False).data
         return data
     else:
         raise APIException(
             detail=f'The transaction with id {transaction_id} is not found.',
             code=HTTP_400_BAD_REQUEST
         )
Ejemplo n.º 3
0
 def setUp(self) -> None:
     transactions = TransactionManager.get_all()
     for transaction in transactions:
         session.delete(transaction)
         session.commit()
     self.transaction = Transaction(
         transaction_id='52fba4fa-3a01-4961-a809-e343dd4f9597',
         transaction_date='2020-06-01',
         transaction_amount=200000,
         client_id=1067,
         client_name='test 1')
     session.add(self.transaction)
     session.commit()
Ejemplo n.º 4
0
    def get_transactions(self, params: Dict) -> Optional[List]:
        self.__data = params
        validate_allowed_fields(
            data=self.__data,
            allowed_fields={
                'transaction_id',
                'transaction_date',
                'transaction_amount',
                'client_id',
                'client_name',
                'page',
                'per_page',
                'order_by'
            }
        )

        data = TransactionManager.get_all_by_params(params=self.__data)
        data = TransactionSerializer(instance=data, many=True).data
        return data
Ejemplo n.º 5
0
    def upload_file(self, file: Dict) -> Dict:
        field = 'file'

        self.__data = file
        validate_required_fields(data=self.__data, required_fields={field})
        validate_allowed_fields(data=self.__data, allowed_fields={field})
        validate_allowed_type_files(data=self.__data, field=field, type_files={'csv'})

        service = MinioAPI()
        file_path = service.upload_object(
            file=self.__data['file']
        )

        try:
            with atomic_transaction():
                file_data = {
                    'name': self.__data['file'].name,
                    'created_at': date.today()
                }
                FileManager.create(data=file_data)

                ex = ThreadPoolExecutor(max_workers=2)
                process = ex.submit(self.__read_file_and_store_data, file_path)
                process.result()

                transaction_data = TransactionManager.get_all()

                data = TransactionSerializer(
                    instance=transaction_data,
                    many=True
                ).data

                return data
        except:
            raise APIException(
                detail='The operation is invalid',
                code=HTTP_400_BAD_REQUEST
            )
Ejemplo n.º 6
0
 def test_get_all(self):
     transactions = TransactionManager.get_all()
     self.assertEqual(self.transaction.transaction_id,
                      transactions[0].transaction_id)
     self.assertEqual(self.transaction.transaction_amount,
                      transactions[0].transaction_amount)