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

Python api.url_for函数代码示例

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

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



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

示例1: test_filters

    def test_filters(self):
        factories.CalendarDateFactory(start_date=datetime.datetime(2016, 1, 2))
        factories.CalendarDateFactory(location='Mississippi, CA')
        factories.CalendarDateFactory(event_id=123)
        factories.CalendarDateFactory(state=['CA'])
        factories.CalendarDateFactory(category='Public Hearings')
        factories.CalendarDateFactory(description='a really interesting event')
        factories.CalendarDateFactory(summary='Meeting that will solve all the problems')
        factories.CalendarDateFactory(end_date=datetime.datetime(2015, 1, 2))

        filter_fields = [
            ('min_start_date', '2015-01-01'),
            ('category', 'Public Hearings'),
            ('min_end_date', '2014-01-01'),
            # this is not passing or working :/
            #('state', 'CA'),
            ('description', 'interesting event'),
            ('summary', 'solve all the problems'),
            ('event_id', 123),
        ]

        orig_response = self._response(api.url_for(CalendarDatesView))
        original_count = orig_response['pagination']['count']

        for field, example in filter_fields:
            page = api.url_for(CalendarDatesView, **{field: example})
            # returns at least one result
            results = self._results(page)
            self.assertEqual(len(results), 1)
            # doesn't return all results
            response = self._response(page)
            self.assertGreater(original_count, response['pagination']['count'])
开发者ID:evaluation-alex,项目名称:openFEC,代码行数:32,代码来源:test_dates.py


示例2: test_reports_by_committee_type_and_year

 def test_reports_by_committee_type_and_year(self):
     presidential_report_2012 = factories.ReportsPresidentialFactory(report_year=2012)
     presidential_report_2016 = factories.ReportsPresidentialFactory(report_year=2016)
     house_report_2016 = factories.ReportsHouseSenateFactory(report_year=2016)
     results = self._results(
         api.url_for(
             ReportsView,
             committee_type='presidential',
             year=2016,
         )
     )
     self._check_committee_ids(
         results,
         [presidential_report_2016],
         [presidential_report_2012, house_report_2016],
     )
     # Test repeated cycle parameter
     results = self._results(
         api.url_for(
             ReportsView,
             committee_type='presidential',
             year=[2016, 2018],
         )
     )
     self._check_committee_ids(
         results,
         [presidential_report_2016],
         [presidential_report_2012, house_report_2016],
     )
开发者ID:LetsUnlockiPhone,项目名称:openFEC,代码行数:29,代码来源:report_tests.py


示例3: test_committee_filters

    def test_committee_filters(self):
        [
            factories.CommitteeFactory(state='CA'),
            factories.CommitteeFactory(name='Obama'),
            factories.CommitteeFactory(committee_type='S'),
            factories.CommitteeFactory(designation='P'),
            factories.CommitteeFactory(party='DEM'),
            factories.CommitteeFactory(organization_type='C'),
            factories.CommitteeFactory(committee_id='C01'),
        ]

        # checking one example from each field
        filter_fields = (
            ('committee_id', ['C01', 'C02']),
            ('state', ['CA', 'DC']),
            ('name', 'Obama'),
            ('committee_type', 'S'),
            ('designation', 'P'),
            ('party', ['REP', 'DEM']),
            ('organization_type', 'C'),
        )

        org_response = self._response(api.url_for(CommitteeList))
        original_count = org_response['pagination']['count']

        for field, example in filter_fields:
            page = api.url_for(CommitteeList, **{field: example})
            # returns at least one result
            results = self._results(page)
            self.assertGreater(len(results), 0)
            # doesn't return all results
            response = self._response(page)
            self.assertGreater(original_count, response['pagination']['count'])
开发者ID:adborden,项目名称:openFEC,代码行数:33,代码来源:test_committees.py


