Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4264] Bug/Ecla Acknowledged timestamp #4454

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cla-backend/cla/models/docusign_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import xml.etree.ElementTree as ET
from typing import Any, Dict, List, Optional
from urllib.parse import urlparse
from datetime import datetime

import cla
import pydocusign # type: ignore
Expand Down Expand Up @@ -784,6 +785,8 @@ def _save_employee_signature(self,signature):
'signature_approved': {'BOOL': signature.get_signature_approved()},
'signature_acl': {'SS': list(signature.get_signature_acl())},
'signature_user_ccla_company_id': {'S': signature.get_signature_user_ccla_company_id()},
'date_modified': {'S': datetime.now().isoformat()},
'date_created': {'S': datetime.now().isoformat()}
}

if signature.get_signature_return_url() is not None:
Expand Down
53 changes: 53 additions & 0 deletions cla-backend/cla/tests/unit/test_ecla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import unittest
from unittest.mock import Mock, patch
import datetime

from cla.models.docusign_models import DocuSign

def test_save_employee_signature(project, company, user_instance):
""" Test _save_employee_signature """
# Mock DocuSign method and related class methods
DocuSign.check_and_prepare_employee_signature = Mock(return_value={'success': {'the employee is ready to sign the CCLA'}})

# Create an instance of DocuSign and mock its dynamo_client
docusign = DocuSign()
docusign.dynamo_client = Mock() # Mock the dynamo_client on the instance
mock_put_item = docusign.dynamo_client.put_item = Mock()

# Mock ecla signature object with necessary attributes for the helper method
signature = Mock()
signature.get_signature_id.return_value = "sig_id"
signature.get_signature_project_id.return_value = "proj_id"
signature.get_signature_document_minor_version.return_value = 1
signature.get_signature_document_major_version.return_value = 2
signature.get_signature_reference_id.return_value = "ref_id"
signature.get_signature_reference_type.return_value = "user"
signature.get_signature_type.return_value = "cla"
signature.get_signature_signed.return_value = True
signature.get_signature_approved.return_value = True
signature.get_signature_acl.return_value = ['acl1', 'acl2']
signature.get_signature_user_ccla_company_id.return_value = "company_id"
signature.get_signature_return_url.return_value = None
signature.get_signature_reference_name.return_value = None

# Call the helper method
docusign._save_employee_signature(signature)

# Check if dynamo_client.put_item was called
assert mock_put_item.called

# Extract the 'Item' argument passed to put_item
_, kwargs = mock_put_item.call_args
item = kwargs['Item']

# Assert that 'date_modified' and 'date_created' are in the item
assert 'date_modified' in item
assert 'date_created' in item


# Optionally, check if they are correctly formatted ISO timestamps
try:
datetime.datetime.fromisoformat(item['date_modified']['S'])
datetime.datetime.fromisoformat(item['date_created']['S'])
except ValueError:
assert False, "date_modified or date_created are not valid ISO format timestamps"
Loading