<s> from changes . config import db <EOL> from changes . testutils . cases import TestCase <EOL> from changes . models import ProjectOption , Snapshot , SnapshotImage , SnapshotStatus <EOL> class TestSnapshotTestCase ( TestCase ) : <EOL> def test_snapshot_change_status ( self ) : <EOL> project = self . create_project ( ) <EOL> plan_1 = self . create_plan ( project ) <EOL> plan_2 = self . create_plan ( project ) <EOL> snapshot = self . create_snapshot ( project , status = SnapshotStatus . pending ) <EOL> snapshot_image_1 = self . create_snapshot_image ( snapshot , plan_1 ) <EOL> snapshot_image_2 = self . create_snapshot_image ( snapshot , plan_2 ) <EOL> assert Snapshot . query . get ( snapshot . id ) . status == SnapshotStatus . pending <EOL> snapshot_image_1 . change_status ( SnapshotStatus . active ) <EOL> assert Snapshot . query . get ( snapshot . id ) . status == SnapshotStatus . pending <EOL> snapshot_image_2 . change_status ( SnapshotStatus . active ) <EOL> assert Snapshot . query . get ( snapshot . id ) . status == SnapshotStatus . active <EOL> def test_snapshot_invalidated ( self ) : <EOL> project = self . create_project ( ) <EOL> plan_1 = self . create_plan ( project ) <EOL> plan_2 = self . create_plan ( project ) <EOL> snapshot = self . create_snapshot ( project , status = SnapshotStatus . pending ) <EOL> snapshot_image_1 = self . create_snapshot_image ( snapshot , plan_1 ) <EOL> snapshot_image_2 = self . create_snapshot_image ( snapshot , plan_2 ) <EOL> snapshot_image_1 . change_status ( SnapshotStatus . active ) <EOL> snapshot_image_2 . change_status ( SnapshotStatus . active ) <EOL> snapshot_image_1 . change_status ( SnapshotStatus . invalidated ) <EOL> assert Snapshot . query . get ( snapshot . id ) . status == SnapshotStatus . invalidated <EOL> def test_snapshot_failed ( self ) : <EOL> project = self . create_project ( ) <EOL> plan_1 = self . create_plan ( project ) <EOL> plan_2 = self . create_plan ( project ) <EOL> snapshot = self . create_snapshot ( project , status = SnapshotStatus . failed ) <EOL> snapshot_image_1 = self . create_snapshot_image ( snapshot , plan_1 ) <EOL> snapshot_image_2 = self . create_snapshot_image ( snapshot , plan_2 ) <EOL> snapshot_image_1 . change_status ( SnapshotStatus . active ) <EOL> snapshot_image_2 . change_status ( SnapshotStatus . active ) <EOL> assert Snapshot . query . get ( snapshot . id ) . status == SnapshotStatus . failed <EOL> class TestSnapshotImageTestCase ( TestCase ) : <EOL> def test_get_snapshot_image_independent ( self ) : <EOL> project = self . create_project ( ) <EOL> plan = self . create_plan ( project ) <EOL> snapshot = self . create_snapshot ( project ) <EOL> db . session . add ( ProjectOption ( <EOL> project_id = project . id , <EOL> name = '<STR_LIT>' , <EOL> value = snapshot . id . hex , <EOL> ) ) <EOL> snapshot_image = self . create_snapshot_image ( snapshot , plan ) <EOL> assert snapshot_image == SnapshotImage . get ( plan , snapshot . id ) <EOL> def test_get_snapshot_image_dependent ( self ) : <EOL> project = self . create_project ( ) <EOL> plan_1 = self . create_plan ( project ) <EOL> plan_2 = self . create_plan ( project ) <EOL> plan_1 . snapshot_plan_id = plan_2 . id <EOL> snapshot = self . create_snapshot ( project ) <EOL> db . session . add ( ProjectOption ( <EOL> project_id = project . id , <EOL> name = '<STR_LIT>' , <EOL> value = snapshot . id . hex , <EOL> ) ) <EOL> snapshot_image_1 = self . create_snapshot_image ( snapshot , plan_1 ) <EOL> snapshot_image_2 = self . create_snapshot_image ( snapshot , plan_2 ) <EOL> assert snapshot_image_2 == SnapshotImage . get ( plan_1 , snapshot . id ) <EOL> assert snapshot_image_2 == SnapshotImage . get ( plan_2 , snapshot . id ) <EOL> def test_get_snapshot_image_given_snapshot ( self ) : <EOL> project = self . create_project ( ) <EOL> plan = self . create_plan ( project ) <EOL> snapshot = self . create_snapshot ( project ) <EOL> current_snapshot = self . create_snapshot ( project ) <EOL> db . session . add ( ProjectOption ( <EOL> project_id = project . id , <EOL> name = '<STR_LIT>' , <EOL> value = current_snapshot . id . hex , <EOL> ) ) <EOL> snapshot_image = self . create_snapshot_image ( snapshot , plan ) <EOL> current_snapshot_image = self . create_snapshot_image ( current_snapshot , plan ) <EOL> assert snapshot_image == SnapshotImage . get ( plan , snapshot . id ) <EOL> assert current_snapshot_image == SnapshotImage . get ( plan , current_snapshot . id ) </s>
