proofmode 0.9.0

Capture, share, and preserve verifiable photos and videos
Documentation
#!/usr/bin/env python3
"""
Tests for ProofMode UniFFI Python bindings
"""

import sys
import os
import tempfile
import unittest
from pathlib import Path

# Add the python package to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python'))

import proofmode


class TestProofModeUniFFI(unittest.TestCase):
    """Test ProofMode UniFFI bindings"""
    
    def setUp(self):
        """Set up test fixtures"""
        self.storage_path = tempfile.mkdtemp()
        self.test_email = "test@example.com"
        self.test_passphrase = "test_passphrase"
        
    def test_version(self):
        """Test version retrieval"""
        version = proofmode.get_proofmode_version()
        self.assertEqual(version, "0.4.0")
        
    def test_create_proofmode(self):
        """Test ProofMode instance creation"""
        pm = proofmode.create_proofmode(
            self.storage_path,
            self.test_email,
            self.test_passphrase
        )
        self.assertIsNotNone(pm)
        
    def test_generator_class(self):
        """Test ProofModeGenerator class"""
        generator = proofmode.ProofModeGenerator(
            storage_path=self.storage_path,
            email=self.test_email,
            passphrase=self.test_passphrase
        )
        
        # Test version
        version = generator.version()
        self.assertEqual(version, "0.4.0")
        
    def test_checker_class(self):
        """Test ProofModeChecker class"""
        checker = proofmode.ProofModeChecker()
        self.assertIsNotNone(checker)
        
    def test_progress_callback(self):
        """Test progress callback"""
        messages = []
        
        class TestCallback(proofmode.SimpleProgressCallback):
            def report_progress(self, message):
                messages.append(message)
        
        callback = TestCallback()
        callback.report_progress("Test message")
        
        self.assertEqual(messages, ["ProofMode: Test message"])
        
    def test_platform_callbacks(self):
        """Test platform callbacks"""
        callbacks = proofmode.FilePlatformCallbacks(self.storage_path)
        
        # Test device info
        device_info = callbacks.get_device_info()
        self.assertIsNotNone(device_info)
        self.assertEqual(device_info.manufacturer, "Python")
        
        # Test network info
        network_info = callbacks.get_network_info()
        self.assertIsNotNone(network_info)
        self.assertEqual(network_info.network_type, "unknown")
        
        # Test location (should return None)
        location = callbacks.get_location()
        self.assertIsNone(location)
        
    def test_generate_proof_simple(self):
        """Test simple proof generation"""
        # Create a test file
        test_file = Path(self.storage_path) / "test.txt"
        test_file.write_text("Test content")
        
        # Generate proof
        proof_hash = proofmode.generate_proof_simple(
            str(test_file),
            self.storage_path,
            self.test_email,
            self.test_passphrase,
            {"description": "Test file"}
        )
        
        self.assertIsNotNone(proof_hash)
        self.assertIsInstance(proof_hash, str)
        
    def test_check_files_simple(self):
        """Test simple file checking"""
        # Create a test file
        test_file = Path(self.storage_path) / "test.txt"
        test_file.write_text("Test content")
        
        # Check files
        result = proofmode.check_files_simple([str(test_file)])
        
        self.assertIsNotNone(result)
        self.assertIsInstance(result, str)
        
        # Result should be valid JSON
        import json
        parsed_result = json.loads(result)
        self.assertIn("metadata", parsed_result)
        self.assertIn("version", parsed_result["metadata"])
        
    def test_data_structures(self):
        """Test data structure creation"""
        # Test ProofModeConfig
        config = proofmode.ProofModeConfig(
            storage_path=self.storage_path,
            email=self.test_email,
            passphrase=self.test_passphrase
        )
        self.assertEqual(config.storage_path, self.storage_path)
        self.assertEqual(config.email, self.test_email)
        self.assertEqual(config.passphrase, self.test_passphrase)
        
        # Test LocationInfo
        location = proofmode.LocationInfo(
            latitude=37.7749,
            longitude=-122.4194,
            altitude=100.0,
            accuracy=10.0,
            provider="GPS"
        )
        self.assertEqual(location.latitude, 37.7749)
        self.assertEqual(location.longitude, -122.4194)
        self.assertEqual(location.altitude, 100.0)
        self.assertEqual(location.accuracy, 10.0)
        self.assertEqual(location.provider, "GPS")
        
        # Test DeviceInfo
        device = proofmode.DeviceInfo(
            manufacturer="Test",
            model="TestModel",
            os_version="TestOS 1.0",
            device_id="test123",
            imei="123456789"
        )
        self.assertEqual(device.manufacturer, "Test")
        self.assertEqual(device.model, "TestModel")
        self.assertEqual(device.os_version, "TestOS 1.0")
        self.assertEqual(device.device_id, "test123")
        self.assertEqual(device.imei, "123456789")
        
        # Test NetworkInfo
        network = proofmode.NetworkInfo(
            network_type="WiFi",
            carrier="TestCarrier",
            cell_tower_id="tower123",
            wifi_ssid="TestNetwork"
        )
        self.assertEqual(network.network_type, "WiFi")
        self.assertEqual(network.carrier, "TestCarrier")
        self.assertEqual(network.cell_tower_id, "tower123")
        self.assertEqual(network.wifi_ssid, "TestNetwork")


if __name__ == '__main__':
    # Run tests
    unittest.main(verbosity=2)