示例4: test_filings_filters

    def test_filings_filters(self):
        [
            factories.FilingsFactory(committee_id='C0004'),
            factories.FilingsFactory(committee_id='C0005'),
            factories.FilingsFactory(beginning_image_number=123456789021234567),
            factories.FilingsFactory(form_type='3'),
            factories.FilingsFactory(primary_general_indicator='G'),
            factories.FilingsFactory(amendment_indicator='A'),
            factories.FilingsFactory(report_type='Post General'),
            factories.FilingsFactory(report_year=1999),
        ]

        filter_fields = (
            ('beginning_image_number', 123456789021234567),
            ('form_type', '3'),
            ('primary_general_indicator', 'G'),
            ('amendment_indicator', 'A'),
            ('report_type', 'Post General'),
            ('report_year', 1999),
        )

        # checking one example from each field
        orig_response = self._response(api.url_for(FilingsList))
        original_count = orig_response['pagination']['count']

        for field, example in filter_fields:
            page = api.url_for(FilingsList, **{field: example})
            # returns at least one result
            results = self._results(page)
            self.assertGreater(len(results), 0)
            # doesn't return all results
            response = self._response(page)
            self.assertGreater(original_count, response['pagination']['count'])
开发者ID:EricSchles,项目名称:openFEC,代码行数:33,代码来源:filings_tests.py


示例5: test_cand_filters

    def test_cand_filters(self):
        [
            factories.CandidateFactory(office='H'),
            factories.CandidateFactory(district='00'),
            factories.CandidateFactory(district='02'),
            factories.CandidateFactory(state='CA'),
            factories.CandidateFactory(name='Obama'),
            factories.CandidateFactory(party='DEM'),
            factories.CandidateFactory(cycles=[2006]),
            factories.CandidateFactory(candidate_id='BARLET'),
            factories.CandidateFactory(candidate_id='RITCHIE'),
        ]

        filter_fields = (
            ('office', 'H'),
            ('district', ['00', '02']),
            ('state', 'CA'),
            ('name', 'Obama'),
            ('party', 'DEM'),
            ('cycle', '2006'),
            ('candidate_id', ['BARTLET', 'RITCHIE'])
        )

        # checking one example from each field
        orig_response = self._response(api.url_for(CandidateList))
        original_count = orig_response['pagination']['count']

        for field, example in filter_fields:
            page = api.url_for(CandidateList, **{field: example})
            # returns at least one result
            results = self._results(page)
            self.assertGreater(len(results), 0)
            # doesn't return all results
            response = self._response(page)
            self.assertGreater(original_count, response['pagination']['count'])
开发者ID:srinivasmalladi,项目名称:openFEC,代码行数:35,代码来源:test_candidates.py


示例6: test_page_param

 def test_page_param(self):
     [factories.CandidateFactory() for _ in range(20)]
     page_one_and_two = self._results(api.url_for(CandidateList, per_page=10, page=1))
     page_two = self._results(api.url_for(CandidateList, per_page=5, page=2))
     self.assertEqual(page_two[0], page_one_and_two[5])
     for itm in page_two:
         self.assertIn(itm, page_one_and_two)
开发者ID:Apeder,项目名称:openFEC,代码行数:7,代码来源:test_api.py


示例7: test_committee_date_filters

 def test_committee_date_filters(self):
     [
         factories.CommitteeFactory(first_file_date=datetime.date(2015, 1, 1)),
         factories.CommitteeFactory(first_file_date=datetime.date(2015, 2, 1)),
         factories.CommitteeFactory(first_file_date=datetime.date(2015, 3, 1)),
         factories.CommitteeFactory(first_file_date=datetime.date(2015, 4, 1)),
     ]
     results = self._results(api.url_for(CommitteeList, min_first_file_date='02/01/2015'))
     self.assertTrue(all(each['first_file_date'] >= datetime.date(2015, 2, 1).isoformat() for each in results))
     results = self._results(api.url_for(CommitteeList, max_first_file_date='02/03/2015'))
     self.assertTrue(all(each['first_file_date'] <= datetime.date(2015, 3, 1).isoformat() for each in results))
     results = self._results(
         api.url_for(
             CommitteeList,
             min_first_file_date='02/01/2015',
             max_first_file_date='02/03/2015',
         )
     )
     self.assertTrue(
         all(
             datetime.date(2015, 2, 1).isoformat()
             <= each['first_file_date']
             <= datetime.date(2015, 3, 1).isoformat()
             for each in results
         )
     )
开发者ID:adborden,项目名称:openFEC,代码行数:26,代码来源:test_committees.py


示例8: test_committee_sort

 def test_committee_sort(self):
     committees = [factories.CommitteeFactory(designation="B"), factories.CommitteeFactory(designation="U")]
     committee_ids = [each.committee_id for each in committees]
     results = self._results(api.url_for(CommitteeList, sort="designation"))
     self.assertEqual([each["committee_id"] for each in results], committee_ids)
     results = self._results(api.url_for(CommitteeList, sort="-designation"))
     self.assertEqual([each["committee_id"] for each in results], committee_ids[::-1])
