def test_basic(self): sot = instance.Instance() self.assertEqual('instance', sot.resource_key) self.assertEqual('instances', sot.resources_key) self.assertEqual('/instances', sot.base_path) self.assertTrue(sot.allow_list) self.assertTrue(sot.allow_create) self.assertTrue(sot.allow_get) self.assertTrue(sot.allow_update) self.assertTrue(sot.allow_delete)
def test_make_it(self): sot = instance.Instance(**EXAMPLE) self.assertEqual(IDENTIFIER, sot.id) self.assertEqual(EXAMPLE['status'], sot.status) self.assertEqual(EXAMPLE['hostname'], sot.hostname) # self.assertEqual(EXAMPLE['links'], sot.links) self.assertEqual(EXAMPLE['volume'], sot.volume) self.assertEqual(EXAMPLE['flavor'], sot.flavor) self.assertEqual(EXAMPLE['datastore'], sot.datastore) self.assertEqual(EXAMPLE['publicEndpoint'], sot.publicEndpoint) self.assertEqual(EXAMPLE['region'], sot.region)
def test_action_restart(self): sot = instance.Instance(**EXAMPLE) response = mock.Mock() response.json = mock.Mock(return_value='') sess = mock.Mock() sess.post = mock.Mock(return_value=response) self.assertIsNotNone(sot.restart(sess)) url = ("instances/%(id)s/action" % { 'id': IDENTIFIER, }) body = {'restart': {}} sess.post.assert_called_with(url, json=body, headers={'X-Language': 'en-us'})
def setUp(self): super(TestInstance, self).setUp() self.sess = mock.Mock(spec=adapter.Adapter) self.sess.get = mock.Mock() # self.sess.get_project_id = mock.Mock(return_value=PROJECT_ID) self.sot = instance.Instance(**EXAMPLE)
def test_list(self): mock_response = mock.Mock() mock_response.status_code = 200 mock_response.json.return_value = {"instances": [ {"instance": { "status": "ACTIVE", "name": "rds-new-channle-read", "links": [ { "rel": "self", "href": "" }, { "rel": "bookmark", "href": "" } ], "id": "37f52707-2fb3-482c-a444-77a70a4eafd6", "volume": { "type": "COMMON", "size": 100 }, "flavor": { "id": "7fbf27c5-07e5-43dc-cf13-ad7a0f1c5d9a", "links": [ { "rel": "self", "href": "" }, { "rel": "bookmark", "href": "" } ] }, "datastore": { "type": "PostgreSQL", "version": "PostgreSQL-9.5.5" }, "publicEndpoint": "10.11.77.101:8635", "dbPort": 8635, "region": "eu-de", "ip": "192.168.1.29", "replica_of": [ { "id": "c42cdd29-9912-4b57-91a8-c37a845566b1", "links": [ { "rel": "self", "href": "" }, { "rel": "bookmark", "href": "" } ] } ], "hostname": 'test' } } ]} self.sess.get.return_value = mock_response result = list(self.sot.list(self.sess)) self.sess.get.assert_called_once_with( '/instances', params={}, ) self.assertEqual([instance.Instance(**EXAMPLE)], result)