<s> import mock <EOL> from datetime import datetime , timedelta <EOL> from nose . tools import * <EOL> from tests . base import OsfTestCase <EOL> from tests . utils import mock_archive <EOL> from tests . factories import ( <EOL> AuthUserFactory , <EOL> NodeFactory , <EOL> ) <EOL> from framework . auth import Auth <EOL> from website . project . sanctions import Sanction , EmbargoTerminationApproval <EOL> from scripts . approve_embargo_terminations import main , get_pending_embargo_termination_requests <EOL> class TestApproveEmbargoTerminations ( OsfTestCase ) : <EOL> def tearDown ( self ) : <EOL> with mock . patch ( '<STR_LIT>' , mock . Mock ( return_value = None ) ) : <EOL> super ( TestApproveEmbargoTerminations , self ) . tearDown ( ) <EOL> @ mock . patch ( '<STR_LIT>' , mock . Mock ( ) ) <EOL> def setUp ( self ) : <EOL> super ( TestApproveEmbargoTerminations , self ) . setUp ( ) <EOL> self . user = AuthUserFactory ( ) <EOL> self . node = NodeFactory ( creator = self . user ) <EOL> NodeFactory ( <EOL> creator = self . user , <EOL> parent = NodeFactory ( creator = self . user , parent = self . node ) <EOL> ) <EOL> with mock_archive ( self . node , embargo = True , autoapprove = True ) as registration : <EOL> registration . request_embargo_termination ( auth = Auth ( self . user ) ) <EOL> self . registration1 = registration <EOL> with mock_archive ( self . node , embargo = True , autoapprove = True ) as registration : <EOL> old_time = datetime . now ( ) - timedelta ( days = <NUM_LIT:5> ) <EOL> approval = registration . request_embargo_termination ( auth = Auth ( self . user ) ) <EOL> EmbargoTerminationApproval . _storage [ <NUM_LIT:0> ] . store . update ( <EOL> { '<STR_LIT>' : approval . _id } , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : old_time } } , <EOL> ) <EOL> self . registration2 = registration <EOL> with mock_archive ( self . node , embargo = True , autoapprove = True ) as registration : <EOL> old_time = datetime . now ( ) - timedelta ( days = <NUM_LIT:5> ) <EOL> approval = registration . request_embargo_termination ( auth = Auth ( self . user ) ) <EOL> EmbargoTerminationApproval . _storage [ <NUM_LIT:0> ] . store . update ( <EOL> { '<STR_LIT>' : approval . _id } , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : old_time } } , <EOL> ) <EOL> approval . state = Sanction . APPROVED <EOL> approval . save ( ) <EOL> self . registration3 = registration <EOL> with mock_archive ( self . node , embargo = True , autoapprove = True ) as registration : <EOL> self . registration4 = registration <EOL> EmbargoTerminationApproval . _clear_caches ( ) <EOL> def test_get_pending_embargo_termination_requests_returns_only_unapproved ( self ) : <EOL> targets = get_pending_embargo_termination_requests ( ) <EOL> assert_equal ( len ( targets ) , <NUM_LIT:1> ) <EOL> assert_equal ( targets [ <NUM_LIT:0> ] . _id , self . registration2 . embargo_termination_approval . _id ) <EOL> def test_main_auto_approves_embargo_termination_request ( self ) : <EOL> for node in self . registration2 . node_and_primary_descendants ( ) : <EOL> assert_false ( node . is_public ) <EOL> assert_true ( node . is_embargoed ) <EOL> main ( ) <EOL> for node in self . registration2 . node_and_primary_descendants ( ) : <EOL> assert_true ( node . is_public ) <EOL> assert_false ( node . is_embargoed ) </s>
