• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.api.utils.get_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_path函数的具体用法?Python get_path怎么用?Python get_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _test_model

 def _test_model(self, name, data):
     """
     1. Test getting JWT token with wrong credentials and getting 401
     2. Get JWT token with right credentials
     3. Send a sample successful POST request
     """
     path = get_path() if name == 'event' else get_path(1, name + 's')
     # get access token
     response = self._send_login_request('wrong_password')
     self.assertEqual(response.status_code, 401)
     response = self._send_login_request('test')
     self.assertEqual(response.status_code, 200)
     token = json.loads(response.data)['access_token']
     # send a post request
     response = self.app.post(
         path,
         data=json.dumps(data),
         headers={
             'content-type': 'application/json',
             'Authorization': 'JWT %s' % token
         }
     )
     self.assertNotEqual(response.status_code, 401)
     self.assertEqual(response.status_code, 201)
     self.assertIn('Test' + str(name).title(), response.data)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:25,代码来源:test_post_api_auth.py


示例2: test_media_successful_uploads

 def test_media_successful_uploads(self):
     """
     Test successful uploads of relative and direct links,
     both types of media
     """
     self._create_set()
     self._update_json('event', 'background_url', '/bg.png')
     self._create_file('bg.png')
     self._update_json('speakers', 'photo', '/spkr.png', 1)
     self._create_file('spkr.png')
     self._update_json('sponsors', 'logo', 'http://google.com/favicon.ico', 1)
     # import
     data = self._make_zip_from_dir()
     event_dic = self._do_succesful_import(data)
     # checks
     resp = self.app.get(event_dic['background_url'])
     self.assertEqual(resp.status_code, 200)
     # speaker
     photo = self._get_event_value(
         get_path(2, 'speakers', 2), 'photo'
     )
     resp = self.app.get(photo)
     self.assertEqual(resp.status_code, 200)
     self.assertIn('http://', photo)
     # sponsor
     logo = self._get_event_value(
         get_path(2, 'sponsors', 2), 'logo'
     )
     self.assertIn('sponsors', logo)
     self.assertNotEqual(logo, 'http://google.com/favicon.ico')
     resp = self.app.get(logo)
     self.assertEqual(resp.status_code, 200)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:32,代码来源:test_import_more.py


示例3: _test_model

 def _test_model(self, name):
     """
     Tests -
     1. When just one item, check if next and prev urls are empty
     2. When one more item added, limit results to 1 and see if
         next is not empty
     3. start from position 2 and see if prev is not empty
     """
     if name == 'event':
         path = get_path('page')
     else:
         path = get_path(1, name + 's', 'page')
     data = self._json_from_url(path)
     self.assertEqual(data['next'], '')
     self.assertEqual(data['previous'], '')
     # add second service
     with app.test_request_context():
         create_event(name='TestEvent2')
         create_services(1)
     data = self._json_from_url(path + '?limit=1')
     self.assertIn('start=2', data['next'])
     self.assertEqual(data['previous'], '')
     # check from start=2
     data = self._json_from_url(path + '?start=2')
     self.assertIn('limit=1', data['previous'])
     self.assertEqual(data['next'], '')
开发者ID:faheemzunjani,项目名称:open-event-orga-server,代码行数:26,代码来源:test_get_api_paginated.py


示例4: _test_import_success

 def _test_import_success(self):
     # first export
     resp = self._do_successful_export(1)
     file = resp.data
     # import
     upload_path = get_path('import', 'json')
     resp = self._upload(file, upload_path, 'event.zip')
     self.assertEqual(resp.status_code, 200)
     self.assertIn('task_url', resp.data)
     task_url = json.loads(resp.data)['task_url']
     # wait for done
     while True:
         resp = self.app.get(task_url)
         if 'SUCCESS' in resp.data:
             self.assertIn('result', resp.data)
             dic = json.loads(resp.data)['result']
             break
         logging.info(resp.data)
         time.sleep(2)
     # check internals
     self.assertEqual(dic['id'], 2)
     self.assertEqual(dic['name'], 'TestEvent')
     self.assertIn('fb.com', json.dumps(dic['social_links']), dic)
     # get to check final
     resp = self.app.get(get_path(2))
     self.assertEqual(resp.status_code, 200)
     self.assertIn('TestEvent', resp.data)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:27,代码来源:test_export_import.py


示例5: _test_model

 def _test_model(self, name, data, fields=[]):
     """
     Sets a random value to each of the :fields in :data and makes
     sure POST request failed
     """
     path = get_path() if name == "event" else get_path(1, name + "s")
     self._login_user()
     for field in fields:
         data_copy = data.copy()
         data_copy[field] = "[email protected][email protected]"
         response = self.post_request(path, data_copy)
         self.assertEqual(response.status_code, 400)
开发者ID:yasharmaster,项目名称:open-event-orga-server,代码行数:12,代码来源:test_post_api_validation.py


