def test_get_data_request_uri(self): mock = MagicMock(return_value=RequestsResponse( {'votering': {'dokvotering': []}}) ) with patch('requests.get', mock): get_votation(self.votation_id) mock.assert_called_with( '{0}/votering/{1}/json'.format(API_URL, self.votation_id))
def test_get_data_request_uri(self): mock = MagicMock( return_value=RequestsResponse({'votering': { 'dokvotering': [] }})) with patch('requests.get', mock): get_votation(self.votation_id) mock.assert_called_with('{0}/votering/{1}/json'.format( API_URL, self.votation_id))
def test_invalid_json_document_returned(self): '''Shouldn't raise errors, log a message saying what went wrong''' mock = MagicMock(return_value=RequestsResponse('')) with LogCapture() as l: with patch('requests.get', mock): get_votation(self.votation_id) l.check( ('riksdagen', 'ERROR', 'Invalid JSON document for votation ' '"75F2D01D-4EE1-11D7-AE75-006008577F08".') )
def test_get_data_parse(self): mock = MagicMock(return_value=RequestsResponse( json.load(open('tests/fixtures/votation-{0}.json'.format( self.votation_id))) )) with patch('requests.get', mock): data = get_votation(self.votation_id) first_voter = data[0] self.assertEqual(first_voter['beteckning'], 'UBU7') self.assertEqual(first_voter['namn'], 'Gunnar Hökmark')
def test_get_data_parse(self): mock = MagicMock(return_value=RequestsResponse( json.load( open('tests/fixtures/votation-{0}.json'.format( self.votation_id))))) with patch('requests.get', mock): data = get_votation(self.votation_id) first_voter = data[0] self.assertEqual(first_voter['beteckning'], 'UBU7') self.assertEqual(first_voter['namn'], 'Gunnar Hökmark')