mirror of
				https://github.com/Eledio/superfaktura-client.git
				synced 2025-10-31 16:11:20 +01:00 
			
		
		
		
	test_client_contact: add tests
This commit is contained in:
		
							
								
								
									
										52
									
								
								test/test_client_contact.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								test/test_client_contact.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| import pytest  # type: ignore | ||||
| from unittest.mock import patch | ||||
| from superfaktura.client_contacts import ( | ||||
|     ClientContactModel, | ||||
|     ClientContact, | ||||
|     ClientException, | ||||
| ) | ||||
|  | ||||
|  | ||||
| @pytest.fixture | ||||
| def client_contact(): | ||||
|     with patch("superfaktura.client_contacts.ClientContact", return_value=None): | ||||
|         return ClientContact() | ||||
|  | ||||
|  | ||||
| def test_add_contact_success(client_contact): | ||||
|     client = ClientContactModel( | ||||
|         name="John Doe", | ||||
|     ) | ||||
|  | ||||
|     with patch("superfaktura.superfaktura_api.SuperFakturaAPI.post") as mock_post: | ||||
|         mock_post.return_value = {"error_message": "Client created"} | ||||
|         assert client_contact.add_contact(contact=client) | ||||
|  | ||||
|  | ||||
| def test_add_contact_failed(client_contact): | ||||
|     client = ClientContactModel( | ||||
|         name="John Doe", | ||||
|     ) | ||||
|  | ||||
|     with patch("superfaktura.superfaktura_api.SuperFakturaAPI.post") as mock_post: | ||||
|         mock_post.return_value = {"error_message": "Client creation failed"} | ||||
|         assert not client_contact.add_contact(contact=client) | ||||
|  | ||||
|  | ||||
| def test_list(client_contact): | ||||
|     with patch("superfaktura.superfaktura_api.SuperFakturaAPI.get") as mock_get: | ||||
|         mock_get.return_value = {"data": "test"} | ||||
|         assert client_contact.list() == {"data": "test"} | ||||
|  | ||||
|  | ||||
| def test_get_client_exists(client_contact): | ||||
|     with patch("superfaktura.superfaktura_api.SuperFakturaAPI.get") as mock_get: | ||||
|         mock_get.return_value = {"Client": {"name": "John Doe", "id": 1}} | ||||
|         assert client_contact.get_client(client_id=1).name == "John Doe" | ||||
|  | ||||
|  | ||||
| def test_get_client_not_exists(client_contact): | ||||
|     with patch("superfaktura.superfaktura_api.SuperFakturaAPI.get") as mock_get: | ||||
|         mock_get.return_value = {} | ||||
|         with pytest.raises(ClientException): | ||||
|             client_contact.get_client(client_id=1) | ||||
		Reference in New Issue
	
	Block a user