Esempio n. 1
0
 def test_plan_get_not_found(self, PlanHandler, resp_mock, request_mock):
     hand_get = PlanHandler.return_value.get
     hand_get.side_effect = exception.ResourceNotFound(name='plan',
                                                       id='test_id')
     plan.PlanController('test_id').get()
     hand_get.assert_called_with('test_id')
     self.assertEqual(404, resp_mock.status)
Esempio n. 2
0
 def test_plan_delete_ok(self, PlanHandler, resp_mock, request_mock):
     hand_delete = PlanHandler.return_value.delete
     hand_delete.return_value = None
     obj = plan.PlanController('test_id')
     obj.delete()
     hand_delete.assert_called_with('test_id')
     self.assertEqual(202, resp_mock.status)
Esempio n. 3
0
 def test_plan_put_empty_yaml(self, PlanHandler, resp_mock, request_mock):
     request_mock.content_type = 'application/x-yaml'
     request_mock.body = '{}'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
Esempio n. 4
0
 def test_plan_delete_not_found(self, PlanHandler, resp_mock, request_mock):
     hand_delete = PlanHandler.return_value.delete
     hand_delete.side_effect = exception.ResourceNotFound(name='plan',
                                                          plan_id='test_id')
     obj = plan.PlanController('test_id')
     obj.delete()
     hand_delete.assert_called_with('test_id')
     self.assertEqual(404, resp_mock.status)
Esempio n. 5
0
 def test_plan_put_version_not_found_yaml(self, PlanHandler, resp_mock,
                                          request_mock):
     data = 'name: ex_plan1\ndescription: yaml plan1.'
     request_mock.body = data
     request_mock.content_type = 'application/x-yaml'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
Esempio n. 6
0
 def test_plan_put_version_not_found_json(self, PlanHandler, resp_mock,
                                          request_mock):
     data = {'name': 'foo'}
     request_mock.body = json.dumps(data)
     request_mock.content_type = 'application/json'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
Esempio n. 7
0
 def test_plan_put_invalid_yaml(self, PlanHandler, resp_mock, request_mock,
                                mock_policy):
     mock_policy.return_value = True
     request_mock.content_type = 'application/x-yaml'
     request_mock.body = 'invalid yaml file'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     self.assertEqual(400, resp_mock.status)
Esempio n. 8
0
 def test_plan_put_ok_yaml(self, PlanHandler, resp_mock, request_mock):
     data = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
     request_mock.body = data
     request_mock.content_type = 'application/x-yaml'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     hand_update.assert_called_with('test_id', {'name': 'ex_plan1',
                                                'description': u'dsc1.'})
     self.assertEqual(200, resp_mock.status)
Esempio n. 9
0
 def test_plan_get_not_found_yaml(self, PlanHandler, resp_mock,
                                  request_mock, mock_policy):
     mock_policy.return_value = True
     request_mock.accept = 'application/x-yaml'
     hand_get = PlanHandler.return_value.get
     hand_get.side_effect = exception.ResourceNotFound(name='plan',
                                                       id='test_id')
     plan.PlanController('test_id').get()
     hand_get.assert_called_with('test_id')
     self.assertEqual(404, resp_mock.status)
Esempio n. 10
0
 def test_plan_put_ok_json(self, PlanHandler, resp_mock, request_mock,
                           mock_policy):
     mock_policy.return_value = True
     data = {'name': 'foo', 'version': '1'}
     request_mock.body = json.dumps(data)
     request_mock.content_type = 'application/json'
     hand_update = PlanHandler.return_value.update
     hand_update.return_value = fakes.FakePlan()
     plan.PlanController('test_id').put()
     hand_update.assert_called_with('test_id', {'name': 'foo'})
     self.assertEqual(200, resp_mock.status)