开发者ID:LetsUnlockiPhone,项目名称:openFEC,代码行数:7,代码来源:committee_tests.py


示例9: test_filters

    def test_filters(self):
        [
            factories.RadAnalystFactory(telephone_ext=123, committee_id='C0001'),
            factories.RadAnalystFactory(telephone_ext=456, committee_id='C0002'),
            factories.RadAnalystFactory(analyst_id=789, committee_id='C0003'),
            factories.RadAnalystFactory(analyst_id=1011, analyst_short_id=11, committee_id='C0004'),
        ]

        filter_fields = (
            ('committee_id', 'C0002'),
            ('telephone_ext', 123),
            ('analyst_id', 789),
            ('analyst_short_id', 11),
        )

        # checking one example from each field
        orig_response = self._response(api.url_for(RadAnalystView))
        original_count = orig_response['pagination']['count']

        for field, example in filter_fields:
            page = api.url_for(RadAnalystView, **{field: example})
            # returns at least one result
            results = self._results(page)
            self.assertGreater(len(results), 0)
            # doesn't return all results
            response = self._response(page)
            self.assertGreater(original_count, response['pagination']['count'])
开发者ID:18F,项目名称:openFEC,代码行数:27,代码来源:test_filing_resources.py


示例10: test_invalid_per_page_param

 def test_invalid_per_page_param(self):
     results = self.app.get(api.url_for(CandidateList, per_page=-10))
     self.assertEquals(results.status_code, 422)
     results = self.app.get(api.url_for(CandidateList, per_page=34.2))
     self.assertEquals(results.status_code, 422)
     results = self.app.get(api.url_for(CandidateList, per_page='dynamic-wombats'))
     self.assertEquals(results.status_code, 422)
开发者ID:gadbaw,项目名称:openFEC,代码行数:7,代码来源:test_api.py


示例11: test_committee_sort

 def test_committee_sort(self):
     committees = [
         factories.CommitteeFactory(designation='B'),
         factories.CommitteeFactory(designation='U'),
     ]
     committee_ids = [each.committee_id for each in committees]
     results = self._results(api.url_for(CommitteeList, sort='designation'))
     self.assertEqual([each['committee_id'] for each in results], committee_ids)
     results = self._results(api.url_for(CommitteeList, sort='-designation'))
     self.assertEqual([each['committee_id'] for each in results], committee_ids[::-1])
开发者ID:adborden,项目名称:openFEC,代码行数:10,代码来源:test_committees.py


示例12: test_null_pagination_with_null_sort_column_values_ascending_with_sort_expression

    def test_null_pagination_with_null_sort_column_values_ascending_with_sort_expression(self):
        # NOTE:  Schedule B is sorted by disbursement date with the expression
        # sa.func.coalesce(self.disbursement_date, sa.cast('9999-12-31', sa.Date))
        # by default (in descending order), so we must account for that with the
        # results and slice the baseline list of objects accordingly!
        filings = [
            factories.ScheduleBFactory(disbursement_date=None)
            # this range should ensure the page has a null transition
            for _ in range(10)
            ]
        filings = filings + [
            factories.ScheduleBFactory(
                disbursement_date=datetime.date(2016, 1, 1)
            )
            for _ in range(15)
            ]

        page1 = self._results(api.url_for(
            ScheduleBView,
            sort='disbursement_date',
            sort_reverse_nulls='true',
            **self.kwargs
        ))

        self.assertEqual(len(page1), 20)

        top_reversed_from_middle = filings[10::]
        reversed_from_bottom_to_middle = filings[0:5:]
        top_reversed_from_middle.extend(reversed_from_bottom_to_middle)
        self.assertEqual(
            [int(each['sub_id']) for each in page1],
            [each.sub_id for each in top_reversed_from_middle],
        )
        self.assertEqual(
            [each['disbursement_date'] for each in page1],
            [each.disbursement_date.strftime('%Y-%m-%d') if each.disbursement_date else None for each in
             top_reversed_from_middle]
        )
        page2 = self._results(api.url_for(
            ScheduleBView,
            last_index=page1[-1]['sub_id'],
            sort_null_only=True,
            sort='disbursement_date',
            **self.kwargs
        ))
        self.assertEqual(len(page2), 5)
        self.assertEqual(
            [int(each['sub_id']) for each in page2],
            [each.sub_id for each in filings[5:10:]],
        )
        self.assertEqual(
            [each['disbursement_date'] for each in page2],
            [each.disbursement_date.strftime('%Y-%m-%d') if each.disbursement_date else None for each in
             filings[5:10:]]
        )
