class CreateBookTest(unittest.TestCase):
	def setUp(self):
		self.api = ApiClient('#your_api_key', '#your_api_secret', 'http://restful.jamiecressey.com:5000')
		self.title = str(int(time()))

	def test_createBook(self):
		_resp = self.api.post('/books/', {
			'title': self.title
		})
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'title': self.title}, _resp.content)

		_resp = self.api.get('/book/{0}/'.format(self.title))	
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'title': self.title}, _resp.content)

		_resp = self.api.put('/book/{0}/'.format(self.title), {
			'author': 'Jamie Cressey'
		})
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'author': 'Jamie Cressey'}, _resp.content)

		_resp = self.api.put('/book/{0}/'.format(self.title), {
			'release_date': '01/01/2001'
		})
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'release_date': '01/01/2001'}, _resp.content)

		_resp = self.api.get('/book/{0}/'.format(self.title))	
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'title': self.title, 'author': 'Jamie Cressey', 'release_date': '01/01/2001'}, _resp.content)

		_resp = self.api.delete('/book/{0}/'.format(self.title))	
		self.assertEqual(_resp.ok(), True)
		self.assertDictContainsSubset({'message': 'Book deleted'}, _resp.content)
Ejemplo n.º 2
0
class CreateBookTest(unittest.TestCase):
    def setUp(self):
        self.api = ApiClient('#your_api_key', '#your_api_secret',
                             'http://restful.jamiecressey.com:5000')
        self.title = str(int(time()))

    def test_createBook(self):
        _resp = self.api.post('/books/', {'title': self.title})
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'title': self.title}, _resp.content)

        _resp = self.api.get('/book/{0}/'.format(self.title))
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'title': self.title}, _resp.content)

        _resp = self.api.put('/book/{0}/'.format(self.title),
                             {'author': 'Jamie Cressey'})
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'author': 'Jamie Cressey'},
                                      _resp.content)

        _resp = self.api.put('/book/{0}/'.format(self.title),
                             {'release_date': '01/01/2001'})
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'release_date': '01/01/2001'},
                                      _resp.content)

        _resp = self.api.get('/book/{0}/'.format(self.title))
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset(
            {
                'title': self.title,
                'author': 'Jamie Cressey',
                'release_date': '01/01/2001'
            }, _resp.content)

        _resp = self.api.delete('/book/{0}/'.format(self.title))
        self.assertEqual(_resp.ok(), True)
        self.assertDictContainsSubset({'message': 'Book deleted'},
                                      _resp.content)
#!/usr/bin/env python
from RestfulClient.api import ApiClient

api = ApiClient('#key', '#secret', 'http://localhost:5000')

req = api.get('/')
req = api.put('/')
req = api.delete('/')
req = api.post('/')

if req.ok():
	print 'Success!'
else:
	print req.errors()
Ejemplo n.º 4
0
#!/usr/bin/env python
from RestfulClient.api import ApiClient

api = ApiClient('#key', '#secret', 'http://localhost:5000')

req = api.get('/')
req = api.put('/')
req = api.delete('/')
req = api.post('/')

if req.ok():
    print 'Success!'
else:
    print req.errors()