File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -45,5 +45,34 @@ class Meta:
4545 'list' : {
4646 'methods' : ['post' , 'get' ],
4747 'path' : '/backups/full/' ,
48+ },
49+ }
50+
51+ def schedule_restore (self ):
52+ restore = Restore (backup = self .id ).save ()
53+ return restore
54+
55+
56+ class Restore (Model ):
57+
58+ author = fields .ModelField ('Admin' )
59+ status = fields .StringField (read_only = True )
60+ status_info = fields .StringField (read_only = True )
61+ updated_at = fields .DateTimeField (read_only = True , required = False )
62+ created_at = fields .DateTimeField (read_only = True , required = False )
63+ links = fields .LinksField ()
64+ backup = fields .StringField ()
65+ archive = fields .StringField (read_only = True )
66+
67+ class Meta :
68+ parent = Instance
69+ endpoints = {
70+ 'list' : {
71+ 'methods' : ['get' , 'post' ],
72+ 'path' : '/restores/' ,
73+ },
74+ 'detail' : {
75+ 'methods' : ['get' ],
76+ 'path' : '/restores/{id}/' ,
4877 }
4978 }
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
2+ import time
3+
24from syncano .models import Backup
35from tests .integration_test import InstanceMixin , IntegrationTest
46
@@ -27,6 +29,20 @@ def _test_backup_list(self):
2729 backups = [backup for backup in Backup .please .list ()]
2830 self .assertTrue (len (backups )) # at least one backup here;
2931
32+ def _test_backup_schedule_restore (self , backup_id ):
33+ backup = Backup .please .get (id = backup_id )
34+
35+ # wait for backup to be saved
36+ seconds_waited = 0
37+ while backup .status in ['scheduled' , 'running' ]:
38+ seconds_waited += 1
39+ self .assertTrue (seconds_waited < 20 , 'Waiting for backup to be saved takes too long.' )
40+ time .sleep (1 )
41+ backup .reload ()
42+
43+ restore = backup .schedule_restore ()
44+ self .assertIn (restore .status , ['success' , 'scheduled' ])
45+
3046 def _test_backup_delete (self , backup_id ):
3147 backup = Backup .please .get (id = backup_id )
3248 backup .delete ()
@@ -38,4 +54,5 @@ def test_backup(self):
3854 backup_id = self ._test_backup_create ()
3955 self ._test_backup_list ()
4056 self ._test_backup_detail (backup_id = backup_id )
57+ self ._test_backup_schedule_restore (backup_id = backup_id )
4158 self ._test_backup_delete (backup_id = backup_id )
You can’t perform that action at this time.
0 commit comments