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)
示例#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)
示例#3
0
        continue

    print 'Iniciando o envio de dados para o servidor'

    if os.path.isfile(arquivo_backup) == True:
        enviaBackuspParaServidor()

    for i, val in enumerate(_valsSplit):

        if i == len(sensores):
            continue

        _time = time.strftime("%d/%m/%Y %H:%M:%S")

        try:
            req = api.get('/sensor_data/send?data=' + _time + '&' +
                          sensores[i] + '=' + val)

            if req.ok():
                print 'Dado enviado com sucesso, iluminati.'
            else:
                print 'Comunicacao com servidor falhou. Salvando dados local...'
                salvaLocal(_time, i, val)

        except Exception, e:
            print 'Comunicacao com servidor falhou. Salvando dados local...'
            salvaLocal(_time, i, val)
        else:
            pass
        finally:
            pass
示例#4
0
文件: com.py 项目: renancunha/sitecur
		continue

	print 'Iniciando o envio de dados para o servidor'

	if os.path.isfile(arquivo_backup) == True:
		enviaBackuspParaServidor()

	for i, val in enumerate(_valsSplit):

		if i == len(sensores):
			continue

		_time = time.strftime("%d/%m/%Y %H:%M:%S")

		try:
			req = api.get('/sensor_data/send?data=' + _time + '&' + sensores[i] + '=' + val)

			if req.ok():
			    print 'Dado enviado com sucesso, iluminati.'
			else:
				print 'Comunicacao com servidor falhou. Salvando dados local...'
				salvaLocal(_time, i, val)

		except Exception, e:
			print 'Comunicacao com servidor falhou. Salvando dados local...'
			salvaLocal(_time, i, val)
		else:
			pass
		finally:
			pass
	
#!/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()
示例#6
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()