|
| 1 | +import unittest |
| 2 | +from unittest.mock import Mock, patch |
| 3 | +import datetime |
| 4 | + |
| 5 | +from cla.models.docusign_models import DocuSign |
| 6 | + |
| 7 | +def test_save_employee_signature(project, company, user_instance): |
| 8 | + """ Test _save_employee_signature """ |
| 9 | + # Mock DocuSign method and related class methods |
| 10 | + DocuSign.check_and_prepare_employee_signature = Mock(return_value={'success': {'the employee is ready to sign the CCLA'}}) |
| 11 | + |
| 12 | + # Create an instance of DocuSign and mock its dynamo_client |
| 13 | + docusign = DocuSign() |
| 14 | + docusign.dynamo_client = Mock() # Mock the dynamo_client on the instance |
| 15 | + mock_put_item = docusign.dynamo_client.put_item = Mock() |
| 16 | + |
| 17 | + # Mock ecla signature object with necessary attributes for the helper method |
| 18 | + signature = Mock() |
| 19 | + signature.get_signature_id.return_value = "sig_id" |
| 20 | + signature.get_signature_project_id.return_value = "proj_id" |
| 21 | + signature.get_signature_document_minor_version.return_value = 1 |
| 22 | + signature.get_signature_document_major_version.return_value = 2 |
| 23 | + signature.get_signature_reference_id.return_value = "ref_id" |
| 24 | + signature.get_signature_reference_type.return_value = "user" |
| 25 | + signature.get_signature_type.return_value = "cla" |
| 26 | + signature.get_signature_signed.return_value = True |
| 27 | + signature.get_signature_approved.return_value = True |
| 28 | + signature.get_signature_acl.return_value = ['acl1', 'acl2'] |
| 29 | + signature.get_signature_user_ccla_company_id.return_value = "company_id" |
| 30 | + signature.get_signature_return_url.return_value = None |
| 31 | + signature.get_signature_reference_name.return_value = None |
| 32 | + |
| 33 | + # Call the helper method |
| 34 | + docusign._save_employee_signature(signature) |
| 35 | + |
| 36 | + # Check if dynamo_client.put_item was called |
| 37 | + assert mock_put_item.called |
| 38 | + |
| 39 | + # Extract the 'Item' argument passed to put_item |
| 40 | + _, kwargs = mock_put_item.call_args |
| 41 | + item = kwargs['Item'] |
| 42 | + |
| 43 | + # Assert that 'date_modified' and 'date_created' are in the item |
| 44 | + assert 'date_modified' in item |
| 45 | + assert 'date_created' in item |
| 46 | + |
| 47 | + |
| 48 | + # Optionally, check if they are correctly formatted ISO timestamps |
| 49 | + try: |
| 50 | + datetime.datetime.fromisoformat(item['date_modified']['S']) |
| 51 | + datetime.datetime.fromisoformat(item['date_created']['S']) |
| 52 | + except ValueError: |
| 53 | + assert False, "date_modified or date_created are not valid ISO format timestamps" |
0 commit comments