示例6: _test_model

 def _test_model(self, name, data, api_model, path=None):
     # strip data
     data = data.copy()
     for i in api_model:
         if not api_model[i].required:
             data.pop(i, None)
     # test
     if not path:
         path = get_path() if name == 'event' else get_path(1, name + 's')
     self._login_user()
     response = self.post_request(path, data)
     self.assertEqual(201, response.status_code, msg=response.data)
     self.assertIn('Test' + name[0].upper() + name[1:], response.data)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:13,代码来源:test_post_api.py


示例7: _test_import_success

 def _test_import_success(self):
     # first export
     path = get_path(1, 'export', 'json')
     resp = self.app.get(path)
     file = resp.data
     self.assertEqual(resp.status_code, 200)
     # import
     upload_path = get_path('import', 'json')
     resp = self._upload(file, upload_path, 'event.zip')
     self.assertEqual(resp.status_code, 200)
     # check internals
     dic = json.loads(resp.data)
     self.assertEqual(dic['id'], 2)
     self.assertEqual(dic['name'], 'TestEvent')
开发者ID:faheemzunjani,项目名称:open-event-orga-server,代码行数:14,代码来源:test_export_import.py


示例8: _test_model

 def _test_model(self, name, data):
     path = get_path() if name == 'event' else get_path(1, name + 's')
     response = self.app.post(
         path,
         data=json.dumps(data),
         headers={
             'content-type': 'application/json',
             'Authorization': 'Basic %s' %
             base64.b64encode('[email protected]:test')
         }
     )
     self.assertNotEqual(response.status_code, 401)
     self.assertEqual(response.status_code, 201)
     self.assertIn('Test' + str(name).title(), response.data)
开发者ID:agwisniewska,项目名称:open-event-orga-server,代码行数:14,代码来源:test_post_api_auth.py


示例9: _test_model

 def _test_model(self, name, data):
     """
     Tests -
     1. Without login, try to do a PUT request and catch 401 error
     2. Login and match 200 response code and make sure that
         data changed
     """
     path = get_path(1) if name == 'event' else get_path(1, name + 's', 1)
     response = self._put(path, data)
     self.assertEqual(401, response.status_code, msg=response.data)
     # login and send the request again
     self._login_user()
     response = self._put(path, data)
     self.assertEqual(200, response.status_code, msg=response.data)
     # surrounded by quotes for strict checking
     self.assertIn('"Test%s"' % str(name).title(), response.data)
开发者ID:deepakpathania,项目名称:open-event-orga-server,代码行数:16,代码来源:test_put_api.py


示例10: test_session_api_extended

 def test_session_api_extended(self):
     self._login_user()
     path = get_path(1, 'tracks')
     self.post_request(path, POST_TRACK_DATA)
     path = get_path(1, 'microlocations')
     self.post_request(path, POST_MICROLOCATION_DATA)
     path = get_path(1, 'speakers')
     self.post_request(path, POST_SPEAKER_DATA)
     # create session json
     data = POST_SESSION_DATA.copy()
     data['track_id'] = 1
     data['microlocation_id'] = 1
     data['speaker_ids'] = [1]
     resp = self.post_request(get_path(1, 'sessions'), data)
     self.assertEqual(resp.status_code, 201)
     for i in ['TestTrack', 'TestSpeaker', 'TestMicrolocation']:
         self.assertIn(i, resp.data, i)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:17,代码来源:test_post_api.py


示例11: _test_model

 def _test_model(self, name, data, fields=[]):
     """
     Sets a random value to each of the :fields in :data and makes
     sure PUT request failed.
     At last check if original value had prevailed
     """
     path = get_path(1) if name == 'event' else get_path(1, name + 's', 1)
     self._login_user()
     for field in fields:
         data_copy = data.copy()
         data_copy[field] = '[email protected][email protected]'
         response = self._put(path, data_copy)
         self.assertEqual(response.status_code, 400)
     # make sure field is not updated
     response = self.app.get(path)
     self.assertIn('Test%s_1' % str(name).title(), response.data)
     self.assertNotIn('"Test%s"' % str(name).title(), response.data)
开发者ID:agwisniewska,项目名称:open-event-orga-server,代码行数:17,代码来源:test_put_api_validation.py


示例12: test_api

 def test_api(self):
     path = get_path('page')
     response = self.app.get(path)
     self.assertEqual(response.status_code, 404, msg=response.data)
     with app.test_request_context():
         create_event()
     response = self.app.get(path)
     self.assertEqual(response.status_code, 200)
     self.assertIn('TestEvent', response.data)
开发者ID:faheemzunjani,项目名称:open-event-orga-server,代码行数:9,代码来源:test_get_api_paginated.py


示例13: _test_import_ots

 def _test_import_ots(self):
     dir_path = 'samples/ots16'
     shutil.make_archive(dir_path, 'zip', dir_path)
     file = open(dir_path + '.zip', 'r').read()
     os.remove(dir_path + '.zip')
     upload_path = get_path('import', 'json')
     resp = self._upload(file, upload_path, 'event.zip')
     self.assertEqual(resp.status_code, 200)
     self.assertIn('Open Tech Summit', resp.data)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:9,代码来源:test_export_import.py


