Ejemplo n.º 1
0
    def test_timeout(self):
        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        self.called = False

        def urlopen_timeout(request, **kwargs):
            self.called = True
            raise socket.timeout('TIMEOUT')

        restore = RestoreSuspects(self.conf, self.db)
        with patch(suspects, 'urlopen', urlopen_timeout):
            restore.run(datetime(2000, 01, 01, 1, 1, 30))
        self.assert_(self.called)
Ejemplo n.º 2
0
    def test_run(self):
        expected = self.create('BUILDING', datetime(2000, 01, 01, 1, 1, 1))
        available = self.create('AVAILABLE', datetime(2000, 01, 01, 1, 1, 1))
        not_expected = self.create('BUILDING',
                                   datetime(2000, 01, 01, 1, 1, 25))
        self.count = 0

        def urlopen(request, **kwargs):
            self.assert_(kwargs.get('timeout'))
            self.assertEquals(kwargs['timeout'], self.timeout)
            self.count += 1
            data = parse_qs(request.get_data())
            self.assertIn('backup_source_volume_id', data)
            self.assertEquals(data['backup_id'][0], expected.restore_of)
            self.assertEquals(data['size'][0], '0')
            return MockResponse('{}', 200)

        restore = RestoreSuspects(self.conf, self.db)
        with patch(suspects, 'urlopen', urlopen):
            restore.run(datetime(2000, 01, 01, 1, 1, 30))
        self.assertEquals(self.count, 1)