Exemplo n.º 1
0
class InstanceActionLogTest(test.TestCase):

    def setUp(self):
        super(InstanceActionLogTest, self).setUp()
        self.controller = InstanceActionLogController()

    def test_create(self):
        req = fakes.HTTPRequest.blank('/v2/fake/servers/create')
        req._headers = {
            'X-Auth-User': '******',
            'X-Auth-Project-Id': 'cool project'
        }
        req.environ['REMOTE_ADDR'] = '1.2.3.4'
        body = {'server':
                {'ip': '1.2.3.4',
                 'name': 'a server',
                 'info': 'this all gets logged',
                }}
        resp_obj = FakeResponse(200, {'server': {'id': '1234'}})
        self.controller.create(req, body, resp_obj)
        result = instance_action_log_get_by_instance_uuid(
            FakeContext(), '1234')
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['extra'], \
            "{'info': 'this all gets logged', "
            "'ip': '1.2.3.4', 'name': 'a server'}"
        )
        self.assertEqual(result[0]['instance_uuid'], '1234')
        self.assertEqual(result[0]['user_id'], 'mister cool')
        self.assertEqual(result[0]['project_id'], 'cool project')
        self.assertEqual(result[0]['action_name'], 'create')
        # Must have been logged in last 60 seconds..
        self.assert_(datetime.now() - result[0]['created_at'] < timedelta(0,60))
        self.assertEqual(result[0]['response_code'], 200)
        self.assertEqual(result[0]['requesting_ip'], '1.2.3.4')
Exemplo n.º 2
0
 def setUp(self):
     super(InstanceActionLogTest, self).setUp()
     self.controller = InstanceActionLogController()