Beispiel #1
0
class RajaOngkirStarterApiTests(TestCase):

    def setUp(self):
        self.rajaongkir = RajaOngkirStarter('FakeAPI')
        BASE_URL = 'http://api.rajaongkir.com/starter'
        self.province_url = '{base_url}/{url}?'.format(
            base_url=BASE_URL, url='province'
        )

    def test_get_provinces(self, mock_get):
        mock_response = mock.Mock()

        expected_response = [
            {u'province': u'Bali', u'province_id': u'1'}
        ]
        mock_response.status_code = 200
        mock_response.text = json.dumps(expected_response)

        mock_get.return_value = mock_response
        response = self.rajaongkir.get_provinces()

        # mock_get.assert_called_once_with(self.province_url, headers={'key': 'FakeAPI'})
        #
        # self.assertEqual(1, mock_response.json.call_count)
        self.assertEqual(response, expected_response)
Beispiel #2
0
 def setUp(self):
     self.rajaongkir = RajaOngkirStarter('FakeAPI')
     BASE_URL = 'http://api.rajaongkir.com/starter'
     self.province_url = '{base_url}/{url}?'.format(
         base_url=BASE_URL, url='province'
     )