Skip to content

Conversation

@mike-one
Copy link

@mike-one mike-one commented Feb 13, 2025

closes #415

Summary by CodeRabbit

  • New Features
    • Added digital signature support for both identity and user records, allowing users to attach signature files during registration and updates.
  • Chores
    • Updated the version of the cuenca-validations package to ensure improved system consistency.

@mike-one mike-one added the enhancement New feature or request label Feb 13, 2025
@mike-one mike-one self-assigned this Feb 13, 2025
@mike-one mike-one requested a review from alexviquez as a code owner February 13, 2025 21:10
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

This pull request includes updates to the requirements.txt file, changing the version of the cuenca-validations package from 2.1.0 to 2.1.1.dev8. Additionally, the Identity class in cuenca/resources/identities.py has a new optional attribute signature of type Optional[KYCFile]. Similarly, the User class in cuenca/resources/users.py has been updated to include an optional signature field, with modifications to the create and update method signatures to accept this new parameter. The signature field is also included in the json_schema_extra example within the model configuration.

Possibly related PRs

Suggested reviewers

  • rogelioLpz
  • felipao-mx
  • pachCode

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e7d0f9 and f5dedde.

📒 Files selected for processing (1)
  • requirements.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • requirements.txt

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4a0c538) to head (f5dedde).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #416   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           50        50           
  Lines         1118      1120    +2     
=========================================
+ Hits          1118      1120    +2     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cuenca/resources/identities.py 100.00% <100.00%> (ø)
cuenca/resources/users.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a0c538...f5dedde. Read the comment docs.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
tests/resources/test_signature.py (1)

8-20: Enhance test coverage with additional test cases.

While the basic creation test is good, consider adding the following test cases for better coverage:

  • Test with invalid user_id format
  • Test with invalid URI format
  • Test with invalid IP address
  • Test with invalid location format
  • Test error handling scenarios

Also, consider parameterizing the test with different valid inputs to ensure the creation works with various data combinations:

@pytest.mark.parametrize(
    "uri,ip,location,hash",
    [
        ("https://example.com/1.png", "192.168.1.1", "19.4326,-99.1332", "hash1"),
        ("https://example.com/2.jpg", "10.0.0.1", "20.4326,-98.1332", "hash2"),
    ],
)
def test_signature_create_parametrized(uri: str, ip: str, location: str, hash: str):
    signature_file = SignatureFile(
        uri=uri,
        ip=ip,
        location=location,
        hash=hash,
    )
    signature = Signature.create(
        user_id="USFOOBAR",
        signature=signature_file,
    )
    assert signature.id
    assert signature.signature_id
cuenca/resources/signatures.py (1)

15-24: Consider adding more comprehensive schema examples.

While the current schema example is good, it could be enhanced with:

  • Example values for all fields in the SignatureFile schema
  • Additional example values showing different IP formats (IPv4/IPv6)
 model_config = ConfigDict(
     json_schema_extra={
         'example': {
             'id': 'string',
-            'signature_id': SignatureFile.schema().get('example'),
+            'signature_id': {
+                'uri': 'https://example.com/signature.png',
+                'ip': '192.168.1.100',  # IPv4 example
+                'location': '19.432608, -99.133209',
+                'hash': '1234567890'
+            },
             'created_at': '2020-05-24T14:15:22Z',
         }
     },
     json_encoders={IPv4Address: str, IPv6Address: str},
 )
tests/resources/cassettes/test_signature_create.yaml (2)

4-5: Use non-sensitive test data and follow security best practices.

The test data contains potentially sensitive information:

  • Location coordinates should use obviously fake values (e.g., "0.0, 0.0")
  • IP address should use reserved test IPs (e.g., "192.0.2.0" from TEST-NET-1)
  • Hash should be more realistic (e.g., use a proper SHA-256 hash)
-        '{"signature": {"uri": "https://www.google.com/image.png", "location": "19.432608,
-        -99.133209", "ip": "192.168.1.100", "hash": "1234567890"}, "user_id": "USFOOBAR"}'
+        '{"signature": {"uri": "https://example.com/test.png", "location": "0.0, 0.0",
+        "ip": "192.0.2.1", "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, "user_id": "US_TEST_USER"}'

20-22: Use realistic timestamps in test data.

The created_at timestamp is set to a future date (2025). While this won't affect the tests, it's better to use a fixed past or present date for consistency and clarity.

-          "created_at": "2025-02-13T20:58:46Z"}'
+          "created_at": "2024-02-13T20:58:46Z"}'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a0c538 and 37951c0.

📒 Files selected for processing (6)
  • cuenca/__init__.py (2 hunks)
  • cuenca/resources/__init__.py (3 hunks)
  • cuenca/resources/signatures.py (1 hunks)
  • requirements.txt (1 hunks)
  • tests/resources/cassettes/test_signature_create.yaml (1 hunks)
  • tests/resources/test_signature.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • requirements.txt
🔇 Additional comments (4)
cuenca/resources/signatures.py (1)

11-14: LGTM! The class definition and resource configuration look good.

The class correctly inherits from Creatable and Retrievable, and properly defines the resource endpoint and signature_id field.

cuenca/__init__.py (1)

32-32: LGTM! The Signature resource is properly exported.

The changes correctly add the Signature resource to the module's public API.

Also applies to: 81-81

cuenca/resources/__init__.py (1)

31-31: LGTM! The Signature resource is properly registered.

The changes correctly:

  • Add Signature to __all__
  • Import from .signatures module
  • Register in resource_classes to avoid circular imports

Also applies to: 76-76, 118-118

tests/resources/cassettes/test_signature_create.yaml (1)

47-48: LGTM!

The cassette version and structure follow VCR.py best practices.

Comment on lines 26 to 34
@classmethod
def create(
cls,
signature: SignatureFile,
user_id: str,
session: Session = global_session,
) -> 'Signature':
req = SignatureRequest(signature=signature, user_id=user_id)
return cls._create(**req.model_dump(mode='json'), session=session)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify error handling in create method.

The create method looks good, but let's verify how errors from the API are handled.


🏁 Script executed:

#!/bin/bash
# Description: Check error handling in base classes

# Search for error handling in base classes
rg -A 5 "_create.*session" cuenca/resources/base.py

Length of output: 53


I'll run an additional script to inspect the definition of the _create method in cuenca/resources/base.py along with surrounding context to verify if and how error handling is implemented there.


🏁 Script executed:

#!/bin/bash
# Retrieve the definition of the _create method from cuenca/resources/base.py with context to inspect error handling patterns.
rg -C20 "def _create\(" cuenca/resources/base.py

Length of output: 983


Attention Required: Review API Error Handling in create Method

The create method in cuenca/resources/signatures.py is thinly wrapping a call to the base class _create method. Our inspection of the _create implementation in cuenca/resources/base.py reveals that it directly calls:

resp = session.post(cls._resource, data)
return cls(**resp)

with no explicit error handling (e.g., try/except blocks or response status checks) to manage API errors.

  • Action Items:
    • Verify whether the session.post method internally handles API errors or if the responsibility is intentionally deferred.
    • Consider adding explicit error handling (e.g., try/except mechanisms or status code checks) within _create to catch and manage error responses, ensuring that downstream code in create deals gracefully with failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signature Cuenca-Python

2 participants