A systematic way to test RESTful APIs with curl?
You could look at tools such as Postman which focuses on testing REST APIs with JavaScript - it has some nice features but you lose the use of Python.

Instead, I'd suggest looking at REST-related plugins for pytest, a Python test framework that simplifies your test code, while still running tests written using unittest. 


For example, writing parameterised tests avoids boring and error-prone duplicate test code.


Pytest has a huge set of plugins that simplify various tasks, including:


Tavern, which specialises in testing REST APIs and seems highly relevant here - sort of "Postman for Python unit tests". 
pytest-curl-report - when  testing with the requests library, will print a curl command you can use to reproduce the error from shell. 
Testinfra - focuses on server testing (e.g. state of OS packages, files, processes, etc, usually tested on remote servers) - strongly recommended if you also need this type  e.g. to test Ansible code.


For those who use Puppet or Chef, Testinfra is similar to Beaker (with RSpec), ServerSpec or InSpec.



If you don't like Tavern, you can of course use pycurl with pytest, which makes it easier to diagnose exactly what failed. This example from the pytest-curl-report site uses only generic pytest features:

$ py.test test.py
============================= test session starts ==============================
platform darwin -- Python 2.7.9 -- py-1.4.27 -- pytest-2.6.4
plugins: curl-report, httpbin, cache, capturelog, cov, flakes, pep8
collected 1 items

test.py F

=================================== FAILURES ===================================
______________________________ test_requests_get _______________________________

    def test_requests_get():
        r = requests.get('http://httpbin.org/get')
&gt;       assert False
E       assert False

test.py:7: AssertionError


Pytest lets you write all tests with a plain assert, and optionally include a helpful message as part of the output.  For example, one of your tests could be written:

def test_2():
    assert pycurl.response("some_url").matches ("xxx"), "xxx not found in response"