dimanche 1 juillet 2018

Test JSON string in Python

I getting a JSON data from an API and testing if the "Description" value is "Plunket". Currently, I have the following:

import unittest
import json
import requests

class TestJSON(unittest.TestCase):
    def test_description(self):
        api_url_base = 'https://api.tmsandbox.co.nz/v1/Categories/6328/Details.json?catalogue=false'
        r = requests.get(api_url_base)
        d1 = json.dumps(r.json())
        self.assertIn('"Description":"Plunket"', d1)

if __name__ == '__main__':
    unittest.main()  

I am wondering if I am on the right track or if I have used the correct assert statement

Aucun commentaire:

Enregistrer un commentaire