Esempio n. 1
0
	def chunk_string(self):
		# Breaking string into smaller strings
		self.assertEqual(utils.chunk("aa bb cc dd ee ff gg", 5), ['aa bb', ' cc d', 'd ee ', 'ff gg'])
		self.assertEqual(utils.chunk("aa bb", 5), ['aa bb',])
		self.assertEqual(utils.chunk("aa bb c", 5), ['aa bb',' c'])		
		self.assertNotEqual(utils.chunk("aa bb cc dd", 5), ['aa bb cc dd', ])
		
		# Using a webtext
		chunks = utils.chunk("This is a webtext that will be chunked into 8 smaller pieces of length 10", 10)
		self.assertEqual(len(chunks), 8)
Esempio n. 2
0
		def send(self, message, recipients):
			"""
			Front-facing sending wrapper to send a message to a list (or comma separated string) of phone numbers. This 
			method automatically breaks the message and recipient list into smaller chunks if they are bigger then the
			network provider can deal with (depending on what has been set in self.MAX_LENGTH and self.MAX_RECIPIENTS)
			
			Parameters:
			- message : a string of any length 
			- recipients : a comma separated string or a list of strings containing the phone numbers to send to. 
			"""	
			webtext = Webtext(message, recipients)
			for message_chunk in utils.chunk(webtext.message, self.MAX_LENGTH):
				for recipient_chunk in utils.chunk(webtext.recipients, self.MAX_RECIPIENTS):
					self._do_send(message_chunk, recipient_chunk)	
			return True					
Esempio n. 3
0
	def chunk_list(self):
		# Breaking string into smaller strings
		self.assertEqual(utils.chunk(["1", "2", "3", "4", "5", "6"], 5), [["1", "2", "3", "4", "5",], ["6"]])
		self.assertEqual(utils.chunk(["1", "2", "3",], 1), [["1",], ["2"], ["3"]])
		self.assertEqual(utils.chunk(["1", "2", "3",], 3), [["1", "2", "3"],])