<s> """<STR_LIT>""" <EOL> import datetime <EOL> from mock import patch <EOL> from tests import case <EOL> class MTModelTestCase ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . user = self . F . UserFactory . create ( ) <EOL> class UserDeleteTest ( MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_delete_created_by_sets_null ( self ) : <EOL> """<STR_LIT>""" <EOL> u = self . F . UserFactory ( ) <EOL> p = self . F . ProductFactory ( user = u ) <EOL> u . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . created_by , None ) <EOL> def test_delete_modified_by_sets_null ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> u = self . F . UserFactory ( ) <EOL> p . save ( user = u ) <EOL> u . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_by , None ) <EOL> def test_delete_deleted_by_sets_null ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> u = self . F . UserFactory ( ) <EOL> p . delete ( user = u ) <EOL> u . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_by , None ) <EOL> class MTModelMockNowTestCase ( MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( MTModelMockNowTestCase , self ) . setUp ( ) <EOL> self . utcnow = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> patcher = patch ( "<STR_LIT>" ) <EOL> self . mock_utcnow = patcher . start ( ) . datetime . utcnow <EOL> self . mock_utcnow . return_value = self . utcnow <EOL> self . addCleanup ( patcher . stop ) <EOL> class CreateTest ( MTModelMockNowTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_created_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( p . created_by , None ) <EOL> def test_created_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" , user = self . user ) <EOL> self . assertEqual ( p . created_by , self . user ) <EOL> def test_new_modified_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( p . modified_by , None ) <EOL> def test_new_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" , user = self . user ) <EOL> self . assertEqual ( p . modified_by , self . user ) <EOL> def test_created_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( p . created_on , self . utcnow ) <EOL> def test_new_modified_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( p . modified_on , self . utcnow ) <EOL> class SaveTest ( MTModelMockNowTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_created_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product ( name = "<STR_LIT>" ) <EOL> p . save ( ) <EOL> self . assertEqual ( p . created_by , None ) <EOL> def test_created_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product ( name = "<STR_LIT>" ) <EOL> p . save ( user = self . user ) <EOL> self . assertEqual ( p . created_by , self . user ) <EOL> def test_new_modified_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product ( name = "<STR_LIT>" ) <EOL> p . save ( ) <EOL> self . assertEqual ( p . modified_by , None ) <EOL> def test_new_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product ( name = "<STR_LIT>" ) <EOL> p . save ( user = self . user ) <EOL> self . assertEqual ( p . modified_by , self . user ) <EOL> def test_created_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product ( name = "<STR_LIT>" ) <EOL> p . save ( ) <EOL> self . assertEqual ( p . created_on , self . utcnow ) <EOL> def test_new_modified_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product ( name = "<STR_LIT>" ) <EOL> p . save ( ) <EOL> self . assertEqual ( p . modified_on , self . utcnow ) <EOL> def test_modified_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" , user = self . user ) <EOL> p . save ( ) <EOL> self . assertEqual ( p . modified_by , None ) <EOL> def test_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> p . save ( user = self . user ) <EOL> self . assertEqual ( p . modified_by , self . user ) <EOL> def test_modified_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> new_now = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:0> ) <EOL> self . mock_utcnow . return_value = new_now <EOL> p . save ( ) <EOL> self . assertEqual ( p . modified_on , new_now ) <EOL> def test_notrack_modified_on ( self ) : <EOL> """<STR_LIT>""" <EOL> self . mock_utcnow . return_value = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . mock_utcnow . return_value = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> p . save ( notrack = True ) <EOL> self . assertEqual ( <EOL> self . refresh ( p ) . modified_on , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> def test_notrack_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" , user = self . user ) <EOL> p . save ( notrack = True ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_by , self . user ) <EOL> class UpdateTest ( MTModelMockNowTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_modified_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" , user = self . user ) <EOL> self . model . Product . objects . update ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_by , None ) <EOL> def test_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . model . Product . objects . update ( name = "<STR_LIT>" , user = self . user ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_by , self . user ) <EOL> def test_modified_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> new_now = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:0> ) <EOL> self . mock_utcnow . return_value = new_now <EOL> self . model . Product . objects . update ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_on , new_now ) <EOL> def test_notrack_modified_on ( self ) : <EOL> """<STR_LIT>""" <EOL> self . mock_utcnow . return_value = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" ) <EOL> self . mock_utcnow . return_value = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . model . Product . objects . update ( name = "<STR_LIT:bar>" , notrack = True ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_on , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> def test_notrack_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . model . Product . objects . create ( name = "<STR_LIT>" , user = self . user ) <EOL> self . model . Product . objects . update ( name = "<STR_LIT:bar>" , notrack = True ) <EOL> self . assertEqual ( self . refresh ( p ) . modified_by , self . user ) <EOL> class DeleteTest ( MTModelMockNowTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_queryset_deleted_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> self . model . Product . objects . all ( ) . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_by , None ) <EOL> def test_queryset_deleted_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> self . model . Product . objects . all ( ) . delete ( user = self . user ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_by , self . user ) <EOL> def test_queryset_deleted_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> self . model . Product . objects . all ( ) . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_on , self . utcnow ) <EOL> def test_deleted_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_by , None ) <EOL> def test_deleted_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p . delete ( user = self . user ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_by , self . user ) <EOL> def test_deleted_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p . delete ( ) <EOL> self . assertEqual ( self . refresh ( p ) . deleted_on , self . utcnow ) <EOL> class HardDeleteTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p . delete ( permanent = True ) <EOL> self . assertEqual ( self . model . Product . _base_manager . count ( ) , <NUM_LIT:0> ) <EOL> def test_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . F . ProductFactory . create ( ) <EOL> self . model . Product . objects . all ( ) . delete ( permanent = True ) <EOL> self . assertEqual ( self . model . Product . _base_manager . count ( ) , <NUM_LIT:0> ) <EOL> class CascadeDeleteTest ( MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_queryset_deleted_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> self . model . Product . objects . all ( ) . delete ( ) <EOL> self . assertEqual ( self . refresh ( s ) . deleted_by , None ) <EOL> def test_queryset_deleted_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> self . model . Product . objects . all ( ) . delete ( user = self . user ) <EOL> self . assertEqual ( self . refresh ( s ) . deleted_by , self . user ) <EOL> def test_queryset_deleted_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> self . model . Product . objects . all ( ) . delete ( ) <EOL> p = self . refresh ( p ) <EOL> s = self . refresh ( s ) <EOL> self . assertIsNot ( p . deleted_on , None ) <EOL> self . assertEqual ( s . deleted_on , p . deleted_on ) <EOL> def test_deleted_by_none ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> p . delete ( ) <EOL> self . assertEqual ( self . refresh ( s ) . deleted_by , None ) <EOL> def test_deleted_by ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> p . delete ( user = self . user ) <EOL> self . assertEqual ( self . refresh ( s ) . deleted_by , self . user ) <EOL> def test_deleted_on ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> p . delete ( ) <EOL> p = self . refresh ( p ) <EOL> s = self . refresh ( s ) <EOL> self . assertIsNot ( p . deleted_on , None ) <EOL> self . assertEqual ( s . deleted_on , p . deleted_on ) <EOL> def test_no_cascade_redelete ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> with patch ( "<STR_LIT>" ) as mock_dt : <EOL> mock_dt . datetime . utcnow . return_value = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> ) <EOL> s . delete ( ) <EOL> mock_dt . datetime . utcnow . return_value = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> ) <EOL> p . delete ( ) <EOL> self . assertNotEqual ( <EOL> self . refresh ( s ) . deleted_on , self . refresh ( p ) . deleted_on ) <EOL> class UndeleteMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def assertNotDeleted ( self , obj ) : <EOL> self . assertEqual ( obj . deleted_on , None ) <EOL> self . assertEqual ( obj . deleted_by , None ) <EOL> class UndeleteTest ( UndeleteMixin , MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p . delete ( ) <EOL> p . undelete ( ) <EOL> self . assertNotDeleted ( p ) <EOL> def test_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> p . delete ( ) <EOL> self . model . Product . everything . all ( ) . undelete ( ) <EOL> self . assertNotDeleted ( self . refresh ( p ) ) <EOL> class CascadeUndeleteTest ( UndeleteMixin , MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> p . delete ( ) <EOL> p = self . refresh ( p ) <EOL> p . undelete ( ) <EOL> self . assertNotDeleted ( self . refresh ( s ) ) <EOL> def test_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> p . delete ( ) <EOL> self . model . Product . everything . all ( ) . undelete ( ) <EOL> self . assertNotDeleted ( self . refresh ( s ) ) <EOL> def test_cascade_limited ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> s = self . F . SuiteFactory . create ( product = p ) <EOL> with patch ( "<STR_LIT>" ) as mock_dt : <EOL> mock_dt . datetime . utcnow . return_value = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> ) <EOL> s . delete ( ) <EOL> mock_dt . datetime . utcnow . return_value = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> ) <EOL> p . delete ( ) <EOL> self . refresh ( p ) . undelete ( ) <EOL> self . assertIsNot ( self . refresh ( s ) . deleted_on , None ) <EOL> class CloneTest ( UndeleteMixin , MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_cascade_non_m2m_or_reverse_fk ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory . create ( ) <EOL> with self . assertRaises ( ValueError ) : <EOL> p . clone ( cascade = [ "<STR_LIT:name>" ] ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_updates_created_on ( self , mock_dt ) : <EOL> """<STR_LIT>""" <EOL> mock_dt . datetime . utcnow . return_value = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:30> ) <EOL> p = self . F . ProductFactory . create ( ) <EOL> cloned_on = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> ) <EOL> mock_dt . datetime . utcnow . return_value = cloned_on <EOL> new = p . clone ( ) <EOL> self . assertEqual ( new . created_on , cloned_on ) <EOL> def test_updates_created_by ( self ) : <EOL> """<STR_LIT>""" <EOL> u1 = self . F . UserFactory . create ( ) <EOL> p = self . F . ProductFactory . create ( user = u1 ) <EOL> u2 = self . F . UserFactory . create ( ) <EOL> new = p . clone ( user = u2 ) <EOL> self . assertEqual ( new . created_by , u2 ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_updates_modified_on ( self , mock_dt ) : <EOL> """<STR_LIT>""" <EOL> mock_dt . datetime . utcnow . return_value = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:30> ) <EOL> p = self . F . ProductFactory . create ( ) <EOL> cloned_on = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> ) <EOL> mock_dt . datetime . utcnow . return_value = cloned_on <EOL> new = p . clone ( ) <EOL> self . assertEqual ( new . modified_on , cloned_on ) <EOL> def test_updates_modified_by ( self ) : <EOL> """<STR_LIT>""" <EOL> u1 = self . F . UserFactory . create ( ) <EOL> p = self . F . ProductFactory . create ( user = u1 ) <EOL> u2 = self . F . UserFactory . create ( ) <EOL> new = p . clone ( user = u2 ) <EOL> self . assertEqual ( new . modified_by , u2 ) <EOL> class MTManagerTest ( MTModelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_objects_doesnt_include_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> p1 = self . F . ProductFactory . create ( ) <EOL> p2 = self . F . ProductFactory . create ( ) <EOL> p2 . delete ( ) <EOL> self . assertEqual ( set ( self . model . Product . objects . all ( ) ) , set ( [ p1 ] ) ) <EOL> def test_everything_does_include_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> p1 = self . F . ProductFactory . create ( ) <EOL> p2 = self . F . ProductFactory . create ( ) <EOL> p2 . delete ( ) <EOL> self . assertEqual ( <EOL> set ( self . model . Product . everything . all ( ) ) , set ( [ p1 , p2 ] ) ) <EOL> def test_everything_is_default_manager ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIs ( <EOL> self . model . Product . _default_manager , self . model . Product . everything ) <EOL> def test_related_managers_dont_include_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> pv1 = self . F . ProductVersionFactory . create ( version = "<STR_LIT>" ) <EOL> pv2 = self . F . ProductVersionFactory . create ( product = pv1 . product ) <EOL> pv2 . delete ( ) <EOL> self . assertEqual ( set ( pv1 . product . versions . all ( ) ) , set ( [ pv1 ] ) ) <EOL> class TeamModelTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def TeamModel ( self ) : <EOL> from moztrap . model . mtmodel import TeamModel <EOL> return TeamModel <EOL> def test_parent ( self ) : <EOL> """<STR_LIT>""" <EOL> t = self . TeamModel ( ) <EOL> self . assertIsNone ( t . parent ) <EOL> class DraftStatusModelTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_activate ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> r . activate ( ) <EOL> self . assertEqual ( self . refresh ( r ) . status , "<STR_LIT>" ) <EOL> def test_draft ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> r . draft ( ) <EOL> self . assertEqual ( self . refresh ( r ) . status , "<STR_LIT>" ) <EOL> def test_deactivate ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> r . deactivate ( ) <EOL> self . assertEqual ( self . refresh ( r ) . status , "<STR_LIT>" ) <EOL> def test_activate_by_user ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> u = self . F . UserFactory . create ( ) <EOL> r . activate ( user = u ) <EOL> self . assertEqual ( self . refresh ( r ) . modified_by , u ) <EOL> def test_draft_by_user ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> u = self . F . UserFactory . create ( ) <EOL> r . draft ( user = u ) <EOL> self . assertEqual ( self . refresh ( r ) . modified_by , u ) <EOL> def test_deactivate_by_user ( self ) : <EOL> """<STR_LIT>""" <EOL> r = self . F . RunFactory . create ( status = "<STR_LIT>" ) <EOL> u = self . F . UserFactory . create ( ) <EOL> r . deactivate ( user = u ) <EOL> self . assertEqual ( self . refresh ( r ) . modified_by , u ) <EOL> class NotDeletedCountTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def NotDeletedCount ( self ) : <EOL> """<STR_LIT>""" <EOL> from moztrap . model . mtmodel import NotDeletedCount <EOL> return NotDeletedCount <EOL> def test_counts_not_deleted ( self ) : <EOL> """<STR_LIT>""" <EOL> pv = self . F . ProductVersionFactory . create ( ) <EOL> self . F . ProductVersionFactory . create ( product = pv . product ) <EOL> pv . delete ( ) <EOL> p = self . model . Product . objects . annotate ( <EOL> num_versions = self . NotDeletedCount ( "<STR_LIT>" ) ) . get ( ) <EOL> self . assertEqual ( p . num_versions , <NUM_LIT:1> ) <EOL> def test_aggregate_annotation ( self ) : <EOL> """<STR_LIT>""" <EOL> from django . db . models import Count <EOL> pv1 = self . F . ProductVersionFactory . create ( ) <EOL> self . F . ProductVersionFactory . create ( ) <EOL> pv1 . product . delete ( ) <EOL> res = self . model . Product . everything . annotate ( <EOL> num_versions = Count ( "<STR_LIT>" ) ) . aggregate ( <EOL> products_with_versions = self . NotDeletedCount ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( res , { "<STR_LIT>" : <NUM_LIT:1> } ) <EOL> class OptimisticLockingTest ( case . DBTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_concurrency_error ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> p2 = self . model . Product . objects . get ( ) <EOL> p2 . name = "<STR_LIT>" <EOL> p2 . save ( ) <EOL> p . name = "<STR_LIT>" <EOL> with self . assertRaises ( self . model . ConcurrencyError ) : <EOL> p . save ( ) <EOL> def test_queryset_update_increments_version ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . F . ProductFactory ( ) <EOL> self . model . Product . objects . update ( name = "<STR_LIT>" ) <EOL> p . name = "<STR_LIT>" <EOL> with self . assertRaises ( self . model . ConcurrencyError ) : <EOL> p . save ( ) </s>
