Esempio n. 1
0
    def test_disable_users_jobs_extended(self):
        """Test disable extended users jobs works."""
        users = UserFactory.create_batch(1, email_addr='*****@*****.**')
        date_old = (datetime.datetime.utcnow() -
                    datetime.timedelta(91)).isoformat()
        users += UserFactory.create_batch(1,
                                          email_addr='*****@*****.**',
                                          created=date_old,
                                          last_login=date_old)
        users += UserFactory.create_batch(1,
                                          email_addr='*****@*****.**',
                                          created=date_old,
                                          last_login=date_old)
        ext_date_old = (datetime.datetime.utcnow() -
                        datetime.timedelta(300)).isoformat()
        users += UserFactory.create_batch(1,
                                          email_addr='*****@*****.**',
                                          created=ext_date_old,
                                          last_login=ext_date_old)

        patch_dict = {
            'STALE_USERS_MONTHS': 3,
            'EXTENDED_STALE_USERS_MONTHS': 9,
            'EXTENDED_STALE_USERS_DOMAINS': ['extended.com']
        }

        with patch.dict(self.flask_app.config, patch_dict):
            disable_users_job()

        assert users[0].enabled, 'recent user should be enabled'
        assert not users[1].enabled, 'stale user should be disabled'
        assert users[2].enabled, 'recent extended user should be enabled'
        assert users[3].enabled, 'stale extended user should be enabled'
    def test_disable_users_jobs(self):
        """Test disable users jobs works."""
        users = UserFactory.create_batch(3)
        res = disable_users_job()
        assert users[0].enabled and users[1].enabled \
            and users[2].enabled, "Users created recently shouldn't be disabled"

        date_old = (datetime.datetime.utcnow() -
                    datetime.timedelta(100)).isoformat()
        old_users = UserFactory.create_batch(2,
                                             created=date_old,
                                             last_login=date_old)
        res = disable_users_job()
        assert users[0].enabled and users[1].enabled \
            and users[2].enabled and not old_users[0].enabled \
            and not old_users[1].enabled, "Only users not logged in > 90 days should be disabled"