开发者ID:18F,项目名称:openFEC,代码行数:55,代码来源:test_itemized.py


示例13: test_conditional_missing_params

 def test_conditional_missing_params(self):
     response = self.app.get(api.url_for(ElectionView, office='president', cycle=2012))
     self.assertEquals(response.status_code, 200)
     response = self.app.get(api.url_for(ElectionView, office='senate', cycle=2012))
     self.assertEquals(response.status_code, 422)
     response = self.app.get(api.url_for(ElectionView, office='senate', cycle=2012, state='NY'))
     self.assertEquals(response.status_code, 200)
     response = self.app.get(api.url_for(ElectionView, office='house', cycle=2012, state='NY'))
     self.assertEquals(response.status_code, 422)
     response = self.app.get(api.url_for(ElectionView, office='house', cycle=2012, state='NY', district='01'))
     self.assertEquals(response.status_code, 200)
开发者ID:NoahKunin,项目名称:openFEC,代码行数:11,代码来源:test_elections.py


示例14: test_cycle_filter

 def test_cycle_filter(self):
     factories.CandidateFactory(cycles=[1986, 1988])
     factories.CandidateFactory(cycles=[2000, 2002])
     results = self._results(api.url_for(CandidateList, cycle=1988))
     self.assertEqual(len(results), 1)
     for result in results:
         self.assertIn(1988, result["cycles"])
     results = self._results(api.url_for(CandidateList, cycle=[1986, 2002]))
     self.assertEqual(len(results), 2)
     cycles = set([1986, 2002])
     for result in results:
         self.assertTrue(cycles.intersection(result["cycles"]))
开发者ID:Apeder,项目名称:openFEC,代码行数:12,代码来源:test_api.py


示例15: test_amount_sched_e

 def test_amount_sched_e(self):
     [
         factories.ScheduleEFactory(expenditure_amount=50),
         factories.ScheduleEFactory(expenditure_amount=100),
         factories.ScheduleEFactory(expenditure_amount=150),
         factories.ScheduleEFactory(expenditure_amount=200),
     ]
     results = self._results(api.url_for(ScheduleEView, min_amount=100))
     self.assertTrue(all(each['expenditure_amount'] >= 100 for each in results))
     results = self._results(api.url_for(ScheduleEView, max_amount=150))
     self.assertTrue(all(each['expenditure_amount'] <= 150 for each in results))
     results = self._results(api.url_for(ScheduleEView, min_amount=100, max_amount=150))
     self.assertTrue(all(100 <= each['expenditure_amount'] <= 150 for each in results))
开发者ID:18F,项目名称:openFEC,代码行数:13,代码来源:test_itemized.py


示例16: test_amount_sched_b

 def test_amount_sched_b(self):
     [
         factories.ScheduleBFactory(disbursement_amount=50),
         factories.ScheduleBFactory(disbursement_amount=100),
         factories.ScheduleBFactory(disbursement_amount=150),
         factories.ScheduleBFactory(disbursement_amount=200),
     ]
     results = self._results(api.url_for(ScheduleBView, min_amount=100))
     self.assertTrue(all(each['disbursement_amount'] >= 100 for each in results))
     results = self._results(api.url_for(ScheduleBView, max_amount=150))
     self.assertTrue(all(each['disbursement_amount'] <= 150 for each in results))
     results = self._results(api.url_for(ScheduleBView, min_amount=100, max_amount=150))
     self.assertTrue(all(100 <= each['disbursement_amount'] <= 150 for each in results))
开发者ID:18F,项目名称:openFEC,代码行数:13,代码来源:test_itemized.py


示例17: test_amount_sched_a

 def test_amount_sched_a(self):
     [
         factories.ScheduleAFactory(contribution_receipt_amount=50),
         factories.ScheduleAFactory(contribution_receipt_amount=100),
         factories.ScheduleAFactory(contribution_receipt_amount=150),
         factories.ScheduleAFactory(contribution_receipt_amount=200),
     ]
     results = self._results(api.url_for(ScheduleAView, min_amount=100))
     self.assertTrue(all(each['contribution_receipt_amount'] >= 100 for each in results))
     results = self._results(api.url_for(ScheduleAView, max_amount=150))
     self.assertTrue(all(each['contribution_receipt_amount'] <= 150 for each in results))
     results = self._results(api.url_for(ScheduleAView, min_amount=100, max_amount=150))
     self.assertTrue(all(100 <= each['contribution_receipt_amount'] <= 150 for each in results))
