Ejemplo n.º 1
0
def addPlayer(postVars):
	
	global couchdbServer
	
	templateVars = dict(saved = False)
	try:
		templateVars["name"] = postVars["playerName"].value.decode("utf-8")
		templateVars["birth"] = postVars["playerBirth"].value.decode("utf-8")
		templateVars["nickname"] = postVars["playerNickname"].value.decode("utf-8")
		
		tempImagePath = "/tmp/%s" % postVars["playerPhoto"].filename
		tempImageFile = open(tempImagePath ,"w")
		tempImageFile.write(postVars["playerPhoto"].value)
		tempImageFile.close();
		
		try:
			db = couchdbServer.create("players")
		except:
			db = couchdbServer["players"]
		
		player = Player()
		player.setName(templateVars["name"])
		player.birth = templateVars["birth"]
		player.nickname = templateVars["nickname"]
		player.setPhoto(tempImagePath)
		player.store(db)
		
		templateVars["saved"] = True
		
	except KeyError:
		name = u"undef"
		
	return output_template("addPlayer.html", templateVars)
Ejemplo n.º 2
0
	def testNewPlayer(self):
		player = Player()
		self.assertEqual(player.name, None),"Unable to instantiate Player"
		self.assertEqual(player.photo, None),"Unable to instantiate Player"
		self.assertEqual(player.karma, 400),"Unable to instantiate Player"
		self.assertEqual(player.setName("Ricardo"), True), "Unable to set player's name"
		self.assertEqual(player.setPhoto("invalid/path/to/image.jpg"), False), "Player's class is accepting invalid photo image"
		self.assertEqual(player.setPhoto("images/test-image.jpg"), True), "Player's class isn't accepting valid photo image"
		self.assertEqual(player.photo, "images/test-image.jpg"), "Player's class isn't accepting valid photo image"
Ejemplo n.º 3
0
	def testSnapshots(self):

		server = Server()
		try:
			db = server.create("players")
		except:
			db = server["players"]

		bolivar = Player()
		bolivar.setName("Bolivar")
		bolivar.setPhoto("images/bolivar.jpg")
		bolivar.setKarma(288)
		bolivar.store(db)

		indio = Player()
		indio.setName("Indio")
		indio.setPhoto("images/indio.jpg")
		indio.setKarma(388)
		indio.store(db)

		ss = Snapshot()
		ss.description = "Teste de snapshot"
		self.assertEqual(ss.takeSnapshot(), True), "Error taking snapshot"

		try:
			server.delete("snapshots")
		except:
			pass

		try:
			db = server.create("snapshots")
		except:
			db = server["snapshots"]

		ss.store(db)

		ss = Snapshot.load(db,ss.id)
		server.delete(ss.name)
		server.delete("snapshots")
Ejemplo n.º 4
0
	def testPlayerDb(self):

		server = Server()
		try:
			db = server.create("players")
		except:
			db = server["players"]

		bolivar = Player()
		bolivar.setName("Bolivar")
		bolivar.setPhoto("images/bolivar.jpg")
		bolivar.store(db)

		indio = Player()
		indio.setName("Indio")
		indio.setPhoto("images/indio.jpg")
		indio.store(db)
		
		nei = Player()
		nei.setName("Nei")
		nei.setPhoto("images/nei.jpg")
		nei.store(db)

		server.delete("players")