|
| 1 | +# anin.test.py |
| 2 | + |
| 3 | +import unittest |
| 4 | +from anin import AstroNeuralInterfaceNetwork |
| 5 | + |
| 6 | +class TestAstroNeuralInterfaceNetwork(unittest.TestCase): |
| 7 | + def setUp(self): |
| 8 | + """Set up a new AstroNeuralInterfaceNetwork instance for testing.""" |
| 9 | + self.anin = AstroNeuralInterfaceNetwork() |
| 10 | + |
| 11 | + def test_connect_user_success(self): |
| 12 | + """Test successful user connection.""" |
| 13 | + self.anin.connect_user("User _1", "secure-token-123") |
| 14 | + self.assertIn("User _1", self.anin.user_connections) |
| 15 | + |
| 16 | + def test_connect_user_invalid_token(self): |
| 17 | + """Test connection with an invalid authentication token.""" |
| 18 | + with self.assertRaises(PermissionError) as context: |
| 19 | + self.anin.connect_user("User _2", "invalid-token") |
| 20 | + self.assertEqual(str(context.exception), "Invalid authentication token.") |
| 21 | + |
| 22 | + def test_disconnect_user_success(self): |
| 23 | + """Test successful user disconnection.""" |
| 24 | + self.anin.connect_user("User _1", "secure-token-123") |
| 25 | + self.anin.disconnect_user("User _1") |
| 26 | + self.assertNotIn("User _1", self.anin.user_connections) |
| 27 | + |
| 28 | + def test_disconnect_user_not_connected(self): |
| 29 | + """Test disconnection of a user that is not connected.""" |
| 30 | + with self.assertRaises(ValueError) as context: |
| 31 | + self.anin.disconnect_user("User _2") |
| 32 | + self.assertEqual(str(context.exception), "User not connected.") |
| 33 | + |
| 34 | + def test_transfer_with_thought_success(self): |
| 35 | + """Test successful asset transfer for a connected user.""" |
| 36 | + self.anin.connect_user("User _1", "secure-token-123") |
| 37 | + self.anin.transfer_with_thought("User _1", "CNC", 50) |
| 38 | + self.assertEqual(len(self.anin.transaction_log), 1) |
| 39 | + self.assertEqual(self.anin.transaction_log[0]['user_id'], "User _1") |
| 40 | + self.assertEqual(self.anin.transaction_log[0]['asset'], "CNC") |
| 41 | + self.assertEqual(self.anin.transaction_log[0]['amount'], 50) |
| 42 | + |
| 43 | + def test_transfer_with_thought_user_not_connected(self): |
| 44 | + """Test transfer when the user is not connected.""" |
| 45 | + with self.assertRaises(ValueError) as context: |
| 46 | + self.anin.transfer_with_thought("User _2", "CNC", 50) |
| 47 | + self.assertEqual(str(context.exception), "User not connected.") |
| 48 | + |
| 49 | + def test_get_transaction_log(self): |
| 50 | + """Test retrieval of transaction log.""" |
| 51 | + self.anin.connect_user("User _1", "secure-token-123") |
| 52 | + self.anin.transfer_with_thought("User _1", "CNC", 50) |
| 53 | + log = self.anin.get_transaction_log() |
| 54 | + self.assertEqual(len(log), 1) |
| 55 | + self.assertEqual(log[0]['user_id'], "User _1") |
| 56 | + |
| 57 | + def test_check_user_status(self): |
| 58 | + """Test checking user connection status.""" |
| 59 | + self.anin.connect_user("User _1", "secure-token-123") |
| 60 | + self.assertTrue(self.anin.check_user_status("User _1")) |
| 61 | + self.anin.disconnect_user("User _1") |
| 62 | + self.assertFalse(self.anin.check_user_status("User _1")) |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + unittest.main() |
0 commit comments