예제 #1
0
class test_run_command(Test_Helper):
    def setUp(self):
        self.oss_setup = super().setUp()
        self.aws_lambda = Lambda_Package('oss_bot.lambdas.oss_bot')
        self.aws_lambda._lambda.set_s3_bucket(self.oss_setup.s3_bucket_lambdas)         \
                               .set_role     (self.oss_setup.role_lambdas)
        #self.aws_lambda.create()  # use when wanting to update lambda function

    def update_lambda(self):
        self.aws_lambda.update_code()

    def test__invoke_directy(self):
        from oss_bot.lambdas.oss_bot import run
        self.result = run({'event': {'type': 'message', 'text': 'help'}},{})

    def test_invoke(self):
        self.update_lambda()
        self.result = self.aws_lambda.invoke({'event': {'type': 'message', 'text': 'help'}})

    def test_invoke_with_channel(self):
        self.update_lambda()
        self.result = self.aws_lambda.invoke({'event': {'type': 'message', 'text': 'help', "channel": "DJ8UA0RFT"}})

    def test_participant_view(self):
        self.update_lambda()
        text = 'participant view Dinis Cruz'
        self.result = self.aws_lambda.invoke({'event': {'type': 'message', 'text': text, "channel": "DJ8UA0RFT"}})
class test_run_command(TestCase):
    def setUp(self):
        self.short_id = '3ddc8'
        self.aws_lambda = Lambda_Package(
            'osbot_jupyter.lambdas.execute_python')
        self.result = None
        self.png_data = None
        self.aws_lambda.add_module('osbot_browser')
        self.aws_lambda.update_code(
        )  # use when wanting to update lambda function

    def tearDown(self):
        if self.result:
            Dev.pprint(self.result)

        if self.png_data:
            png_file = '/tmp/lambda_png_file.png'
            with open(png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
            Dev.pprint("Png data with size {0} saved to {1}".format(
                len(self.png_data), png_file))

    def test_execute_python(self):
        code = '40+3'
        target = None
        keep_contents = None
        payload = {
            'short_id': self.short_id,
            'python_code': code,
            target: target,
            keep_contents: keep_contents
        }
        #self.png_data = self.aws_lambda.invoke(payload)
        self.result = self.aws_lambda.invoke(payload)
예제 #3
0
class test_run_command(TestCase):
    def setUp(self):
        self.aws_lambda = Lambda_Package('osbot_jupyter.lambdas.nbconvert')
        #self.aws_lambda.add_module('osbot_browser')
        self.aws_lambda.update_code()                                        # use when wanting to update lambda function
        self.result = None
        self.png_data = None

    def tearDown(self):
        if self.result:
            Dev.pprint(self.result)

        if self.png_data:
            png_file = '/tmp/lambda_png_file.png'
            with open(png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
            Dev.pprint("Png data with size {0} saved to {1}".format(len(self.png_data), png_file))

    def test_upload_dependency(self):
        from osbot_aws.apis.Lambda import upload_dependency
        self.result = upload_dependency('jupyter')

    def test_nbconvert(self):
        payload     = { }
        from osbot_aws.Dependencies import load_dependency
        load_dependency('jupyter')
        #self.png_data = self.aws_lambda.invoke(payload)
        self.result =  self.aws_lambda.invoke(payload)
예제 #4
0
class test_run_command(TestCase):
    def setUp(self):
        self.task_name = 'update_sheet'
        self.command = 'load_sheet'
        self.file_id = '1_Bwz6z34wALFGb1ILUXG8CtF1-Km6F9_sGXnAu4gewY'
        self.aws_lambda = Lambda_Package(
            'osbot_gsheet_sync.lambdas.run_command')
        self.result = None

        self.aws_lambda.update_code(
        )  # use when wanting to update lambda function

    def tearDown(self):
        if self.result:
            Dev.pprint(self.result)

    def test_invoke_lambda(self):
        payload = {
            'task_name': self.task_name,
            'command': self.command,
            'file_id': self.file_id
        }
        self.result = self.aws_lambda.invoke(payload)

    def test_ping(self):
        payload = {'task_name': 'ping'}
        self.result = self.aws_lambda.invoke(payload)
예제 #5
0
class test_run_command(TestCase):
    def setUp(self):
        self.aws_lambda = Lambda_Package('osbot_jupyter.lambdas.browser')
        self.result     = None
        self.png_data   = None
        self.aws_lambda.add_module('osbot_browser')
        self.aws_lambda.update_code()       # use when wanting to update lambda function

    def tearDown(self):
        if self.result:
            Dev.pprint(self.result)

        if self.png_data:
            png_file = '/tmp/lambda_png_file.png'
            with open(png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
            Dev.pprint("Png data with size {0} saved to {1}".format(len(self.png_data), png_file))

    def test_invoke_lambda(self):
        payload     = { 'url' : 'https://www.google.com/abc'}
        self.png_data = self.aws_lambda.invoke(payload)
예제 #6
0
class test_jira_web(unittest.TestCase):
    def setUp(self):
        self.png_data = None
        self.result = None
        self._lambda = Lambda_Package('osbot_browser.lambdas.jira_web')

    def tearDown(self):
        if self.png_data:
            png_file = '/tmp/tmp-jira-screenshot.png'
            with open(png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
            Dev.pprint("Png data with size {0} saved to {1}".format(
                len(self.png_data), png_file))
        if self.result:
            Dev.print(self.result)

    def test_invoke_directly(self):
        result = run({}, {})
        assert result == '*Here are the `Browser_Commands` commands available:*'

    def test_invoke(self):
        self._lambda.update_code()
        issue_id = 'SEC-10965'  # 'GSP-95'

        payload = {
            'issue_id': issue_id,
            'channel': 'DDKUZTK6X',  # gsbot
            'team_id': 'T7F3AUXGV',  # GS-CST
            'width': 2000,
            'height': 300
        }
        self.result = self._lambda.invoke(payload)
        #self.png_data = self._lambda.invoke(payload)

    def test_update_lambda(self):
        self._lambda.update_code()
예제 #7
0
class test_jira_web(unittest.TestCase):
    def setUp(self):
        self.png_data = None
        self.result = None
        self._lambda = Lambda_Package('osbot_browser.lambdas.slack_web')

    def tearDown(self):
        if self.png_data:
            if type(self.png_data) is str:
                png_file = '/tmp/tmp-jira-screenshot.png'
                with open(png_file, "wb") as fh:
                    fh.write(base64.decodebytes(self.png_data.encode()))
                Dev.pprint("Png data with size {0} saved to {1}".format(
                    len(self.png_data), png_file))
            else:
                Dev.print(self.result)
        if self.result:
            Dev.print(self.result)

    #def test_invoke_directly(self):
    #    result = run({},{})
    #    assert result == '*Here are the `Browser_Commands` commands available:*'

    def test_invoke(self):
        self._lambda.update_code()
        target = '/messages/random/'

        payload = {
            'target': target,
            'channel': 'DDKUZTK6X',  # gsbot
            'team_id': 'T7F3AUXGV',  # GS-CST
            'width': 800,
            'height': 1000
        }
        self.result = self._lambda.invoke(payload)
        self.png_data = self.result  # self._lambda.invoke(payload)

    def test_invoke_oss(self):
        self._lambda.update_code()
        target = '/messages/oss-helpdesk'
        target = '/messages/oss-general'

        payload = {
            'target': target,
            'channel': 'DDKUZTK6X',  # gsbot
            #'team_id': 'T7F3AUXGV',  # GS-CST
            'team_id': 'TAULHPATC',  # OSS
            'width': 800,
            'height': 4000
        }
        #self.result = self._lambda.invoke(payload)
        self.png_data = self._lambda.invoke(payload)

    def test_update_lambda(self):
        self._lambda.update_code()