| 
									
										
										
										
											2024-08-27 21:11:44 -05:00
										 |  |  | # -*- coding: utf-8; -*- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from unittest.mock import patch, MagicMock | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import pytest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from wuttaweb.db import continuum as mod | 
					
						
							| 
									
										
										
										
											2025-01-06 16:47:48 -06:00
										 |  |  | from wuttaweb.testing import WebTestCase | 
					
						
							| 
									
										
										
										
											2024-08-27 21:11:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestWuttaWebContinuumPlugin(WebTestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2025-08-31 12:26:43 -05:00
										 |  |  |         if not hasattr(mod, "WuttaWebContinuumPlugin"): | 
					
						
							| 
									
										
										
										
											2024-08-27 21:11:44 -05:00
										 |  |  |             pytest.skip("test not relevant without sqlalchemy-continuum") | 
					
						
							|  |  |  |         self.setup_web() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def make_plugin(self): | 
					
						
							|  |  |  |         return mod.WuttaWebContinuumPlugin() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_get_remote_addr(self): | 
					
						
							|  |  |  |         plugin = self.make_plugin() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 12:26:43 -05:00
										 |  |  |         with patch.object(mod, "get_current_request", return_value=None): | 
					
						
							| 
									
										
										
										
											2024-08-27 21:11:44 -05:00
										 |  |  |             self.assertIsNone(plugin.get_remote_addr(None, self.session)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 12:26:43 -05:00
										 |  |  |         self.request.client_addr = "127.0.0.1" | 
					
						
							|  |  |  |         self.assertEqual(plugin.get_remote_addr(None, self.session), "127.0.0.1") | 
					
						
							| 
									
										
										
										
											2024-08-27 21:11:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_get_user_id(self): | 
					
						
							|  |  |  |         plugin = self.make_plugin() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 12:26:43 -05:00
										 |  |  |         with patch.object(mod, "get_current_request", return_value=None): | 
					
						
							| 
									
										
										
										
											2024-08-27 21:11:44 -05:00
										 |  |  |             self.assertIsNone(plugin.get_user_id(None, self.session)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 12:26:43 -05:00
										 |  |  |         self.request.user = MagicMock(uuid="some-random-uuid") | 
					
						
							|  |  |  |         self.assertEqual(plugin.get_user_id(None, self.session), "some-random-uuid") |