| 
									
										
										
										
											2024-07-11 12:55:55 -05:00
										 |  |  | # -*- coding: utf-8; -*- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from unittest import TestCase | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							| 
									
										
										
										
											2025-01-25 16:26:14 -06:00
										 |  |  |     import sqlalchemy as sa | 
					
						
							|  |  |  |     from sqlalchemy import orm | 
					
						
							| 
									
										
										
										
											2024-08-30 20:30:09 -05:00
										 |  |  |     from wuttjamaican.db.model import base as mod | 
					
						
							| 
									
										
										
										
											2024-07-14 15:47:39 -05:00
										 |  |  |     from wuttjamaican.db.model.auth import User | 
					
						
							| 
									
										
										
										
											2024-07-11 12:55:55 -05:00
										 |  |  | except ImportError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 16:26:14 -06:00
										 |  |  |     class MockUser(mod.Base): | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |         __tablename__ = "mock_user" | 
					
						
							|  |  |  |         uuid = mod.uuid_column(sa.ForeignKey("user.uuid"), default=False) | 
					
						
							| 
									
										
										
										
											2025-01-25 16:26:14 -06:00
										 |  |  |         user = orm.relationship( | 
					
						
							|  |  |  |             User, | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |             backref=orm.backref("_mock", uselist=False, cascade="all, delete-orphan"), | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2025-01-25 16:26:14 -06:00
										 |  |  |         favorite_color = sa.Column(sa.String(length=100), nullable=False) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class TestWuttaModelBase(TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def test_make_proxy(self): | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |             self.assertFalse(hasattr(User, "favorite_color")) | 
					
						
							|  |  |  |             MockUser.make_proxy(User, "_mock", "favorite_color") | 
					
						
							|  |  |  |             self.assertTrue(hasattr(User, "favorite_color")) | 
					
						
							|  |  |  |             user = User(favorite_color="green") | 
					
						
							|  |  |  |             self.assertEqual(user.favorite_color, "green") | 
					
						
							| 
									
										
										
										
											2025-01-25 16:26:14 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-11 12:55:55 -05:00
										 |  |  |     class TestSetting(TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def test_basic(self): | 
					
						
							| 
									
										
										
										
											2024-08-30 20:30:09 -05:00
										 |  |  |             setting = mod.Setting() | 
					
						
							| 
									
										
										
										
											2024-07-11 12:55:55 -05:00
										 |  |  |             self.assertEqual(str(setting), "") | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |             setting.name = "foo" | 
					
						
							| 
									
										
										
										
											2024-07-11 12:55:55 -05:00
										 |  |  |             self.assertEqual(str(setting), "foo") | 
					
						
							| 
									
										
										
										
											2024-07-14 15:47:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     class TestPerson(TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def test_basic(self): | 
					
						
							| 
									
										
										
										
											2024-08-30 20:30:09 -05:00
										 |  |  |             person = mod.Person() | 
					
						
							| 
									
										
										
										
											2024-07-14 15:47:39 -05:00
										 |  |  |             self.assertEqual(str(person), "") | 
					
						
							|  |  |  |             person.full_name = "Barney Rubble" | 
					
						
							|  |  |  |             self.assertEqual(str(person), "Barney Rubble") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def test_users(self): | 
					
						
							| 
									
										
										
										
											2024-08-30 20:30:09 -05:00
										 |  |  |             person = mod.Person() | 
					
						
							| 
									
										
										
										
											2024-07-14 15:47:39 -05:00
										 |  |  |             self.assertIsNone(person.user) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             user = User() | 
					
						
							|  |  |  |             person.users.append(user) | 
					
						
							|  |  |  |             self.assertIs(person.user, user) |