You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB

  1. # Copyright 2020 Coop IT Easy SCRL fs
  2. # Robin Keunen <robin@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from unittest.mock import Mock, patch
  5. import requests
  6. from odoo.fields import Date
  7. from odoo.addons.easy_my_coop.tests.test_base import EMCBaseCase
  8. from .test_data import AP_CREATE_RESULT, SR_VALIDATE_RESULT, dict_to_dump
  9. class EMCPaymentConnectorCase(EMCBaseCase):
  10. def setUp(self):
  11. super().setUp()
  12. self.backend = self.browse_ref(
  13. "easy_my_coop_connector.emc_backend_demo"
  14. )
  15. self.env["emc.binding.account.journal"].create(
  16. {
  17. "backend_id": self.backend.id,
  18. "internal_id": self.bank_journal.id,
  19. "external_id": 1,
  20. }
  21. )
  22. def test_post_payment_sends_and_binds_request(self):
  23. srequest = self.browse_ref("easy_my_coop.subscription_request_1_demo")
  24. with patch.object(requests, "post") as mock_get:
  25. mock_get.return_value = mock_response = Mock()
  26. mock_response.status_code = 200
  27. mock_response.content = dict_to_dump(SR_VALIDATE_RESULT)
  28. srequest.validate_subscription_request()
  29. capital_release_request = srequest.capital_release_request
  30. payment_method_manual_in = self.env.ref(
  31. "account.account_payment_method_manual_in"
  32. )
  33. ctx = {
  34. "active_model": "account.invoice",
  35. "active_ids": [capital_release_request.id],
  36. }
  37. register_payments = (
  38. self.env["account.register.payments"]
  39. .with_context(ctx)
  40. .create(
  41. {
  42. "payment_date": Date.today(),
  43. "journal_id": self.bank_journal.id,
  44. "payment_method_id": payment_method_manual_in.id,
  45. }
  46. )
  47. )
  48. with patch.object(requests, "post") as mock_get:
  49. mock_get.return_value = mock_response = Mock()
  50. mock_response.status_code = 200
  51. mock_response.content = dict_to_dump(AP_CREATE_RESULT)
  52. register_payments.create_payments()
  53. self.assertEquals(capital_release_request.state, "paid")
  54. payment = capital_release_request.payment_ids
  55. self.assertEquals(payment.state, "posted")
  56. self.assertEquals(payment.binding_id.external_id, 9876)