Esempio n. 1
0
    def test_create(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {'backup': copy.deepcopy(EXAMPLE)}
        mock_response.headers = {}

        self.sess.post.return_value = mock_response

        sot = backup.Backup.new(
            # project_id=PROJECT_ID,
            name='backup_name',
            description='descr',
            instance='some_instance')

        result = sot.create(self.sess, headers=RDS_HEADERS)

        self.sess.post.assert_called_once_with('/backups',
                                               headers=RDS_HEADERS,
                                               json={
                                                   'backup': {
                                                       'instance':
                                                       'some_instance',
                                                       'description': 'descr',
                                                       'name': 'backup_name'
                                                   }
                                               })

        self.assertEqual(
            backup.Backup(
                # project_id=PROJECT_ID,
                instance='some_instance',
                **EXAMPLE),
            result)
Esempio n. 2
0
 def setUp(self):
     super(TestBackup, self).setUp()
     self.sess = mock.Mock(spec=adapter.Adapter)
     self.sess.get = mock.Mock()
     self.sess.post = mock.Mock()
     self.sess.delete = mock.Mock()
     self.sess.put = mock.Mock()
     # self.sess.get_project_id = mock.Mock(return_value=PROJECT_ID)
     self.sot = backup.Backup(**EXAMPLE)
Esempio n. 3
0
 def test_basic(self):
     sot = backup.Backup()
     self.assertEqual('backup', sot.resource_key)
     self.assertEqual('backups', sot.resources_key)
     self.assertEqual('/backups', sot.base_path)
     self.assertTrue(sot.allow_list)
     self.assertTrue(sot.allow_create)
     self.assertFalse(sot.allow_get)
     self.assertFalse(sot.allow_update)
     self.assertTrue(sot.allow_delete)
Esempio n. 4
0
    def test_list(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {'backups': [EXAMPLE]}

        self.sess.get.return_value = mock_response

        result = list(self.sot.list(self.sess, headers=RDS_HEADERS))

        self.sess.get.assert_called_once_with(
            '/backups',
            headers=RDS_HEADERS,
            params={},
        )

        self.assertEqual([backup.Backup(**EXAMPLE)], result)
Esempio n. 5
0
    def test_delete(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {}
        mock_response.headers = {}

        self.sess.delete.return_value = mock_response

        sot = backup.Backup(
            # project_id=PROJECT_ID,
            **EXAMPLE)

        sot.delete(self.sess, headers=RDS_HEADERS)

        url = 'backups/%(id)s' % \
            {
                'id': sot.id
            }

        # utils.urljoin strips leading '/', but it is not a problem
        self.sess.delete.assert_called_once_with(url, headers=RDS_HEADERS)
Esempio n. 6
0
 def test_make_it(self):
     sot = backup.Backup(**EXAMPLE)
     self.assertEqual(IDENTIFIER, sot.id)
     self.assertEqual(EXAMPLE['name'], sot.name)
     self.assertEqual(EXAMPLE['created'], sot.created)