Make the assert methods public.
This commit is contained in:
		
							parent
							
								
									40c255b0d0
								
							
						
					
					
						commit
						0c8a57b6aa
					
				
					 2 changed files with 13 additions and 24 deletions
				
			
		|  | @ -1001,13 +1001,7 @@ class Photo(ObjectBase): | ||||||
|             raise FileNotFoundError(new_filepath.absolute_path) |             raise FileNotFoundError(new_filepath.absolute_path) | ||||||
| 
 | 
 | ||||||
|         if not allow_duplicates: |         if not allow_duplicates: | ||||||
|             try: |             self.photodb.assert_no_such_photo_by_path(filepath=new_filepath) | ||||||
|                 existing = self.photodb.get_photo_by_path(new_filepath) |  | ||||||
|             except exceptions.NoSuchPhoto: |  | ||||||
|                 # Good. |  | ||||||
|                 pass |  | ||||||
|             else: |  | ||||||
|                 raise exceptions.PhotoExists(existing) |  | ||||||
| 
 | 
 | ||||||
|         data = { |         data = { | ||||||
|             'id': self.id, |             'id': self.id, | ||||||
|  | @ -1228,12 +1222,7 @@ class Tag(ObjectBase, GroupableMixin): | ||||||
|         if synname == self.name: |         if synname == self.name: | ||||||
|             raise exceptions.CantSynonymSelf() |             raise exceptions.CantSynonymSelf() | ||||||
| 
 | 
 | ||||||
|         try: |         self.photodb.assert_no_such_tag(name=synname) | ||||||
|             existing_tag = self.photodb.get_tag(name=synname) |  | ||||||
|         except exceptions.NoSuchTag: |  | ||||||
|             pass |  | ||||||
|         else: |  | ||||||
|             raise exceptions.TagExists(existing_tag) |  | ||||||
| 
 | 
 | ||||||
|         self.log.debug('New synonym %s of %s', synname, self.name) |         self.log.debug('New synonym %s of %s', synname, self.name) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -162,7 +162,7 @@ class PDBPhotoMixin: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         super().__init__() |         super().__init__() | ||||||
| 
 | 
 | ||||||
|     def _assert_no_such_photo(self, filepath): |     def assert_no_such_photo_by_path(self, filepath): | ||||||
|         try: |         try: | ||||||
|             existing = self.get_photo_by_path(filepath) |             existing = self.get_photo_by_path(filepath) | ||||||
|         except exceptions.NoSuchPhoto: |         except exceptions.NoSuchPhoto: | ||||||
|  | @ -232,7 +232,7 @@ class PDBPhotoMixin: | ||||||
|             raise FileNotFoundError(filepath.absolute_path) |             raise FileNotFoundError(filepath.absolute_path) | ||||||
| 
 | 
 | ||||||
|         if not allow_duplicates: |         if not allow_duplicates: | ||||||
|             self._assert_no_such_photo(filepath=filepath) |             self.assert_no_such_photo_by_path(filepath=filepath) | ||||||
| 
 | 
 | ||||||
|         self.log.debug('New Photo: %s', filepath.absolute_path) |         self.log.debug('New Photo: %s', filepath.absolute_path) | ||||||
|         author_id = self.get_user_id_or_none(author) |         author_id = self.get_user_id_or_none(author) | ||||||
|  | @ -784,9 +784,9 @@ class PDBTagMixin: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         super().__init__() |         super().__init__() | ||||||
| 
 | 
 | ||||||
|     def _assert_no_such_tag(self, tagname): |     def assert_no_such_tag(self, name): | ||||||
|         try: |         try: | ||||||
|             existing_tag = self.get_tag_by_name(tagname) |             existing_tag = self.get_tag_by_name(name) | ||||||
|         except exceptions.NoSuchTag: |         except exceptions.NoSuchTag: | ||||||
|             return |             return | ||||||
|         else: |         else: | ||||||
|  | @ -861,7 +861,7 @@ class PDBTagMixin: | ||||||
|         Register a new tag and return the Tag object. |         Register a new tag and return the Tag object. | ||||||
|         ''' |         ''' | ||||||
|         tagname = self.normalize_tagname(tagname) |         tagname = self.normalize_tagname(tagname) | ||||||
|         self._assert_no_such_tag(tagname=tagname) |         self.assert_no_such_tag(name=tagname) | ||||||
|         description = objects.Tag.normalize_description(description) |         description = objects.Tag.normalize_description(description) | ||||||
| 
 | 
 | ||||||
|         self.log.debug('New Tag: %s', tagname) |         self.log.debug('New Tag: %s', tagname) | ||||||
|  | @ -897,7 +897,7 @@ class PDBUserMixin: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         super().__init__() |         super().__init__() | ||||||
| 
 | 
 | ||||||
|     def _assert_no_such_user(self, username): |     def assert_no_such_user(self, username): | ||||||
|         try: |         try: | ||||||
|             existing_user = self.get_user(username=username) |             existing_user = self.get_user(username=username) | ||||||
|         except exceptions.NoSuchUser: |         except exceptions.NoSuchUser: | ||||||
|  | @ -905,11 +905,11 @@ class PDBUserMixin: | ||||||
|         else: |         else: | ||||||
|             raise exceptions.UserExists(existing_user) |             raise exceptions.UserExists(existing_user) | ||||||
| 
 | 
 | ||||||
|     def _assert_valid_password(self, password): |     def assert_valid_password(self, password): | ||||||
|         if len(password) < self.config['user']['min_password_length']: |         if len(password) < self.config['user']['min_password_length']: | ||||||
|             raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length']) |             raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length']) | ||||||
| 
 | 
 | ||||||
|     def _assert_valid_username(self, username): |     def assert_valid_username(self, username): | ||||||
|         if len(username) < self.config['user']['min_username_length']: |         if len(username) < self.config['user']['min_username_length']: | ||||||
|             raise exceptions.UsernameTooShort( |             raise exceptions.UsernameTooShort( | ||||||
|                 username=username, |                 username=username, | ||||||
|  | @ -1014,13 +1014,13 @@ class PDBUserMixin: | ||||||
|     @decorators.required_feature('user.new') |     @decorators.required_feature('user.new') | ||||||
|     @decorators.transaction |     @decorators.transaction | ||||||
|     def register_user(self, username, password, *, commit=True): |     def register_user(self, username, password, *, commit=True): | ||||||
|         self._assert_valid_username(username) |         self.assert_valid_username(username) | ||||||
| 
 | 
 | ||||||
|         if not isinstance(password, bytes): |         if not isinstance(password, bytes): | ||||||
|             password = password.encode('utf-8') |             password = password.encode('utf-8') | ||||||
| 
 | 
 | ||||||
|         self._assert_valid_password(password) |         self.assert_valid_password(password) | ||||||
|         self._assert_no_such_user(username=username) |         self.assert_no_such_user(username=username) | ||||||
| 
 | 
 | ||||||
|         self.log.debug('New User: %s', username) |         self.log.debug('New User: %s', username) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue