Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Canux CHENG authored and Canux CHENG committed Dec 11, 2018
2 parents 4112910 + 31646b3 commit 4af7407
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 62 deletions.
2 changes: 2 additions & 0 deletions docs/email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class MIMEText::

MIMEText(email.mime.nonmultipart.MIMENonMultipart)

MIMEText(_text=text, _subtype='plain'/'html', _charset='us-ascii'/'utf-8')

class MIMEAudio::

# Content-Type': 'audio/*'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def read(readme):

class InstInstall(install):
def run(self):
print "PreInst for super-devops."
print("PreInst for super-devops.")
install.run(self)
print "PostInst for super-devops."
print("PostInst for super-devops.")


INSTALL_REQUIRES = []
Expand Down
4 changes: 2 additions & 2 deletions super_devops/email/smtplib_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def sendmail(
self, frm, to, subject='', text='',
files=None, cc=None, date=None
files=None, cc=None, date=None, subtype='plain', charset='utf-8'
):
try:
if frm is None:
Expand Down Expand Up @@ -70,7 +70,7 @@ def sendmail(
to = to + cc
msg['Date'] = date if date else formatdate()

text = MIMEText(text)
text = MIMEText(text, _subtype=subtype, _charset=charset)
msg.attach(text)

if files:
Expand Down
12 changes: 6 additions & 6 deletions super_devops/robotframework/rf_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,26 @@ def __parse_show(self):
partial_func = [BaseColor.MAGENTA, BaseColor.CYAN, BaseColor.GREEN]

format_wf = ''.join(formatter)
print format_wf .format(*header)
print format_wf.format(
print(format_wf.format(*header))
print(format_wf.format(
*(
'=' * len(col)
for col in header
)
)
))
format_wf = ''
for func, param in zip(partial_func, formatter):
format_wf += func(param)

print '\n'.join(
print('\n'.join(
format_wf.format(
index,
[str(tag) for tag in workflow.tags],
workflow.name
) for index, workflow in enumerate(
self.suite.workflowdict.values(), 1
)
)
))
if self.args.detail:
print('')
for index in self.args.detail:
Expand Down Expand Up @@ -268,7 +268,7 @@ def __robot_run(self, workflows):
logger.info("outputdir: {}".format(__outputdir), also_console=True)

if self.args.pythonpath:
print "my pythonpath: ", self.args.pythonpath
print("my pythonpath: ", self.args.pythonpath)
__options.setdefault('pythonpath', self.args.pythonpath)

if not self.args.debug:
Expand Down
3 changes: 2 additions & 1 deletion super_devops/tick_stack/kapacitor_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ def get_all_topics(self):
def get_all_events(self, topic):
try:
url = self.base_url + "/alerts/topics/{}/events".format(topic)
except Exception:
raise

# TODO
def get_event(self, topic, event):
try:
url = self.base_url + "/alerts/topics/{}/events/{}".format(topic,
Expand Down
26 changes: 13 additions & 13 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ class Role(str, Enum):

class EnumTestCase(unittest.TestCase):
def test_persona(self):
print Persona.CONSUMER
print Persona.CONSUMER.name
print Persona.CONSUMER.value
print 'Persona(0): ', Persona(0)
print '3 == Persona.CONSUMER: ', 3 == Persona.CONSUMER
print '3 in Persona.CONSUMER: ', 3 in [Persona.CONSUMER]
print(Persona.CONSUMER)
print(Persona.CONSUMER.name)
print(Persona.CONSUMER.value)
print('Persona(0): ', Persona(0))
print('3 == Persona.CONSUMER: ', 3 == Persona.CONSUMER)
print('3 in Persona.CONSUMER: ', 3 in [Persona.CONSUMER])

def test_role(self):
print Role.CONSUMER
print Role.CONSUMER.name
print Role.CONSUMER.value
print 'Role(dataadmin): ', Role('dataadmin')
print 'consumer == Role.CONSUMER: ', 'consumer' == Role.CONSUMER
print 'consumer in [Role.CONSUMER]', 'consumer' in [Role.CONSUMER]
print 'Role.CONSUMER.lower()', Role.CONSUMER.lower()
print(Role.CONSUMER)
print(Role.CONSUMER.name)
print(Role.CONSUMER.value)
print('Role(dataadmin): ', Role('dataadmin'))
print('consumer == Role.CONSUMER: ', 'consumer' == Role.CONSUMER)
print('consumer in [Role.CONSUMER]', 'consumer' in [Role.CONSUMER])
print('Role.CONSUMER.lower()', Role.CONSUMER.lower())


if __name__ == "__main__":
Expand Down
18 changes: 3 additions & 15 deletions tests/test_http_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def test_get(self):
},
}
)
print res.status_code
print res.text
print res.headers
print(res.status_code)
print(res.text)
print(res.headers)

