Esempio n. 1
0
	def test_command_send(self):
		# START SMTPD
		tfile = tempfile.NamedTemporaryFile()
		tfile_name = tfile.name
		tfile.close()
		p1 = Popen(['./tests/smtp_server.py', tfile_name], stdin=PIPE)
		citems = self.get_testserver_config_scheme()
		proj_dir = self.mm_create_project('Test')
		config = SafeConfigParser()
		config.read(self.config_path)
		for item in citems:
			config.set('Mail', item[0], item[1])
		files = ['mail.txt', 'subject.txt', 'keys.csv', 'attachments.txt']
		self.create_with_sample_files("", proj_dir, files)
		config.write(open(self.config_path, 'w'))
		sys.stdin = x_in = StringIO('\n')
		sys.stdout = x_out = StringIO()
		m = MMailer()
		m.command_send(args=['mmailer', 'send'])
		sys.stdin = sys.__stdin__
		sys.stdout = sys.__stdout__
		p1.terminate()
		p1.wait()
		of = open('tests/samples/send_output.txt','r')
		sto_str = of.read()
		sto = sto_str.decode('UTF-8')
		# exclude first line from compare,
		# because the date changes each test run
		assert x_out.getvalue() == sto,"\n\n[%s]\n\n[%s]" \
				% (sto, x_out.getvalue())
		import filecmp
		assert filecmp.cmp(tfile_name, 'tests/samples/sended.txt')
Esempio n. 2
0
	def mm_config_fill(self, port=1555):
		questions = ['SMTP Server Settings', '\n\n\n', \
				'Server :', 'Port [587] :', 'esmtp [YES/no] :', \
				'tls [YES/no] :', 'Whats your login :'******'Whats your password :'******'Whats your email address :', \
				'try to connect!\n']
		answers = ['localhost', str(port), 'no', 'no', '', '', 'x@localhost']
		sys.stdin = x_in = StringIO('\n'.join(answers))
		sys.stdout = x_out = StringIO()
		m = MMailer()
		mod_time = os.path.getmtime(self.config_path)
		m.command_config(args=['mmailer', '	config'])
		mod_time2 = os.path.getmtime(self.config_path)
		config_changed = not (mod_time == mod_time2)
		sys.stdin = sys.__stdin__
		sys.stdout = sys.__stdout__
		#assert "".join(questions) == x_out.getvalue(), \
		#	'\n[%s] != \n[%s]' % ("".join(questions), x_out.getvalue())
		return config_changed