Esempio n. 11
0
 def test_plan_put_not_found(self, PlanHandler, resp_mock, request_mock):
     data = 'version: 1\nname: ex_plan1\ndescription: dsc1.'
     request_mock.body = data
     request_mock.content_type = 'application/x-yaml'
     hand_update = PlanHandler.return_value.update
     hand_update.side_effect = exception.ResourceNotFound(
         name='plan', id='test_id')
     plan.PlanController('test_id').put()
     hand_update.assert_called_with('test_id', {'name': 'ex_plan1',
                                                'description': u'dsc1.'})
     self.assertEqual(404, resp_mock.status)
Esempio n. 12
0
 def test_plan_get(self, PlanHandler, resp_mock, request_mock):
     hand_get = PlanHandler.return_value.get
     fake_plan = fakes.FakePlan()
     hand_get.return_value = fake_plan
     cont = plan.PlanController('test_id')
     resp = cont.get()
     self.assertIsNotNone(resp)
     resp_yml = yaml.load(resp)
     self.assertEqual(fake_plan.raw_content['name'], resp_yml['name'])
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)
Esempio n. 13
0
    def test_plan_delete_dberror(self, PlanHandler, resp_mock, request_mock):
        hand_get = PlanHandler.return_value.get
        fake_plan = fakes.FakePlan()
        hand_get.return_value = fake_plan

        hand_delete = PlanHandler.return_value.delete
        hand_delete.side_effect = db_exc.DBError()
        obj = plan.PlanController('test_id')
        obj.delete()
        hand_delete.assert_called_with('test_id')
        self.assertEqual(409, resp_mock.status)
Esempio n. 14
0
    def test_plan_put_bad_names(self, PlanHandler, resp_mock, request_mock):
        request_mock.content_type = 'application/x-yaml'
        hand_update = PlanHandler.return_value.update
        hand_update.return_value = fakes.FakePlan()
        pc = plan.PlanController('test_id')
        request_mock.body = 'version: 1\nname: %s' % ('a' * 101)
        pc.put()
        self.assertEqual(400, resp_mock.status)

        request_mock.body = 'version: 1\nname: %s' % ('name with spaces')
        pc.put()
        self.assertEqual(400, resp_mock.status)
Esempio n. 15
0
 def test_plan_get_json(self, PlanHandler, resp_mock, request_mock):
     hand_get = PlanHandler.return_value.get
     fake_plan = fakes.FakePlan()
     hand_get.return_value = fake_plan
     cont = plan.PlanController('test_id')
     resp = cont.get()
     self.assertIsNotNone(resp)
     resp_json = json.loads(resp)
     self.assertEqual(fake_plan.name, resp_json['name'])
     self.assertEqual(fake_plan.project_id, resp_json['project_id'])
     self.assertEqual(fake_plan.uuid, resp_json['uuid'])
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)
Esempio n. 16
0
 def test_plan_get_yaml(self, PlanHandler, resp_mock, request_mock,
                        mock_policy):
     mock_policy.return_value = True
     request_mock.accept = 'application/x-yaml'
     hand_get = PlanHandler.return_value.get
     fake_plan = fakes.FakePlan()
     hand_get.return_value = fake_plan
     cont = plan.PlanController('test_id')
     resp = cont.get()
     self.assertIsNotNone(resp)
     resp_yml = yaml.safe_load(resp)
     self.assertEqual(fake_plan.raw_content['name'], resp_yml['name'])
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)
Esempio n. 17
0
 def test_plan_get(self, resp_mock, request_mock):
     plan_obj = plan.PlanController('test_id')
     plan_obj.get()
     self.assertEqual(200, resp_mock.status)
Esempio n. 18
0
 def test_plan_put(self, resp_mock, request_mock):
     obj = plan.PlanController('test_id')
     obj.put(None)
     self.assertEqual(501, resp_mock.status)
Esempio n. 19
0
 def test_plan_delete(self, resp_mock, request_mock):
     obj = plan.PlanController('test_id')
     obj.delete()
     self.assertEqual(501, resp_mock.status)