test_restapi.py 1.32 KB
Newer Older
Prasad's avatar
Prasad committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#!/bin/python
# The content of this file is subject to ("Vtiger Public License 1.2") refer to LIECENSE for more details.
# Copyright (c) Vtiger.
# All Rights Reserved.
 
import unittest
import vtiger_cloudsdk_restapi

class TestRestApi(unittest.TestCase):

	def setUp(self):
		self.__client = vtiger_cloudsdk_restapi.Client(
			"" #url
			"", #user
                        "", #pass
		)
		self.__MOCK_TEST_ACCOUNTNAME = "TestRestApiPython"

	def fetchMockTestAccount(self):
		records = self.__client.query("SELECT * FROM Accounts WHERE accountname = '"+ self.__MOCK_TEST_ACCOUNTNAME + "'" + " LIMIT 1;")
		return records.pop()

	def testMe(self):
		self.__client.me()

	def testListTypes(self):
		self.__client.list_types()

	def testDescribe(self):
		self.__client.describe("Accounts")

	def testCreate(self):
		self.__client.create("Accounts", {
			"accountname": self.__MOCK_TEST_ACCOUNTNAME,
			"assigned_user_id": self.__client.myid()
		})

	def testQuery(self):
		self.fetchMockTestAccount()

	def testUpdate(self):
		record = self.fetchMockTestAccount()
		record["website"] = "www.404.com"
		self.__client.update(record)

	def testRevise(self):
		account = self.fetchMockTestAccount()
		record = {}
		record["id"] = account["id"]
		record["website"] = "www.404-rev.com"
		self.__client.revise(record)


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