Esempio n. 1
0
	def test_14_command_a(self):
		self.assertEqual(rest.encode('', 'A', '3', 'message'), ('post/interests/interest', {
				'title': 'message',
				'description': '',
				'distance': '10',
				'expire': 3 * 24,
				'latitude': rest.FAKE_LATITUDE,
				'longitude': rest.FAKE_LONGITUDE,
			}))
Esempio n. 2
0
	def test_54_command_r(self):
		self.assertEqual(rest.encode('', 'R', '3', 'message'), ('renew/interests/interest/0003000', {}))
Esempio n. 3
0
	def test_53_command_r(self):
		rest.key_value.add('i', '0003000', '3')
		self.assertEqual(rest.encode('', 'R', '3', ''), ('renew/interests/interest/0003000', {}))
Esempio n. 4
0
	def test_52_command_r(self):
		self.assertEqual(rest.encode('user2', 'R', '', 'message'), ('post/users/register', {'mobile_number': 'user2'}))
Esempio n. 5
0
	def test_49_command_m(self):
		rest.key_value.remove('m', '0001000', '3M1')
		with self.assertRaises(rest.UnknownCommandError):
			rest.encode('', 'M', ('3','1'), 'message')
Esempio n. 6
0
	def test_47_command_m(self):
		with self.assertRaises(rest.UnknownCommandError):
			rest.encode('', 'M', ('3','3'), 'message')
Esempio n. 7
0
	def test_64_command_u(self):
		self.assertEqual(rest.encode('', 'U', '3', 'message'), ('post/users/unregister', {}))
Esempio n. 8
0
	def test_32_command_d(self):
		self.assertEqual(rest.encode('', 'D', '', 'message'), ('', {}))
Esempio n. 9
0
	def test_33_command_d(self):
		rest.key_value.add('i', '0001000', '1')
		self.assertEqual(rest.encode('', 'D', '1', ''), ('delete/interests/interest/0001000', {}))
Esempio n. 10
0
	def test_26_command_i(self):
		rest.key_value.remove('i', '0002000', '2')
		with self.assertRaises(rest.NoInterestError):
			rest.encode('', 'I', '2', 'message')
Esempio n. 11
0
	def test_31_command_d(self):
		self.assertEqual(rest.encode('', 'D', '', ''), ('', {}))
Esempio n. 12
0
	def test_24_command_i(self):
		rest.key_value.add('i', '0002000', '2')
		self.assertEqual(rest.encode('', 'I', '2', 'message'), ('get/interests/matches/0002000', {}))
Esempio n. 13
0
	def test_23_command_i(self):
		rest.key_value.add('i', '0001000', '1')
		self.assertEqual(rest.encode('', 'I', '1', ''), ('get/interests/matches/0001000', {}))
Esempio n. 14
0
	def test_22_command_i(self):
		self.assertEqual(rest.encode('', 'I', '', 'message'), ('get/interests/list', {}))
Esempio n. 15
0
	def test_55_command_r(self):
		rest.key_value.remove('i', '0003000', '3')
		with self.assertRaises(rest.NoInterestError):
			rest.encode('', 'R', '3', '')
Esempio n. 16
0
	def test_34_command_d(self):
		rest.key_value.add('i', '0002000', '2')
		self.assertEqual(rest.encode('', 'D', '2', 'message'), ('delete/interests/interest/0002000', {}))
Esempio n. 17
0
	def test_56_command_r(self):
		with self.assertRaises(rest.NoInterestError):
			rest.encode('', 'R', '3', 'message')
Esempio n. 18
0
	def test_37_command_d(self):
		rest.key_value.remove('i', '0001000', '1')
		with self.assertRaises(rest.NoInterestError):
			rest.encode('', 'D', '1', 'message')
