Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
fix integrational tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Zubov authored and Stanislav Zubov committed Sep 25, 2015
1 parent c2d4dd0 commit ba5a891
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions tests/integrational/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def setUpClass(cls):

from flask import Flask
cls.app = Flask(__name__)
cls.app.sessions = None

from core import db
cls.app.database = db.Database(config.DATABASE)
Expand All @@ -24,24 +25,34 @@ def setUp(self):
self.ctx = self.app.app_context()
self.ctx.push()

def tearDown(self):
self.ctx.pop()

def test_file_deletion(self):
with patch(
'core.utils.init.home_dir', Mock(return_value=config.BASE_DIR)
), patch(
'core.logger.setup_logging', Mock(return_value=Mock())
), patch(
'flask.current_app.sessions', Mock()
), patch(
'core.network.Network', Mock()
), patch(
'core.connection.Virsh', Mock()
):
from vmmaster import cleanup
self.cleanup = cleanup

from core.sessions import Session
self.session = Session()
self.session.status = 'unknown'

session = Session()
session.status = 'unknown'
session.name = '__test_file_deletion'
session.save()
def tearDown(self):
self.ctx.pop()

session_dir = os.path.join(config.SCREENSHOTS_DIR, str(session.id))
def test_file_deletion(self):
self.session.name = '__test_file_deletion'
self.session.save()

session_dir = os.path.join(
config.SCREENSHOTS_DIR, str(self.session.id)
)
system_utils.run_command(
["mkdir", config.SCREENSHOTS_DIR],
silent=True)
Expand All @@ -52,30 +63,20 @@ def test_file_deletion(self):
["touch", os.path.join(session_dir, "file_for_deletion")],
silent=True)

cleanup.delete_session_data([session])
self.cleanup.delete_session_data([self.session])
self.assertEqual(os.path.isdir(session_dir), 0)
system_utils.run_command(
["rm", "-rf", config.SCREENSHOTS_DIR], silent=True)

def test_outdated_sessions(self):
with patch(
'core.utils.init.home_dir', Mock(return_value=config.BASE_DIR)
), patch(
'core.logger.setup_logging', Mock(return_value=Mock())
):
from vmmaster import cleanup
from core.sessions import Session

session = Session()
session.status = 'unknown'
session.closed = True
session.name = '__test_outdated_sessions'
session.created = \
self.session.closed = True
self.session.name = '__test_outdated_sessions'
self.session.created = \
datetime.now() - timedelta(days=config.SCREENSHOTS_DAYS, seconds=1)
session.save()
self.session.save()

outdated_sessions = cleanup.old_sessions()
outdated_sessions = self.cleanup.old_sessions()
outdated_ids = [s.id for s in outdated_sessions]

self.assertIn(session.id, outdated_ids)
cleanup.delete_session_data([session])
self.assertIn(self.session.id, outdated_ids)
self.cleanup.delete_session_data([self.session])

0 comments on commit ba5a891

Please sign in to comment.