Beispiel #1
0
	def test_commands_displayed(self):
		with self.client:
			self.client.post(
				'/login',
				data=dict(username="******", password="******"),
				follow_redirects=True
			)
			db.session.add(Command(
				"s",
				"http://www.google.com/search?q=%s",
				"Google Search",
				getGroupId("global"),
				getUserId("ghooo")
			))
			db.session.add(Command(
				"p",
				"http://pastie.org/",
				"Pastie",
				getUserId("ghooo"),
				getUserId("ghooo")
			))
			db.session.commit()
			response = self.client.get(
				'/dashboard'
			)
			self.assertIn(b'Global Commands', response.data)
			self.assertIn(b'User Commands', response.data)
			self.assertIn(b'Google Search', response.data)
Beispiel #2
0
	def test_access_own_global_commands_only(self):
		db.session.add(Command( \
				"s", \
				"http://www.google.com/search?q=%s", \
				"Google Search", \
				getUserId("ghooo"), \
				getUserId("ghooo") \
				))
		db.session.add(Command( \
				"p", \
				"http://pastie.org", \
				"Pastie", \
				getUserId("omarayad1"), \
				getUserId("omarayad1") \
				))
		db.session.add(Command( \
				"t", \
				"https://translate.google.com/#en/ar/%s", \
				"Google Translate", \
				getGroupId("global"), \
				getUserId("omarayad1") \
				))
		with self.client:
			self.client.post(
				'/login',
				data=dict(username="******", password="******"),
				follow_redirects=True
			)

			# access global commands
			response = self.client.get(
				'/?q=t awesome'
			)
			self.assertIn(b'<a href="https://translate.google.com/#en/ar/'
					'awesome">https://translate.google.com/#en/ar/awesome</a>', 
					response.data)

			# access own commands
			response = self.client.get(
				'/?q=s awesome'
			)
			self.assertIn(b'<a href="http://www.google.com/search?q=awesome">'
					'http://www.google.com/search?q=awesome</a>', 
					response.data)

			# can not access other users commands
			response = self.client.get(
				'/?q=p'
			)
			self.assertIn(b'<a href="http://www.google.com/search?q=p">'
					'http://www.google.com/search?q=p</a>', 
					response.data)
Beispiel #3
0
	def test_with_cmd_id_empty_queryText(self):
		db.session.add(Command( \
				"s", \
				"http://www.google.com/search?q=%s", \
				"Google Search", \
				getGroupId("global"), \
				getUserId("ghooo") \
				))
		db.session.commit()
		response = self.client.get('/?q=s', 
				content_type='html/text')
		self.assertIn(b'<a href="http://www.google.com/search?q=">'
				'http://www.google.com/search?q=</a>', response.data)
Beispiel #4
0
	def test_commands_priority(self):
		db.session.add(Command( \
				"s", \
				"http://www.google.com/search?q=%s", \
				"Google Search", \
				getGroupId("global"), \
				getUserId("omarayad1") \
				))

		with self.client:
			self.client.post(
				'/login',
				data=dict(username="******", password="******"),
				follow_redirects=True
			)

			# access to global command
			response = self.client.get(
				'/?q=s awesome'
			)
			self.assertIn(b'<a href="http://www.google.com/search?q=awesome">'
					'http://www.google.com/search?q=awesome</a>', 
					response.data)

			# creating another command with the same cmd_id
			db.session.add(Command( \
					"s", \
					"http://www.bing.com/search?q=%s", \
					"Bing Search", \
					getUserId("ghooo"), \
					getUserId("ghooo") \
					))

			# should get the user command
			response = self.client.get(
				'/?q=s awesome'
			)
			self.assertIn(b'<a href="http://www.bing.com/search?q=awesome">'
					'http://www.bing.com/search?q=awesome</a>', 
					response.data)
	def processCommand(self):
		tokens = self.command.split(' ', 1)

		cmd_id = tokens[0]

		if len(tokens) > 1:
			commandText = tokens[1]
			commandText = urllib.quote(commandText.encode('utf8'), safe='')
		else:
			commandText = ""

		item = Command.query.filter_by(cmd_id=cmd_id,
				owner=current_user.get_id()).first()

		if item is None:
			item = Command.query.filter_by(cmd_id=cmd_id,
					owner=getGroupId('global')).first()

		if item is None:
			self.command = urllib.quote(self.command.encode('utf8'), safe='')
			return 'http://www.google.com/search?q=%s' % self.command
		else:
			data = item.url
			return data.replace('%s', commandText)
Beispiel #6
0
## groups
db.session.add(Group("global", "Global Group"))

## users
db.session.add(User("ghooo", "Mohamed", "Ghoneim", "ghooo", \
		"*****@*****.**"))
db.session.add(User("omarayad1", "Omar", "Ayad", "omarayad1", \
		"*****@*****.**"))

## commands
### global commands
db.session.add(Command( \
		"s", \
		"http://www.google.com/search?q=%s", \
		"Google Search", \
		getGroupId("global"), \
		getUserId("ghooo") \
		))

db.session.add(Command( \
		"g", \
		"http://www.google.com/search?q=%s", \
		"Google Search", \
		getGroupId("global"), \
		getUserId("ghooo") \
		))

db.session.add(Command( \
		"t", \
		"https://translate.google.com/#en/ar/%s", \
		"Google Translate", \