|
| 1 | +import datetime |
1 | 2 | from unittest.mock import ANY, Mock, call, patch |
2 | 3 |
|
3 | 4 | from django.conf import settings |
@@ -247,7 +248,44 @@ def test_add_transaction(self, mock_post, mock_get): |
247 | 248 | ) |
248 | 249 | called_url = mock_post.call_args[0][0] |
249 | 250 | assert ( |
250 | | - f"{self.cohiva_test_endpoint}journal/create.json?amount=100.00&creditId=1237&debitId=1477&title=Test+CashCtrl+add_transaction&dateAdded=" |
| 251 | + f"{self.cohiva_test_endpoint}journal/create.json?amount=100.00&creditId=1237&debitId=1477&title=Test+CashCtrl+add_transaction&dateAdded=2026-01-01" |
| 252 | + in called_url |
| 253 | + ) |
| 254 | + |
| 255 | + @patch("finance.accounting.cashctrl.requests.get") |
| 256 | + @patch("finance.accounting.cashctrl.requests.post") |
| 257 | + def test_add_transaction_without_date(self, mock_post, mock_get): |
| 258 | + messages = [] |
| 259 | + with AccountingManager(messages) as book: |
| 260 | + # configure fake responses |
| 261 | + mock_get.return_value.raise_for_status.side_effect = None |
| 262 | + mock_get.side_effect = self.fetch_account_responses |
| 263 | + |
| 264 | + mock_post.return_value.json.return_value = { |
| 265 | + "success": True, |
| 266 | + "message": "Buchung gespeichert", |
| 267 | + "insertId": 700, |
| 268 | + } |
| 269 | + mock_post.return_value.raise_for_status.side_effect = None |
| 270 | + |
| 271 | + transaction_id = book.add_transaction( |
| 272 | + 100.00, |
| 273 | + self.account1, |
| 274 | + self.account2, |
| 275 | + None, |
| 276 | + "Test CashCtrl add_transaction", |
| 277 | + autosave=False, |
| 278 | + ) |
| 279 | + self.assertTrue(transaction_id.startswith("cct_")) |
| 280 | + self.assertEqual("cct_0_700", transaction_id) |
| 281 | + book.save() |
| 282 | + |
| 283 | + # verify that the API was called |
| 284 | + today = datetime.date.today().strftime("%Y-%m-%d") |
| 285 | + called_url = mock_post.call_args[0][0] |
| 286 | + assert ( |
| 287 | + f"{self.cohiva_test_endpoint}journal/create.json?amount=100.00&creditId=1237" |
| 288 | + f"&debitId=1477&title=Test+CashCtrl+add_transaction&dateAdded={today}" |
251 | 289 | in called_url |
252 | 290 | ) |
253 | 291 |
|
|
0 commit comments