示例#1
0
    def test_data_rendering(self):
        bill = factories.fake_bill_detail()
        bill_id = bill['bill_id']
        session = bill['session']

        with mock_fetch() as fetch:
            fetch.bill_detail.return_value = bill
            html = render_view('openstates:bill-detail',
                               kwargs={
                                   'session': session,
                                   'id': bill_id
                               })

        fetch.bill_detail.assert_called_once_with(session=session, pk=bill_id)

        assert bill_id in html
        assert bill['title'] in html
        assert bill['subjects'][0] in html
        assert str(session) in html

        action, date = list(bill['action_dates'].items())[0]
        date, timestamp = date.split()
        assert action in html
        assert date in html
        assert timestamp not in html

        vote = bill['votes'][0]
        date, timestamp = vote['date'].split()
        assert date in html
        assert timestamp not in html
        assert str(vote['yes_count']) in html
        assert str(vote['no_count']) in html
        assert vote['chamber'] in html
示例#2
0
    def test_data_rendering(self):
        legislator = fake_legislator()
        detail_url = reverse('openstates:legislator-detail', args=(legislator['leg_id'],))

        with mock_fetch() as fetch:
            fetch.legislators.return_value = [legislator]
            html = render_view('openstates:legislator-list')

        assert detail_url in html
        for value in legislator.values():
            assert value in html
示例#3
0
    def test_data_rendering(self):
        legislator = factories.fake_legislator()
        leg_id = legislator['leg_id']

        with mock_fetch() as fetch:
            fetch.legislators.return_value = legislator
            html = render_view('openstates:legislator-detail', args=(leg_id, ))

        fetch.legislators.assert_called_once_with(leg_id)
        assert legislator['full_name'] in html
        assert legislator['district'] in html
        assert legislator['party'] in html
        assert legislator['chamber'] in html
示例#4
0
    def test_data_rendering(self):
        bill = factories.fake_bill()
        detail_url = reverse('openstates:bill-detail',
                             args=(bill['session'], bill['bill_id']))

        with mock_fetch() as fetch:
            fetch.bills.return_value = [bill]
            html = render_view('openstates:bill-list')

        assert detail_url in html
        assert bill['bill_id'] in html
        assert bill['title'] in html
        assert bill['subjects'] in html
        assert bill['session'] in html
示例#5
0
    def test_data_rendering(self):
        legislator = factories.fake_legislator()
        detail_url = reverse('openstates:legislator-detail',
                             args=(legislator['openstates_leg_id'], ))

        with mock_fetch() as fetch:
            fetch.legislators.return_value = [legislator]
            html = render_view('openstates:legislator-list')

        assert detail_url in html
        assert legislator['openstates_leg_id'] in html
        assert legislator['name'] in html
        assert legislator['district'] in html
        assert legislator['party'] in html
        assert legislator['chamber'] in html
示例#6
0
    def test_data_rendering(self):
        bill = {
            'bill_id': FAKE.pystr(),
            'title': FAKE.pystr(),
            'subjects': FAKE.pystr(),
            'session': str(FAKE.pyint()),
        }
        detail_url = reverse('openstates:bill-detail', args=(bill['session'], bill['bill_id']))

        with mock_fetch() as fetch:
            fetch.bills.return_value = [bill]
            html = render_view('openstates:bill-list')

        assert detail_url in html
        for key, value in bill.items():
            assert value in html
示例#7
0
    def test_data_rendering(self):
        bill_id = FAKE.pystr()
        session = FAKE.pyint()
        bill = {
            'bill_id': bill_id,
            'title': FAKE.pystr(),
            'subjects': [FAKE.pystr()],
            'session': session,
            'action_dates': {
                FAKE.pystr(): fake_openstates_timestamp(),
            },
            'votes': [{
                'date': fake_openstates_timestamp(),
                'yes_count': FAKE.pyint(),
                'no_count': FAKE.pyint(),
                'chamber': FAKE.pystr(),
            }],
        }

        with mock_fetch() as fetch:
            fetch.bill_detail.return_value = bill
            html = render_view('openstates:bill-detail',
                                       kwargs={'session': session, 'id': bill_id})

        fetch.bill_detail.assert_called_once_with(session=session, pk=bill_id)

        assert bill_id in html
        assert bill['title'] in html
        assert bill['subjects'][0] in html
        assert str(session) in html

        action, date = list(bill['action_dates'].items())[0]
        date, timestamp = date.split()
        assert action in html
        assert date in html
        assert timestamp not in html

        vote = bill['votes'][0]
        date, timestamp = vote['date'].split()
        assert date in html
        assert timestamp not in html
        assert str(vote['yes_count']) in html
        assert str(vote['no_count']) in html
        assert vote['chamber'] in html
示例#8
0
 def test_legislator_not_found(self):
     with mock_fetch() as fetch:
         fetch.legislators.return_value = None
         with self.assertRaises(Http404):
             render_view('openstates:legislator-detail',
                         kwargs={'openstates_leg_id': FAKE.pystr()})
示例#9
0
def test_api_key_required_view():
    html = render_view('openstates:api-key-required')
    assert 'https://openstates.org/api/register/' in html
示例#10
0
 def test_bill_not_found(self):
     bill_kwargs = {'session': FAKE.pyint(), 'id': FAKE.pystr()}
     with mock_fetch() as fetch:
         fetch.bill_detail.return_value = None
         with self.assertRaises(Http404):
             render_view('openstates:bill-detail', kwargs=bill_kwargs)
示例#11
0
def test_index_view():
    html = render_view('openstates:index')
    assert reverse('openstates:legislator-list') in html
    assert reverse('openstates:bill-list') in html