Beispiel #1
0
 def test_basic(self):
     sot = server_metadata.ServerMetadata()
     self.assertEqual('metadata', sot.resource_key)
     self.assertEqual(None, sot.resources_key)
     self.assertEqual('/servers/%(server_id)s/metadata', sot.base_path)
     self.assertEqual('compute', sot.service.service_type)
     self.assertTrue(sot.allow_create)
     self.assertTrue(sot.allow_retrieve)
     self.assertTrue(sot.allow_update)
     self.assertFalse(sot.allow_delete)
     self.assertFalse(sot.allow_list)
Beispiel #2
0
    def test_get(self):
        resp = mock.Mock()
        resp.body = FAKE_RESPONSE
        resp.json = mock.Mock(return_value=resp.body)
        sess = mock.Mock()
        sess.get = mock.Mock(return_value=resp)
        sot = server_metadata.ServerMetadata(EXAMPLE.copy())

        sot.get(sess)

        url = '/servers/' + FAKE_SERVER_ID + '/metadata'
        sess.get.assert_called_with(url, endpoint_filter=sot.service)
        self.assertEqual(FAKE_SERVER_ID, sot.server_id)
        self.assertEqual(FAKE_VALUE, sot[FAKE_KEY])
        self.assertEqual(FAKE_VALUE2, sot[FAKE_KEY2])
Beispiel #3
0
    def test_update(self):
        resp = mock.Mock()
        resp.body = FAKE_RESPONSE
        resp.json = mock.Mock(return_value=resp.body)
        sess = mock.Mock()
        sess.put = mock.Mock(return_value=resp)
        sot = server_metadata.ServerMetadata(EXAMPLE.copy())

        sot.update(sess)

        url = '/servers/' + FAKE_SERVER_ID + '/metadata'
        body = {"metadata": {FAKE_KEY: FAKE_VALUE}}
        sess.put.assert_called_with(url,
                                    endpoint_filter=sot.service,
                                    json=body)
        self.assertEqual(FAKE_SERVER_ID, sot.server_id)
        self.assertEqual(FAKE_VALUE, sot[FAKE_KEY])
Beispiel #4
0
 def test_make_it(self):
     sot = server_metadata.ServerMetadata(EXAMPLE)
     self.assertEqual(EXAMPLE['server_id'], sot.server_id)
     self.assertEqual(FAKE_VALUE, sot[FAKE_KEY])