当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_path函数代码示例

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


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


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