def test_deferred_action_times_out(sql_alchemy_fixture, deferred_action_fixture): """If all its Requirements are not fulfilled before its deadline has been reached, a DeferredAction executes its deadline action; then, it and its Requirements are deleted""" fixture = deferred_action_fixture with sql_alchemy_fixture.persistent_test_classes(fixture.MyDeferredAction, fixture.SomeObject): requirements = [Requirement(), Requirement(), Requirement()] deferred_action = fixture.MyDeferredAction(fixture.one_object, requirements=requirements, deadline=fixture.future_time) Session.add(deferred_action) Session.flush() assert deferred_action.deadline == fixture.future_time ReahlEgg.do_daily_maintenance_for_egg('reahl-domain') assert not fixture.one_object.deadline_flag assert not fixture.another_object.deadline_flag assert Session.query(Requirement).count() == 3 assert Session.query(DeferredAction).count() == 1 deferred_action.deadline = fixture.past_time ReahlEgg.do_daily_maintenance_for_egg('reahl-domain') assert fixture.one_object.deadline_flag assert not fixture.another_object.deadline_flag assert Session.query(Requirement).count() == 0 assert Session.query(DeferredAction).count() == 0
def test_expire_stale_requests(reahl_system_fixture, party_account_fixture): fixture = party_account_fixture old_email = '*****@*****.**' recent_email = '*****@*****.**' password = '******' mailer_stub = fixture.mailer EmailAndPasswordSystemAccount.mailer = mailer_stub longago = datetime.now() - timedelta( reahl_system_fixture.config.accounts.request_verification_timeout) old_account_management_interface = AccountManagementInterface() old_account_management_interface.email = old_email old_account_management_interface.password = password old_account_management_interface.register() old_system_account = EmailAndPasswordSystemAccount.by_email(old_email) old_activation_request = Session.query(VerifyEmailRequest).one() old_activation_request.deferred_actions[0].deadline = longago new_account_management_interface = AccountManagementInterface() new_account_management_interface.email = recent_email new_account_management_interface.password = password new_account_management_interface.register() recent_system_account = EmailAndPasswordSystemAccount.by_email( recent_email) ReahlEgg.do_daily_maintenance_for_egg('reahl-domain') assert Session.query(EmailAndPasswordSystemAccount).filter_by( id=old_system_account.id).count() == 0 assert Session.query(EmailAndPasswordSystemAccount).filter_by( id=recent_system_account.id).count() == 1
def test_deferred_action_times_out_with_shared_requirements( sql_alchemy_fixture, deferred_action_fixture): """If a DeferredAction times out, it will not nuke Requirements shared with another DeferredAction.""" fixture = deferred_action_fixture with sql_alchemy_fixture.persistent_test_classes(fixture.MyDeferredAction, fixture.SomeObject): requirements1 = [Requirement()] requirements2 = [Requirement(), Requirement()] deferred_action1 = fixture.MyDeferredAction( fixture.one_object, requirements=requirements2, deadline=fixture.future_time) Session.add(deferred_action1) deferred_action2 = fixture.MyDeferredAction( fixture.another_object, requirements=requirements1 + requirements2, deadline=fixture.future_time) Session.add(deferred_action2) Session.flush() # If one DeferredAction times out, the remaining one and its Requirements are left intact deferred_action1.deadline = fixture.past_time ReahlEgg.do_daily_maintenance_for_egg('reahl-domain') assert fixture.one_object.deadline_flag assert not fixture.another_object.deadline_flag assert Session.query(Requirement).count() == 3 assert Session.query(DeferredAction).count() == 1 for requirement in requirements1 + requirements2: assert set(requirement.deferred_actions) == {deferred_action2} # When no more DeferredActions are held onto by Requirements, those Requirements are deleted deferred_action2.deadline = fixture.past_time ReahlEgg.do_daily_maintenance_for_egg('reahl-domain') assert fixture.one_object.deadline_flag assert fixture.another_object.deadline_flag assert Session.query(Requirement).count() == 0 assert Session.query(DeferredAction).count() == 0
def do_daily_maintenance(self): """Runs the all the scheduled jobs relevant to the current system.""" with self.orm_control.managed_transaction() as transaction: ReahlEgg.do_daily_maintenance_for_egg( self.config.reahlsystem.root_egg)
def do_daily_maintenance(self): with self.orm_control.managed_transaction() as transaction: ReahlEgg.do_daily_maintenance_for_egg(self.config.reahlsystem.root_egg)