Exemplo n.º 1
0
 def test_update_readonly_field(self,
                     ctx,
                     transaction_manager: TransactionManager):
     req = AbstractTransaction(
         author=1,
     )
     with pytest.raises(ValidationError):
         transaction_manager.partially_update(ctx, req)
Exemplo n.º 2
0
 def test_cannot_delete_nonpending(self,
                     ctx,
                     mock_transaction_repository,
                     sample_transaction: Transaction,
                     transaction_manager: TransactionManager):
     # When...
     mock_transaction_repository.get_by_id = MagicMock(return_value=(sample_transaction))
     with raises(UserInputError):
         transaction_manager.delete(ctx, **{"id": sample_transaction.id})
Exemplo n.º 3
0
    def test_transaction_not_found(self,
                                   ctx,
                                   faker,
                                   mock_transaction_repository: TransactionRepository,
                                   transaction_manager: TransactionManager):
        mock_transaction_repository.get_by_id = MagicMock(return_value=(None), side_effect=TransactionNotFoundError(""))

        with raises(TransactionNotFoundError):
            transaction_manager.get_by_id(ctx, **{"id": faker.random_int})
Exemplo n.º 4
0
    def test_object_not_found(self,
                        ctx,
                        mock_transaction_repository,
                        transaction_manager: TransactionManager):
        # Given
        mock_transaction_repository.get_by_id = MagicMock(return_value=(None), side_effect=NotFoundError(""))

        # When...
        with raises(NotFoundError):
            transaction_manager.delete(ctx, **{"id": 0})
Exemplo n.º 5
0
    def test_happy_path(self,
                        ctx,
                        transaction_manager: TransactionManager):
        req = AbstractTransaction(
            name='test',
            attachments=None

        )
        with pytest.raises(NotImplementedError):
            transaction_manager.partially_update(ctx, req)
Exemplo n.º 6
0
    def test_happy_path(self,
                        ctx,
                        mock_transaction_repository,
                        sample_transaction_pending: Transaction,
                        transaction_manager: TransactionManager):
        # When...
        mock_transaction_repository.get_by_id = MagicMock(return_value=(sample_transaction_pending))
        transaction_manager.delete(ctx, **{"id": sample_transaction_pending.id})

        # Expect...
        mock_transaction_repository.delete.assert_called_once_with(ctx, sample_transaction_pending.id)
Exemplo n.º 7
0
    def test_happy_path(self,
                          ctx,
                          transaction_manager: TransactionManager):
        req = AbstractTransaction(
            src='1',
            dst='2',
            name='test',
            value=-1,
            payment_method='1',
            attachments=None

        )
        with raises(ValidationError):
            transaction_manager.update_or_create(ctx, req)
Exemplo n.º 8
0
    def test_happy_path(self,
                        ctx,
                        mock_transaction_repository,
                        sample_transaction,
                        transaction_manager: TransactionManager):
        mock_transaction_repository.get_by_id = MagicMock(return_value=(sample_transaction))
        result = transaction_manager.get_by_id(ctx, **{"id": sample_transaction.id})

        assert sample_transaction == result
        mock_transaction_repository.get_by_id.assert_called_once()
Exemplo n.º 9
0
    def test_happy_path(self,
                        ctx,
                        mock_transaction_repository,
                        sample_transaction: Transaction,
                        transaction_manager: TransactionManager):
        mock_transaction_repository.search_by = MagicMock(return_value=([sample_transaction], 1))
        result, count = transaction_manager.search(ctx, limit=42, offset=2, terms='abc')

        assert [sample_transaction] == result
        assert 1 == count
        mock_transaction_repository.search_by.assert_called_once_with(ctx, limit=42, offset=2, terms='abc')
Exemplo n.º 10
0
    def test_happy_path_create(self,
                               ctx,
                               mock_transaction_repository: TransactionRepository,
                               transaction_manager: TransactionManager,
                               sample_transaction: Transaction):
        req = AbstractTransaction(
            src='1',
            dst='2',
            name='test',
            value=1,
            payment_method='1',
            attachments=None
        )
        mock_transaction_repository.create = MagicMock(return_value=(sample_transaction))

        _, c = transaction_manager.update_or_create(ctx, req)

        assert c is True
        mock_transaction_repository.create.assert_called_once_with(ctx, req)
Exemplo n.º 11
0
    def test_happy_path_create_only_admin(self,
                               ctx_only_admin,
                               mock_transaction_repository: TransactionRepository,
                               transaction_manager: TransactionManager,
                               sample_transaction_pending: Transaction):
        req = AbstractTransaction(
            src=sample_transaction_pending.src,
            dst=sample_transaction_pending.dst,
            name=sample_transaction_pending.name,
            value=sample_transaction_pending.value,
            payment_method=sample_transaction_pending.payment_method,
            attachments=sample_transaction_pending.attachments
        )
        mock_transaction_repository.create = MagicMock(return_value=(sample_transaction_pending))

        r, c = transaction_manager.update_or_create(ctx_only_admin, req)

        assert r.pending_validation
        assert c is True
        mock_transaction_repository.create.assert_called_once_with(ctx_only_admin, req)
Exemplo n.º 12
0
    def test_happy_path_update(self,
                               ctx,
                               mock_transaction_repository: TransactionRepository,
                               transaction_manager: TransactionManager,
                               sample_transaction: Transaction):
        req = AbstractTransaction(
            src=sample_transaction.src,
            dst=sample_transaction.dst,
            name=sample_transaction.name,
            value=sample_transaction.value,
            payment_method=sample_transaction.payment_method,
            attachments=sample_transaction.attachments
        )
        mock_transaction_repository.create = MagicMock(return_value=(sample_transaction))
        mock_transaction_repository.get_by_id = MagicMock(return_value=(sample_transaction))
        mock_transaction_repository.update = MagicMock(return_value=(sample_transaction))

        _, c = transaction_manager.update_or_create(ctx, req, sample_transaction.id)

        assert c is False
        mock_transaction_repository.create.assert_not_called()
        mock_transaction_repository.get_by_id.assert_called_once()
        mock_transaction_repository.update.assert_called_once()
Exemplo n.º 13
0
    def test_happy_path_create_add_cashbox(self,
                               ctx,
                               mock_transaction_repository: TransactionRepository,
                                           mock_cashbox_repository: CashboxRepository,
                               transaction_manager: TransactionManager,
                               sample_transaction: Transaction):
        sample_transaction.cashbox = "to"
        req = AbstractTransaction(
            src=sample_transaction.src,
            dst=sample_transaction.dst,
            name=sample_transaction.name,
            value=sample_transaction.value,
            payment_method=sample_transaction.payment_method,
            attachments=sample_transaction.attachments
        )
        mock_transaction_repository.create = MagicMock(return_value=(sample_transaction))
        mock_cashbox_repository.update = MagicMock(return_value=(None))

        _, c = transaction_manager.update_or_create(ctx, req)

        assert c is True
        mock_transaction_repository.create.assert_called_once_with(ctx, req)
        mock_cashbox_repository.update.assert_called_once_with(ctx, value_modifier=sample_transaction.value, transaction=sample_transaction)
Exemplo n.º 14
0
 def test_limit_negative(self,
                         ctx,
                         transaction_manager: TransactionManager):
     with raises(IntMustBePositive):
         transaction_manager.search(ctx, limit=-1)
Exemplo n.º 15
0
def transaction_manager(mock_transaction_repository, mock_cashbox_repository):
    return TransactionManager(
        transaction_repository=mock_transaction_repository,
        cashbox_repository=mock_cashbox_repository
    )