PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/gkcore/tests/test_delchal.py

https://gitlab.com/bbhavesh07/gkcore
Python | 194 lines | 173 code | 0 blank | 21 comment | 0 complexity | 7024a2829caaccf3d7728408e9da64b9 MD5 | raw file
  1. """
  2. Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
  3. This file is part of GNUKhata:A modular,robust and Free Accounting System.
  4. GNUKhata is Free Software; you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as
  6. published by the Free Software Foundation; either version 3 of
  7. the License, or (at your option) any later version.
  8. GNUKhata is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public
  13. License along with GNUKhata (COPYING); if not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301 USA59 Temple Place, Suite 330,
  16. Contributors:
  17. "Vaibhav Kurhe" <vaibhav.kurhe@gmail.com>
  18. """
  19. import requests, json
  20. class TestDelChal:
  21. @classmethod
  22. def setup_class(self):
  23. orgdata = {"orgdetails":{'orgname': 'Test Organisation', 'yearend': '2016-03-31', 'yearstart': '2015-04-01', 'orgtype': 'Profit Making', 'invflag': 1}, "userdetails":{"username":"admin", "userpassword":"admin","userquestion":"who am i?", "useranswer":"hacker"}}
  24. result = requests.post("http://127.0.0.1:6543/organisations",data=json.dumps(orgdata))
  25. self.key = result.json()["token"]
  26. self.header={"gktoken":self.key}
  27. """ User creation """
  28. """ Check and delete the user creation if it's not being used! """
  29. userdata = {"username":"user","userpassword":"passwd","userrole":0,"userquestion":"what is my pet name?","useranswer":"cat"}
  30. result = requests.post("http://127.0.0.1:6543/users", data=json.dumps(userdata), headers=self.header)
  31. result = requests.get("http://127.0.0.1:6543/users", headers=self.header)
  32. for record in result.json()["gkresult"]:
  33. if record["username"] == "user":
  34. self.userid = record["userid"]
  35. break
  36. """ Customer and Supplier creation """
  37. """ Doubt: This should be a customer or supplier? I have created both!"""
  38. custdata = {"custname":"customer","custaddr":"goregaon","custphone":"22432123","custemail":"customer@gmail.com","custfax":"FAXCUST212345","state":"Maharashtra","custpan":"CUSTPAN1234","custtan":"CUSTTAN1234","csflag":3}
  39. result = requests.post("http://127.0.0.1:6543/customersupplier",data=json.dumps(custdata),headers=self.header)
  40. result = requests.get("http://127.0.0.1:6543/customersupplier?qty=custall", headers=self.header)
  41. for record in result.json()["gkresult"]:
  42. if record["custname"] == "customer":
  43. self.custid = record["custid"]
  44. break
  45. """ supid is used to store custid attribute """
  46. custdata = {"custname":"supplier","custaddr":"borivali","custphone":"44432123","custemail":"supplier@gmail.com","custfax":"FAXSUP212345","state":"Maharashtra","custpan":"SUPPAN1234","custtan":"SUPTAN1234","csflag":19}
  47. result = requests.post("http://127.0.0.1:6543/customersupplier",data=json.dumps(custdata),headers=self.header)
  48. result = requests.get("http://127.0.0.1:6543/customersupplier?qty=supall", headers=self.header)
  49. for record in result.json()["gkresult"]:
  50. if record["custname"] == "supplier":
  51. self.supid = record["custid"]
  52. break
  53. """ setup() is also combined with setup_class()"""
  54. """ Product Creation """
  55. categorydata = {"categoryname":"Test Category", "subcategoryof": None}
  56. result = requests.post("http://127.0.0.1:6543/categories",data=json.dumps(categorydata) ,headers=self.header)
  57. print "categories creation: ", result.json()["gkstatus"]
  58. result = requests.get("http://127.0.0.1:6543/categories", headers=self.header)
  59. for record in result.json()["gkresult"]:
  60. if record["categoryname"] == "Test Category":
  61. self.democategorycode = record["categorycode"]
  62. break
  63. uomdata = {"unitname":"kilogram"}
  64. result = requests.post("http://127.0.0.1:6543/unitofmeasurement", data = json.dumps(uomdata), headers=self.header)
  65. print "unitofmeasurement creation: ", result.json()["gkstatus"]
  66. result = requests.get("http://127.0.0.1:6543/unitofmeasurement?qty=all", headers=self.header)
  67. for record in result.json()["gkresult"]:
  68. if record["unitname"] == "kilogram":
  69. self.demouomid = record["uomid"]
  70. break
  71. specdata= {"attrname":"Type","attrtype":0,"categorycode":self.democategorycode}
  72. specresult = requests.post("http://127.0.0.1:6543/categoryspecs",data=json.dumps(specdata) ,headers=self.header)
  73. print "category-specs creation: ", result.json()["gkstatus"]
  74. result = requests.get("http://127.0.0.1:6543/categoryspecs?categorycode=%d"%(int(self.democategorycode)), headers=self.header)
  75. for record in result.json()["gkresult"]:
  76. if record["attrname"] == "Type":
  77. self.demospeccode = record["spcode"]
  78. break
  79. proddetails = {"productdesc":"Sugar","specs":{self.demospeccode: "Pure"}, "uomid":self.demouomid, "categorycode": self.democategorycode}
  80. productdetails = {"productdetails":proddetails, "godetails":None, "godownflag":False}
  81. result = requests.post("http://127.0.0.1:6543/products", data=json.dumps(productdetails),headers=self.header)
  82. print "product creation: ", result.json()["gkstatus"]
  83. self.demoproductcode = result.json()["gkresult"]
  84. """ Creating Delchallan """
  85. """ In this testcase, godown is not linked with Delivery Challan """
  86. self.qty = 1
  87. products = {self.demoproductcode: self.qty}
  88. delchaldata = {"custid":self.custid,"dcno":"15","dcdate":"2016-03-30","dcflag":16, "noofpackages":2, "modeoftransport":"By Road"}
  89. """ inout = 9 means stock is IN and inout = 15 means stock is OUT """
  90. stockdata = {"inout": 9, "items": products}
  91. self.demo_delchalwholedata = {"delchaldata": delchaldata, "stockdata": stockdata}
  92. result = requests.post("http://127.0.0.1:6543/delchal",data=json.dumps(self.demo_delchalwholedata),headers=self.header)
  93. print "delchal creation: ", result.json()["gkstatus"]
  94. result = requests.get("http://127.0.0.1:6543/delchal?delchal=all", headers=self.header)
  95. for record in result.json()["gkresult"]:
  96. if record["dcno"] == "15":
  97. self.demo_delchalid = record["dcid"]
  98. break
  99. @classmethod
  100. def teardown_class(self):
  101. """ Actually no need to do all this before deleting an organisation. Since, organisation can be deleted directly which deltes all the data underneath it. Still we have done."""
  102. deldata = {"dcid": self.demo_delchalid,"cancelflag": 1}
  103. result = requests.delete("http://127.0.0.1:6543/delchal",data=json.dumps(deldata), headers=self.header)
  104. print "delchal delete: ", result.json()["gkstatus"]
  105. result = requests.delete("http://127.0.0.1:6543/products", data=json.dumps({"productcode":int(self.demoproductcode)}),headers=self.header)
  106. print "products delete: ", result.json()["gkstatus"]
  107. result = requests.delete("http://127.0.0.1:6543/categoryspecs",data=json.dumps({"spcode": int(self.demospeccode)}) ,headers=self.header)
  108. print "categoryspecs delete: ", result.json()["gkstatus"]
  109. gkdata = {"categorycode": self.democategorycode}
  110. result = requests.delete("http://127.0.0.1:6543/categories", data =json.dumps(gkdata), headers=self.header)
  111. print "categories delete: ", result.json()["gkstatus"]
  112. result = requests.delete("http://127.0.0.1:6543/organisations", headers=self.header)
  113. print "organisations delete: ", result.json()["gkstatus"]
  114. result = requests.delete("http://127.0.0.1:6543/unitofmeasurement", data = json.dumps({"uomid":self.demouomid}), headers=self.header)
  115. print "unitofmeasurement delete: ", result.json()["gkstatus"]
  116. def test_create_and_delete_delchal(self):
  117. """ Create and Delete Delivery Challan """
  118. """
  119. IMP Doubt: In this testcase, godown is not linked with Delivery Challan
  120. So, how it gets the quantity? and how and where it gets stored in the database table stock?
  121. """
  122. """ Create Delivery Challan """
  123. qty = 2
  124. products = {self.demoproductcode: qty}
  125. delchaldata = {"custid": self.custid, "dcno": "30", "dcdate": "2016-03-10", "dcflag": 3, "noofpackages":2, "modeoftransport":"By Road"}
  126. """ 'inout = 9' means stock is IN and 'inout = 15' means stock is OUT """
  127. stockdata = {"inout": 9, "items": products}
  128. delchalwholedata = {"delchaldata":delchaldata,"stockdata":stockdata}
  129. result = requests.post("http://127.0.0.1:6543/delchal",data=json.dumps(delchalwholedata),headers=self.header)
  130. """ Delete Delivery Challan """
  131. delchals = requests.get("http://127.0.0.1:6543/delchal?delchal=all", headers=self.header)
  132. for record in delchals.json()["gkresult"]:
  133. if record["dcno"] == "30":
  134. self.delchalid = record["dcid"]
  135. break
  136. deldata = {"dcid": self.delchalid,"cancelflag": 1}
  137. result = requests.delete("http://127.0.0.1:6543/delchal",data=json.dumps(deldata), headers=self.header)
  138. print "delchal: status ",result.json()["gkstatus"]
  139. assert result.json()["gkstatus"] == 0
  140. def test_update_delchal(self):
  141. delchalwholedata = self.demo_delchalwholedata
  142. delchaldata = delchalwholedata["delchaldata"]
  143. delchaldata["dcid"] = self.demo_delchalid
  144. stockdata = delchalwholedata["stockdata"]
  145. delchaldata["dcno"] = 16
  146. delchaldata["dcdate"] = "2016-03-29"
  147. result=requests.put("http://127.0.0.1:6543/delchal",data=json.dumps(delchalwholedata),headers=self.header)
  148. assert result.json()["gkstatus"] == 0
  149. def test_get_all_delchal(self):
  150. delchals = requests.get("http://127.0.0.1:6543/delchal?delchal=all", headers=self.header)
  151. assert delchals.json()["gkstatus"] == 0
  152. def test_get_single_delchal(self):
  153. delchaldata = requests.get("http://127.0.0.1:6543/delchal?delchal=single&dcid=%d"%(int(self.demo_delchalid)), headers=self.header)
  154. result = delchaldata.json()["gkresult"]
  155. dc = result["delchaldata"]
  156. stock = result["stockdata"]
  157. assert dc["dcno"] == "15" and dc["dcflag"] == 16 and dc["dcdate"] == "30-03-2016" and dc["custid"] == self.custid
  158. def test_getLastDelChalDetails(self):
  159. qty = 2
  160. products = {self.demoproductcode: qty}
  161. delchaldata = {"custid": self.custid, "dcno": "31", "dcdate": "2016-03-10", "dcflag": 4, "noofpackages":2, "modeoftransport":"By Road"}
  162. """ 'inout = 9' means stock is IN and 'inout = 15' means stock is OUT """
  163. stockdata = {"inout": 9, "items": products}
  164. delchalwholedata = {"delchaldata":delchaldata,"stockdata":stockdata}
  165. result = requests.post("http://127.0.0.1:6543/delchal",data=json.dumps(delchalwholedata),headers=self.header)
  166. delchaldata = {"custid": self.custid, "dcno": "32", "dcdate": "2016-03-10", "dcflag": 4, "noofpackages":2, "modeoftransport":"By Road"}
  167. stockdata = {"inout": 9, "items": products}
  168. delchalwholedata = {"delchaldata":delchaldata,"stockdata":stockdata}
  169. result = requests.post("http://127.0.0.1:6543/delchal",data=json.dumps(delchalwholedata),headers=self.header)
  170. ''' two delivery challan entries made and now trying to fetch last made entry '''
  171. delchaldata = requests.get("http://127.0.0.1:6543/delchal?delchal=last&dcflag=4", headers=self.header)
  172. assert delchaldata.json()["gkresult"]["dcno"] == "32" and delchaldata.json()["gkresult"]["dcdate"] == "10-03-2016"