示例14: _test_import_success

 def _test_import_success(self):
     # first export
     path = get_path(1, 'export', 'json')
     resp = self.app.get(path)
     file = resp.data
     self.assertEqual(resp.status_code, 200)
     # import
     upload_path = get_path('import', 'json')
     resp = self._upload(file, upload_path, 'event.zip')
     self.assertEqual(resp.status_code, 200)
     # check internals
     dic = json.loads(resp.data)
     self.assertEqual(dic['id'], 2)
     self.assertEqual(dic['name'], 'TestEvent')
     self.assertIn('fb.com', json.dumps(dic['social_links']), dic)
     # get to check final
     resp = self.app.get(get_path(2))
     self.assertEqual(resp.status_code, 200)
     self.assertIn('TestEvent', resp.data)
开发者ID:agwisniewska,项目名称:open-event-orga-server,代码行数:19,代码来源:test_export_import.py


示例15: test_speaker

 def test_speaker(self):
     speaker = POST_SPEAKER_DATA.copy()
     SPEAKER_FORM['github']['require'] = 1
     speaker['github'] = None
     form_str = json.dumps(SPEAKER_FORM, separators=(',', ':'))
     with app.test_request_context():
         update_or_create(CustomForms, event_id=1, speaker_form=form_str)
     path = get_path(1, 'speakers')
     resp = self.post(path, speaker)
     self.assertEqual(resp.status_code, 400)
开发者ID:agwisniewska,项目名称:open-event-orga-server,代码行数:10,代码来源:test_custom_forms.py


示例16: test_session

 def test_session(self):
     session = POST_SESSION_DATA.copy()
     SESSION_FORM['comments']['require'] = 1
     session['comments'] = None
     form_str = json.dumps(SESSION_FORM, separators=(',', ':'))
     with app.test_request_context():
         update_or_create(CustomForms, event_id=1, session_form=form_str)
     path = get_path(1, 'sessions')
     resp = self.post(path, session)
     self.assertEqual(resp.status_code, 400)
开发者ID:agwisniewska,项目名称:open-event-orga-server,代码行数:10,代码来源:test_custom_forms.py


示例17: _test_model

 def _test_model(self, name, data, checks=[]):
     """
     Tests -
     1. Without login, try to do a POST request and catch 401 error
     2. Login and match 201 response code and correct response data
     Param:
         checks - list of strings to assert in successful response data
     """
     path = get_path() if name == 'event' else get_path(1, name + 's')
     response = self.post_request(path, data)
     self.assertEqual(401, response.status_code, msg=response.data)
     # login and send the request again
     self._login_user()
     response = self.post_request(path, data)
     self.assertEqual(201, response.status_code, msg=response.data)
     self.assertIn('location', response.headers)
     self.assertIn('Test' + str(name).title(), response.data)
     for string in checks:
         self.assertIn(string, response.data, msg=string)
     return response
开发者ID:deepakpathania,项目名称:open-event-orga-server,代码行数:20,代码来源:test_post_api.py


示例18: test_event_api

 def test_event_api(self):
     self.app = Setup.create_app()
     with app.test_request_context():
         register(self.app, u'[email protected]', u'test')
         login(self.app, u'[email protected]', u'test')
         # Non existing event
         event_id = 1
         path = get_path(event_id)
         response = self.app.get(path)
         self.assertEqual(response.status_code, 404)
         self.assertIn('does not exist', response.data)
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:11,代码来源:test_get_api_404.py


示例19: _test_model

 def _test_model(self, name, data, path=None, exclude=[]):
     if not path:
         path = get_path(1) if name == 'event' else get_path(1, name + 's', 1)
     self._login_user()
     data_copy = data.copy()
     # loop over keys
     for i in data_copy:
         if i in exclude:
             continue
         # get old
         resp_old = self.app.get(path)
         self.assertEqual(resp_old.status_code, 200)
         # update
         resp = self._put(path, {i: data_copy[i]})
         self.assertEqual(200, resp.status_code,
                          msg='Key: %s\nMsg: %s' % (i, resp.data))
         # check persistence
         status = self._test_change_json(resp_old.data, resp.data, i)
         if status:
             self.assertTrue(0, msg='Key %s changed in %s' % (status, i))
开发者ID:hacktrec,项目名称:open-event-orga-server,代码行数:20,代码来源:test_put_api.py


示例20: test_export_success

 def test_export_success(self):
     path = get_path(1, 'export', 'json')
     resp = self.app.get(path)
     self.assertEqual(resp.status_code, 200)
     self.assertIn('event1.zip', resp.headers['Content-Disposition'])
     size = len(resp.data)
     with app.test_request_context():
         create_services(1, '2')
         create_services(1, '3')
     # check if size increased
     resp = self.app.get(path)
     self.assertEqual(resp.status_code, 200)
     self.assertTrue(len(resp.data) > size)
开发者ID:faheemzunjani,项目名称:open-event-orga-server,代码行数:13,代码来源:test_export_import.py



注:本文中的tests.api.utils.get_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api_client.post_data函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_graphql_content函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap