本文整理汇总了Python中webservices.rest.api.url_for函数的典型用法代码示例。如果您正苦于以下问题:Python url_for函数的具体用法?Python url_for怎么用?Python url_for使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_for函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'])
示例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],
)
示例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'])
示例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'])
示例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'])
示例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)
示例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
)
)
示例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])
示例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'])
示例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)
示例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])
示例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:]]
)
示例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)
示例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"]))
示例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))