@unittest.skip('passed')
def test_post(self):
Expand All @@ -38,9 +38,6 @@ def test_post(self):
},
}
)
print res.status_code
print res.text
print res.headers

@unittest.skip("passed")
def test_post_file(self):
Expand All @@ -54,9 +51,6 @@ def test_post_file(self):
}
}
)
print res.status_code
print res.text
print res.headers

@unittest.skip('passed')
def test_post_files(self):
Expand All @@ -77,9 +71,6 @@ def test_post_files(self):
}
}
)
print res.status_code
print res.text
print res.headers

def test_updatethreadconfig(self):
url = "http://127.0.0.1/JsonData.aspx"
Expand All @@ -94,9 +85,6 @@ def test_updatethreadconfig(self):
'headers': {'content-type': 'application/json'},
}
)
print res.status_code
print res.text
print res.headers


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions tests/test_kapacitor_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def test_disable_smtp(self):
@unittest.skip("ignore")
def test_enable_smtp(self):
kapacitor = BaseKapacitor(kapacitor_url="http://127.0.0.1:9092")
kapacitor.enable_smtp(frm="maf@company.com",
to=["cheng@canux.com"])
kapacitor.enable_smtp(frm="maf@domain.com",
to=["cheng@domain.com"])


if __name__ == "__main__":
Expand Down
18 changes: 14 additions & 4 deletions tests/test_smtp_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,25 @@ def test_sendattach(self):
files=['/home/canux/examples.desktop']
)

def test_smtpserver(self):
with BaseEmail(host='mail.company.com', port=25) as email:
def test_plain(self):
with BaseEmail(host='mail.domain.com', port=25) as email:
email.sendmail(
frm="super-devops@canux.com",
to=['cheng@canux.com'],
frm="super-devops@domain.com",
to=['wcheng@domain.com'],
subject='test subject',
text='text body'
)

def test_html(self):
with BaseEmail(host='mail.domain.com', port=25) as email:
email.sendmail(
frm="super-devops@domain.com",
to=['wcheng@domain.com'],
subject='test subject',
text='<html><body><h1>text body</h1></body></html>',
subtype='html', charset='utf-8'
)


if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions tests/test_ssh_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ def test_exec_command(self):
with BaseParamiko('127.0.0.1', 'canux', 'canux') as ssh:
output, error, rc = ssh.exec_command('ps -ef | grep -v grep | '
'grep sandbox | wc -l')
print output, error, rc

def test_start_deamon(self):
with BaseParamiko('127.0.0.1', 'canux', 'canux') as ssh:
output, error, rc = ssh.start_deamon('influxdb', 'influxd')
print output, error, rc

def test_stop_service(self):
with BaseParamiko('127.0.0.1', 'canux', 'canux') as ssh:
output, error, rc = ssh.stop_deamon('influxdb', 'inlfuxd')
print output, error, rc


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wmi_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_run_cmd(self):
username='username', password='password'
) as wmi:
result = wmi.query("select * from Win32_ComputerSystem")
print result
print(result)


if __name__ == '__main__':
Expand Down
12 changes: 6 additions & 6 deletions tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
class YamlTestCase(unittest.TestCase):
def test_load(self):
data = yaml.load(open(r'C:\Users\wcheng\Desktop\Src\super-devops\etc\global.yaml', 'r'))
print type(data)
print data
print(type(data))
print(data)

def test_safe_load(self):
data = yaml.safe_load(open(r'C:\Users\wcheng\Desktop\Src\super-devops\etc\global.yaml', 'r'))
print type(data)
print data
print(type(data))
print(data)

def test_load_all(self):
data = yaml.load_all(open(r'C:\Users\wcheng\Desktop\Src\super-devops\etc\global.yaml', 'r'))
print type(data)
print data
print(type(data))
print(data)


if __name__ == '__main__':
Expand Down
14 changes: 7 additions & 7 deletions tests/test_yaml_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ class BaseYamlTest(unittest.TestCase):
@unittest.skip('ignore')
def test_list(self):
data = self.ctx.List["first"]
print type(data)
print data
print(type(data))
print(data)

@unittest.skip('ignore')
def test_dict(self):
self.ctx = BaseYaml(r'C:\Users\wcheng\Desktop\Src\super-devops\etc\global.yaml')
data = self.ctx.Dict["second"]
print type(data)
print data
print(type(data))
print(data)

@unittest.skip('ignore')
def test_get_key(self):
self.ctx = BaseYaml('/home/canux/Src/super-devops/etc/global.yaml')
data = self.ctx.engine['threads'][0]
print type(data)
print data
print(type(data))
print(data)

def test_shared(self):
self.ctx = BaseYaml('/home/canux/Src/super-devops/etc/global.yaml')
self.ctx.shared.test = "content"
print self.ctx.shared["test"]
print(self.ctx.shared["test"])


if __name__ == '__main__':
Expand Down

0 comments on commit 4af7407

Please sign in to comment.