开发者ID:18F,项目名称:openFEC,代码行数:13,代码来源:test_itemized.py


示例18: test_image_number_range

 def test_image_number_range(self):
     [
         factories.ScheduleAFactory(image_number='1'),
         factories.ScheduleAFactory(image_number='2'),
         factories.ScheduleAFactory(image_number='3'),
         factories.ScheduleAFactory(image_number='4'),
     ]
     results = self._results(api.url_for(ScheduleAView, min_image_number='2'))
     self.assertTrue(all(each['image_number'] >= '2' for each in results))
     results = self._results(api.url_for(ScheduleAView, max_image_number='3'))
     self.assertTrue(all(each['image_number'] <= '3' for each in results))
     results = self._results(api.url_for(ScheduleAView, min_image_number='2', max_image_number='3'))
     self.assertTrue(all('2' <= each['image_number'] <= '3' for each in results))
开发者ID:18F,项目名称:openFEC,代码行数:13,代码来源:test_itemized.py


示例19: test_null_pagination_with_null_sort_column_values_ascending

    def test_null_pagination_with_null_sort_column_values_ascending(self):
        filings = [
            factories.ScheduleAFactory(contribution_receipt_date=None)
            # this range should ensure the page has a null transition
            for _ in range(10)
            ]
        filings = filings + [
            factories.ScheduleAFactory(
                contribution_receipt_date=datetime.date(2016, 1, 1)
            )
            for _ in range(15)
            ]

        page1 = self._results(api.url_for(
            ScheduleAView,
            sort='contribution_receipt_date',
            sort_reverse_nulls='true',
            **self.kwargs
        ))

        self.assertEqual(len(page1), 20)

        top_reversed_from_middle = filings[10::]
        reversed_from_bottom_to_middle = filings[0:5:]
        top_reversed_from_middle.extend(reversed_from_bottom_to_middle)
        self.assertEqual(
            [int(each['sub_id']) for each in page1],
            [each.sub_id for each in top_reversed_from_middle],
        )
        self.assertEqual(
            [each['contribution_receipt_date'] for each in page1],
            [each.contribution_receipt_date.strftime('%Y-%m-%d') if each.contribution_receipt_date else None for each in
             top_reversed_from_middle]
        )
        page2 = self._results(api.url_for(
            ScheduleAView,
            last_index=page1[-1]['sub_id'],
            sort_null_only=True,
            sort='contribution_receipt_date',
            **self.kwargs
        ))
        self.assertEqual(len(page2), 5)
        self.assertEqual(
            [int(each['sub_id']) for each in page2],
            [each.sub_id for each in filings[5:10:]],
        )
        self.assertEqual(
            [each['contribution_receipt_date'] for each in page2],
            [each.contribution_receipt_date.strftime('%Y-%m-%d') if each.contribution_receipt_date else None for each in
             filings[5:10:]]
        )
开发者ID:18F,项目名称:openFEC,代码行数:51,代码来源:test_itemized.py


示例20: test_candidate_sort

 def test_candidate_sort(self):
     candidates = [
         factories.CandidateFactory(candidate_status='P'),
         factories.CandidateFactory(candidate_status='C'),
     ]
     candidate_ids = [each.candidate_id for each in candidates]
     results = self._results(api.url_for(CandidateList, sort='candidate_status'))
     self.assertEqual([each['candidate_id'] for each in results], candidate_ids[::-1])
     results = self._results(api.url_for(CandidateSearch, sort='candidate_status'))
     self.assertEqual([each['candidate_id'] for each in results], candidate_ids[::-1])
     results = self._results(api.url_for(CandidateList, sort='-candidate_status'))
     self.assertEqual([each['candidate_id'] for each in results], candidate_ids)
     results = self._results(api.url_for(CandidateSearch, sort='-candidate_status'))
     self.assertEqual([each['candidate_id'] for each in results], candidate_ids)
开发者ID:srinivasmalladi,项目名称:openFEC,代码行数:14,代码来源:test_candidates.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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