Ejemplo n.º 1
0
def debug():
	#print Event.get_events(end='2014-06-19')
	
	# Clear database of debug data first
	try: Surf.get_surf('Manual Surf').delete()
	except: pass
	try: Surf.get_surf('Auto Surf').delete()
	except: pass
	try: Surf.get_surf('Auto Surf Without Description').delete()
	except: pass
	try: Status.get_status('Status Without Description').delete()
	except: pass
	try: Status.get_status('Status With Description').delete()
	except: pass
	try: Status.get_status('Status2').delete()
	except: pass
	try: Surfice.get_surfice('Manual Surfice').delete()
	except: pass
	try: Surfice.get_surfice('Surfice').delete()
	except: pass
	try: Surfice.get_surfice('Surfice1').delete()
	except: pass
	try: Surfice.get_surfice('Surfice2').delete()
	except: pass
	
	
	# First test Surfs
	# First manually
	surf_manual = Surf()
	surf_manual.name = "Manual Surf"
	surf_manual.description = "A description of the manual surf"
	surf_manual.save_new()
	
	printv(surf_manual, "MANUAL SURF")
	
	# Now automatic Surf
	surf_auto_nodescr = Surf.create("Auto Surf Without Description")
	surf_auto = Surf.create("Auto Surf", "A Description for the Auto")
	printv(surf_auto_nodescr, "AUTO SURF W/O DESCRIPTION")
	printv(surf_auto, "AUTO SURF")
	
	# Now try to overwrite a Surf (it shouldn't work)
	surf_overwrite = Surf.create("Auto Surf")
	print "The following overwrite should not work:"
	try: printv(surf_overwrite, "SURF OVERWRITE")
	except: pass
	
	# Get a Surf by name
	surf_by_name = Surf.get_surf("Auto Surf")
	printv(surf_by_name, "GET AUTO SURF BY NAME")
	
	# Now delete the manual Surf
	surf_manual.delete()
	print "MANUAL SURF STILL SAVED AFTER DELETION? (Should be False)\n============================"
	print Surf.is_saved(name=surf_manual.name) # Test to see if it worked
	
	
	print "\n\n\n\n"
	
	
	# Second, create a new Status
	status_nodescr = Status.create("Status Without Description", color="#678434")
	status = Status.create("Status With Description", "A description", misc="haha")
	
	printv(status_nodescr, "STATUS W/O DESCRIPTION")
	printv(status, "STATUS WITH DESCRIPTION")
	print(status.data, "DATA of STATUS")
	
	# Get a status by name
	status_by_name = Status.get_status("Status Without Description")
	
	printv(status_by_name, "GET STATUS W/O DESCRIPTION BY NAME")
	
	# Delete the status without a description
	status_by_name.delete()
	
	print "NO DESCRIPTION STILL SAVED? (should be False)\n======================="
	print Status.is_saved(name="Status Without Description")
	
	status2 = Status.create("Status2", "A 2nd description", possible=5)






	# Now test Surfices
	# First manually
	surfice_manual = Surfice()
	surfice_manual.name = "Manual Surfice"
	surfice_manual.surf = surf_auto
	surfice_manual.description = "Manual Description"
	surfice_manual.status = status # I'm afraid this won't work at all
	surfice_manual.save_new()
	
	printv(surfice_manual, "MANUAL SURFICE")
	
	# Now Delete the manual one
	surfice_manual.delete()
	
	print "Is the Manual Surfice still saved (It should be False)\n========================"
	print Surfice.is_saved(name=surfice_manual.name)
	
	
	# Now Automatically
	surfice = Surfice.create("Surfice", surf_auto, status, "A Surfice description")
	surfice2 = Surfice.create("Surfice2", surf_auto, status, "A 2nd Surfice description")
	printv(surfice, "SURFICE")
	printv(surfice2, "SURFICE2")
	
	# Try to overwrite it
	surfice_overwrite = Surfice.create("Surfice", surf_auto, status)
	print surfice_overwrite
	
	# Get surfices
	print Surfice.get_surfices(surf=surf_auto) # All the surfices under surf_auto
	print Surfice.get_surfices(name="Surf") # All that contain "Surf"
	print Surfice.get_surfices() # All surfices
	
	
	surfice.set_surf(surf_auto_nodescr)
	surfice.set_description("I have a description now!")
	surfice.set_name("Surfice1")
	surfice.set_status(status2) # Just changes the status without making an event
	surfice.set_status(status, "What happened now?")
	surfice.set_status(status2, "Okay now we're back at status2")
	printv(surfice, "SURFICE1 UPDATED")
	
	
	
	# Delete everything
	try: surf_auto.delete()
	except: pass
	try: surf_auto_nodescr.delete()
	except: pass
	
	try: status_nodescr.delete()
	except: pass
	
	try: status.delete()
	except: pass
	try: status2.delete()
	except: pass
	
	try: surfice.delete()
	except: pass
	try: surfice2.delete()
	except: pass