| 1 |  |  | # pylint: disable=unused-variable,redefined-outer-name,expression-not-assigned | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | import logging | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | from unittest.mock import Mock | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | import pytest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | from yorm import exceptions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | from yorm import utilities | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | log = logging.getLogger(__name__) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | @pytest.fixture | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | def instance(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     obj = Mock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     obj.__mapper__ = Mock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     obj.__mapper__.attrs = {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     obj.__mapper__.reset_mock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     return obj | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | def describe_update(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     def it_fetches_and_stores(instance): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         utilities.update(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         assert instance.__mapper__.fetch.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         assert instance.__mapper__.store.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     def it_only_stores_when_requested(instance): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         utilities.update(instance, store=False) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         assert instance.__mapper__.fetch.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         assert not instance.__mapper__.store.called | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     def it_only_fetches_when_requested(instance): | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         utilities.update(instance, fetch=False) | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         assert not instance.__mapper__.fetch.called | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         assert instance.__mapper__.store.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     def it_raises_an_exception_with_the_wrong_base(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         instance = Mock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         with pytest.raises(exceptions.MappingError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             utilities.update(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | def describe_update_object(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     def it_fetches(instance): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         utilities.update_object(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         assert instance.__mapper__.fetch.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         assert not instance.__mapper__.store.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     def it_raises_an_exception_with_the_wrong_base(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         instance = Mock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         with pytest.raises(exceptions.MappingError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             utilities.update_object(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | def describe_update_file(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     def it_stores(instance): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         utilities.update_file(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         assert False is instance.__mapper__.fetch.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         assert True is instance.__mapper__.store.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     def it_raises_an_exception_with_the_wrong_base(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         instance = Mock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         with pytest.raises(exceptions.MappingError): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             utilities.update_file(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     def it_only_stores_with_auto_on(instance): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         instance.__mapper__.auto = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         utilities.update_file(instance, force=False) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         assert False is instance.__mapper__.fetch.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         assert False is instance.__mapper__.store.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     def it_creates_missing_files(instance): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         instance.__mapper__.exists = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         utilities.update_file(instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         assert False is instance.__mapper__.fetch.called | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         assert True is instance.__mapper__.create.called | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 94 |  |  |         assert True is instance.__mapper__.store.called | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |  |