Esempio n. 19
0
def start(txt, usr, op):
	rest.key_value = rest.kv.KeyValue(usr, rest.send)
	sms = ''
	
	for command in txt.split('|'):
		cmd, lid, msg = parse(command)
		try:
			url, params = rest.encode(op, usr, cmd, lid, msg)
		except rest.NoInterestError:
			sms += "There is no ad 'AD{}'.\nYour ads are:\n".format(lid)
			cmd, lid, msg = 'I', '', ''
			url, params = rest.encode(op, usr, cmd, lid, msg)
		except rest.NoMatchError:
			if lid == '':
				sms += 'There is no conversation going on.\nPlease specify a match number.'
			else:
				sms += "There is no match 'AD{}'.\nPlease specify the correct match number.".format(lid[0] + "M" + lid[1])
			break
		except rest.UnknownCommandError:
			auth = rest.checkAuth(usr)
			if auth:
				if auth == '401':
					if op == 'zong':
						#sms = "Welcome to Dialog MyTrader. You can now post any amount of ads for just Rs1+tax a day. Just subscribe to the service by sending SUB to 289. (Conditions Apply).".format(product(op))
						sms = "Welcome to Dialog MyTrader! To subscribe to the service send SUB to 289. ".format(product(op))
					elif op == 'warid':
						sms = "Please subscribe for using {}.\nYou can subscribe by sending SUB to 8225 for weekly, SUB to 8226 for Monthly, SUB to 8227 for Business package.\n".format(product(op))
					else :
						sms = "Please subscribe for using Mmatcher. You can subscribe by sending sub<space>free to this number. Thanks.".format(product(op))
					break
				else:
					if cmd == 'SHORT':
						sms += 'Your sent ad needs more details. To sell, send SELL<space> ad to 289. To buy, send BUY<space> ad to 289. '
						#sms += 'Your sent ad needs more details such as Buy or Sell, product name, model, quality and price to find best results for your ads.\n E.g. Buy Toyota Axio X 2010 5M.'
						break
					elif cmd == 'LONG':
						sms += 'Your message needs to be less than 160 characters in length. To sell an item, send SELL<space> your item to 289. To buy, send BUY<space>your item to 289.'
						break
						#sms += 'Please post Buy/Sell ads with less than 160 characters in length. To sell an item: send SELL<space> your item to 289. To buy, send BUY<space>your item to 289.'
					#else:
			sms += "The command was not recognised. To sell, send SELL<space> your item to 289. To buy, send BUY<space>your item to 289. Send H to 289 for help. "
			#sms += "Your sent ad needs more details. To sell, send SELL<space> ad to 289. To buy, send BUY<space> ad to 289. "
			#sms += "Your sent ad needs more details such as Buy or Sell, product name, model, quality and price to find best results for your ads. E.g. Buy Toyota Axio X 2010 5M."
			break
		except rest.NoLocationError:
			sms += "Unknown City!\n To set your location correctly, type 'C<space>city name' and send to 289. e.g. 'C Colombo' Or Dial #289# > MyTrader > Update Location."
			break
		if url:
			body = rest.send(usr, url, params)
			if body:
				if body == '401':
					if op == 'zong':
						sms = "Welcome to Dialog MyTrader! To subscribe to the service send SUB to 289."
						#sms = "Welcome to Dialog MyTrader. You can now post any amount of ads for just Rs1+tax a day. Just subscribe to the service by sending SUB to 289. (Conditions Apply)." % format(product(op))
						#"Welcome to MyTrader! To subscribe to the service send SUB to 289.".format(product(op))
					elif op == 'warid':
						sms = "Please subscribe for using {}.\nYou can subscribe by sending SUB to 8225 for weekly, SUB to 8226 for Monthly, SUB to 8227 for Business package.\n".format(product(op))
					else :
						sms = "Please subscribe for using Mmatcher. You can subscribe by sending sub<space>free to this number. Thanks.".format(product(op))
					break
				else:
					if cmd == 'SHORT':
						sms += 'Your sent ad needs more details. To sell, send SELL<space> ad to 289. To buy, send BUY<space> ad to 289. '
						break
					elif cmd == 'LONG':
						sms += 'Your message needs to be less than 160 characters in length. To sell an item, send SELL<space> your item to 289. To buy, send BUY<space>your item to 289.'
						break
						#sms += 'Please post Buy/Sell ads with less than 160 characters in length. To sell an item: send SELL<space> your item to 289. To buy, send BUY<space>your item to 289.'

					sms += rest.decode(product(op), cmd, lid, body) + '\n'
			else:
				sms += 'EMPTY: ' + command + '\n'
		elif cmd == 'H':
			sms += help() + '\n'
		else:
			sms += 'ERROR: ' + command + '\n'
	if sms:
		sms = sms[:-1]
	return sms
Esempio n. 20
0
	def test_12_command_a(self):
		self.assertEqual(rest.encode('', 'A', '3', ''), ('', {}))