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


Python utils.get_path函数代码示例

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


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

示例1: _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
         if resp.status_code != 200:
             self.assertTrue(False, 'FAIL')
         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:SaptakS,项目名称:open-event-orga-server,代码行数:29,代码来源:test_export_import.py

示例2: test_export_media

 def test_export_media(self):
     """
     test successful export of media, unicode and more
     """
     resp = self._put(get_path(1), {'logo': 'https://placehold.it/350x150'})
     self.assertIn('placehold', resp.data, resp.data)
     # set speaker photo so that its export is checked
     resp = self._put(get_path(1, 'speakers', 1), {'photo': 'https://placehold.it/350x150'})
     # set sponsor photo so that its export is checked
     resp = self._put(get_path(1, 'sponsors', 1), {'photo': 'https://placehold.it/350x150'})
     # set event title as unicode
     resp = self._put(get_path(1), {'organizer_name': 'SandraMüllrick'})
     # export and unzip files
     self._create_set()
     dr = 'static/uploads/test_event_import'
     data = open(dr + '/event', 'r').read()
     self.assertIn('images/logo', data)
     # test unicode in file
     self.assertIn('ü', data)
     self.assertNotIn('\u', data)  # unicode escape
     obj = json.loads(data)
     logo_data = open(dr + obj['logo'], 'r').read()
     self.assertTrue(len(logo_data) > 10)
     # test meta.json
     data = open(dr + '/meta', 'r').read()
     self.assertIn('http', data)
开发者ID:SaptakS,项目名称:open-event-orga-server,代码行数:26,代码来源:test_export_import.py

示例3: 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_image', '/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_image'])
     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:SaptakS,项目名称:open-event-orga-server,代码行数:32,代码来源:test_import_more.py

示例4: _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
     """
     login(self.app, u'[email protected]', u'test')
     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'], '')
     self.assertIn('http', data['previous'])  # check absolute link
开发者ID:ashishpahwa7,项目名称:open-event-orga-server,代码行数:28,代码来源:test_get_api_paginated.py

示例5: _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:ashishpahwa7,项目名称:open-event-orga-server,代码行数:25,代码来源:test_post_api_auth.py

示例6: _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:ashishpahwa7,项目名称:open-event-orga-server,代码行数:12,代码来源:test_post_api_validation.py

示例7: _test_model

 def _test_model(self, name, data):
     if name == 'event':
         return
     with app.test_request_context():
         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'
             }
         )
         self.assertEqual(response.status_code, 403)  # permission denied
开发者ID:SaptakS,项目名称:open-event-orga-server,代码行数:13,代码来源:test_post_api_permissions.py

示例8: _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:ashishpahwa7,项目名称:open-event-orga-server,代码行数:13,代码来源:test_post_api.py

示例9: 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:ashishpahwa7,项目名称:open-event-orga-server,代码行数:17,代码来源:test_post_api.py

示例10: test_export_no_event

 def test_export_no_event(self):
     path = get_path(2, 'export', 'json')
     resp = self._post(path, {})
     if resp.status_code == 404:  # when celery not running
         return
     task_url = json.loads(resp.data)['task_url']
     resp = self.app.get(task_url)
     self.assertEqual(resp.status_code, 404)
开发者ID:SaptakS,项目名称:open-event-orga-server,代码行数:8,代码来源:test_export_import.py

示例11: test_speaker_api

 def test_speaker_api(self):
     path = get_path(1, 'speakers', 1)
     # logged in and check
     self._test_path(path, 'TestSpeaker_1', 'email', 'mobile')
     # logged out, private fields not present
     logout(self.app)
     resp = self.app.get(path)
     self.assertNotIn('email', resp.data)
     self.assertNotIn('mobile', resp.data)
开发者ID:ashishpahwa7,项目名称:open-event-orga-server,代码行数:9,代码来源:test_get_api_200.py

示例12: _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:SaptakS,项目名称:open-event-orga-server,代码行数:9,代码来源:test_export_import.py

示例13: test_api

 def test_api(self):
     login(self.app, u'[email protected]', u'test')
     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:ashishpahwa7,项目名称:open-event-orga-server,代码行数:10,代码来源:test_get_api_paginated.py

示例14: 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:ashishpahwa7,项目名称:open-event-orga-server,代码行数:10,代码来源:test_custom_forms.py

示例15: _test_model

 def _test_model(self, name, data, fields=None):
     """
     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
     """
     if fields is None:
         fields = []
     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:SaptakS,项目名称:open-event-orga-server,代码行数:19,代码来源:test_put_api_validation.py


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