How to use create_ssl_cert method in localstack

Best Python code snippet using localstack_python

test_cmd_create_ssl_cert.py

Source: test_cmd_create_ssl_cert.py Github

copy

Full Screen

1"""2 Here we test our main console utility functionality3"""4import os5import sys67import pytest8import mock9from click.testing import CliRunner1011from tbtbot.apptemplate import template_strings as tstrings12from tbtbot.tbtboter import cli13from tbtbot.tbtboter.commands.cmd_create_bot import (14 make_config_file, make_env_file, set_env15)16from tbtbot.tbtboter import commands17181920@pytest.fixture21def runner():22 return CliRunner()232425def test_create_ssl_cert_command_invalid_path(runner):26 """ This test must rise SystemExit because we are giving nonexistent directory name27 which casues to prompt: "Use current dir?" then gets again 'koko' and aborts28 """29 with runner.isolated_filesystem():30 result = runner.invoke(cli.main, ['create_ssl_cert', '--path'], input='koko\nchocolate')31 assert type(result.exception) == SystemExit32 assert 'Error: --path option requires an argument' in result.output33343536def test_create_certificat_success(runner):37 func = commands.cmd_create_ssl_cert.create_certificate38 with runner.isolated_filesystem():39 with mock.patch('subprocess.call') as mocked_call:40 subprocess_cmd = commands.cmd_create_ssl_cert.get_openssl_command41 mocked_call.return_value = 042 result = func('jeje')43 assert mocked_call.called == True44 assert mocked_call.called_once_with(subprocess_cmd('jeje'))45 assert 'ssl' in result464748def test_create_certificat_fail(runner):49 func = commands.cmd_create_ssl_cert.create_certificate50 with runner.isolated_filesystem():51 with mock.patch('subprocess.call') as mocked_call:52 subprocess_cmd = commands.cmd_create_ssl_cert.get_openssl_command53 mocked_call.return_value = 154 result = func('jeje')55 assert mocked_call.called == True56 assert mocked_call.called_once_with(subprocess_cmd('jeje'))57 assert result == False585960def test_create_ssl_cert_failed(runner):61 """In this test create_ssl_cert command fails to create keys in koko dir"""62 with runner.isolated_filesystem():63 os.mkdir('koko')64 commands.cmd_create_ssl_cert.create_certificate = mock.Mock(return_value=False)65 func = commands.cmd_create_ssl_cert.create_certificate66 result = runner.invoke(cli.main, ['create_ssl_cert'], input="chocolate\nkoko")67 assert func.called == True68 assert len(func.call_args) is 269 assert len(os.listdir('koko')) == 070 assert type(result.exception) == IOError717273def test_create_ssl_cert_succed(runner):74 """In this test create_ssl_cert command successfully creates keys in koko dir"""75 with runner.isolated_filesystem():76 os.mkdir('koko')77 commands.cmd_create_ssl_cert.create_certificate = mock.Mock(return_value=True)78 func = commands.cmd_create_ssl_cert.create_certificate79 result = runner.invoke(cli.main, ['create_ssl_cert'], input="chocolate\nkoko")80 assert func.called == True81 assert len(func.call_args) is 2 ...

Full Screen

Full Screen

pyhttps.py

Source: pyhttps.py Github

copy

Full Screen

...18if PY3:19 OpenSslExecutableNotFoundError = FileNotFoundError20else:21 OpenSslExecutableNotFoundError = OSError22def create_ssl_cert():23 if PY3:24 from subprocess import DEVNULL25 else:26 DEVNULL = open(os.devnull, 'wb')27 try:28 ssl_exec_list = ['openssl', 'req', '-new', '-x509', '-keyout', ssl_cert_path,29 '-out', ssl_cert_path, '-days', '365', '-nodes',30 ]31 call(ssl_exec_list)32 # call(ssl_exec_list, stdout=DEVNULL, stderr=DEVNULL)33 except OpenSslExecutableNotFoundError:34 logging.error('openssl executable not found!')35 exit(1)36 logging.info('Self signed ssl certificate created at {}'.format(ssl_cert_path))37def exit_handler():38 # remove certificate file at exit39 os.remove(ssl_cert_path)40 logging.info('Bye!')41def main():42 logging.info('pyhttps {}'.format(version))43 create_ssl_cert()44 atexit.register(exit_handler)45 if PY3:46 import http.server47 import socketserver48 import ssl49 logging.info('Server running... https:/​/​{}:{}'.format(server_host, server_port))50 httpd = socketserver.TCPServer((server_host, server_port), http.server.SimpleHTTPRequestHandler)51 httpd.socket = ssl.wrap_socket(httpd.socket, certfile=ssl_cert_path, server_side=True)52 else:53 import BaseHTTPServer54 import SimpleHTTPServer55 import ssl56 logging.info('Server running... https:/​/​{}:{}'.format(server_host, server_port))57 httpd = BaseHTTPServer.HTTPServer((server_host, server_port), SimpleHTTPServer.SimpleHTTPRequestHandler)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful