Beispiel #1
0
 def test_31_update_project(self):
     rev = yield self.project.get_doc_rev(self.database, self.project_id)
     doc = {"_rev": rev, "services": [self.service_id]}
     with mock.patch.object(Service, "list_service") as mock_list:
         setup_func(mock_list, [self.service_id])
         resp = yield self.project.update_project(self.database, self.project_id, doc)
         self.assertEqual(json_decode(resp)["ok"], True)
Beispiel #2
0
 def test_list_projects(self):
     # this test is for ProjectsHandler
     url = '/api/v1/couch_test/search/list'
     with mock.patch.object(Project, 'list_project') as mock_list:
         setup_func(mock_list, [self.project_id])
         self.fetch(url)
         mock_list.assert_called_once_with(self.database)
 def test_get(self):
     # get project id by project name
     couch = CouchBase(couch_conf['base_url'])
     url = '/api/v1/couch_test/getPidByName?q=<project_name>'
     with mock.patch.object(couch, 'list_project') as mock_list:
         setup_func(mock_list, [self.project_id])
         self.fetch(url)
         mock_list.assert_called_once_with(self.database)
    def test_1_ProjectHandler_get(self):
        with mock.patch.object(Project, 'get_doc') as mock_get:
            setup_func(mock_get, 'ok')
            self.fetch(self.url)
            mock_get.assert_called_once_with(self.database, self.project_id)

        # raise test
        with mock.patch.object(Project, 'get_doc') as mock_get:
            raise_fetch(mock_get, ValueError, 'foo')
            resp = self.fetch(self.url)
            self.assertEqual(resp.body, '{"ok": false, "msg": "foo"}')
    def test_list_projects(self):
        # this test is for ProjectsHandler
        url = '/api/v1/couch_test/project/list'
        with mock.patch.object(Project, 'list_project') as mock_list:
            setup_func(mock_list, [self.project_id])
            self.fetch(url)
            mock_list.assert_called_once_with(self.database)

        # raise test
        with mock.patch.object(Project, 'get_doc') as mock_get:
            raise_fetch(mock_get, ValueError, 'missing')
            resp = self.fetch(url)
            self.assertEqual(resp.body, '{"ok": false, "msg": "missing"}')
    def test_1_ServiceHandler_get(self):
        with mock.patch.object(Service, 'get_doc') as mock_get:
            data = {"foo": "bar"}
            setup_func(mock_get, data)
            resp = self.fetch(self.url)
            mock_get.assert_called_once_with(self.database, self.service_id)
            self.assertEqual(resp.body, json_encode(data))

        # raise test
        with mock.patch.object(Service, 'get_doc') as mock_get:
            raise_fetch(mock_get, ValueError, 'no_db_file')
            resp = self.fetch(self.url)
            self.assertEqual(resp.code, 500)
            self.assertEqual(resp.body, '{"ok": false, "msg": "no_db_file"}')
    def test_3_ProjectHandler_put(self):
        data = {"foo": "bar"}
        data_str = json_encode(data)
        with mock.patch.object(Project, 'update_project') as mock_up:
            setup_func(mock_up, 'ok')
            resp = self.fetch(self.url, method="PUT", body='')
            self.assertEqual(resp.body, '{"ok": false, "msg": "Request body is empty"}')
            # application/json
            self.fetch(self.url, method="PUT", headers=self.json_header, body=data_str)
            mock_up.assert_called_once_with(self.database, self.project_id, data)

        # multipart/form-data
        with mock.patch.object(Project, 'update_project') as mock_up:
            setup_func(mock_up, 'ok')
            headers, body = self.form_data(data)
            self.fetch(self.url, method="PUT", headers=headers, body=body)
            mock_up.assert_called_once_with(self.database, self.project_id, data)
    def test_2_ProjectHandler_post(self):
        data = {"foo": "bar"}
        data_str = json_encode(data)
        add_data = data.copy()
        add_data.update(self.type)

        # application/json
        with mock.patch.object(Project, 'add_project') as mock_add:
            setup_func(mock_add, 'ok')
            self.fetch(self.url, method="POST", headers=self.json_header, body=data_str)
            mock_add.assert_called_once_with(self.database, self.project_id, add_data)

        # multipart/form-data
        with mock.patch.object(Project, 'add_project') as mock_add:
            setup_func(mock_add, 'ok')
            headers, data = self.form_data(data)
            self.fetch(self.url, method="POST", headers=headers, body=data)
            mock_add.assert_called_once_with(self.database, self.project_id, add_data)

        # raise test
        with mock.patch.object(Project, 'add_project') as mock_add:
            raise_fetch(mock_add, ValueError, 'foo')
            resp = self.fetch(self.url, method="POST", body='')
            self.assertEqual(resp.body, '{"ok": false, "msg": "foo"}')
 def test_4_ProjectHandler_delete(self):
     with mock.patch.object(Project, 'del_doc') as mock_del:
         setup_func(mock_del, 'foo')
         resp = self.fetch(self.url, method="DELETE")
         mock_del.assert_called_once_with(self.database, self.project_id)
         self.assertEqual(resp.body, '{"ok": foo}')