Best Python code snippet using localstack_python
__init__test.py
Source:__init__test.py
...6from ..http.mocks.generic_mock import GenericMock7from ..http.mocks.logout_mock import LogoutMock8class TestPlatform(TestCase):9 def test_key(self):10 sdk = self.get_sdk(False)11 self.assertEqual('d2hhdGV2ZXI6d2hhdGV2ZXI=', sdk.get_platform().get_api_key())12 def test_login(self):13 sdk = self.get_sdk()14 self.assertTrue(sdk.get_platform().get_auth_data()['access_token'])15 def test_refresh_with_outdated_token(self):16 sdk = self.get_sdk()17 sdk.get_context().get_mocks().add(RefreshMock())18 sdk.get_platform().set_auth_data({19 'refresh_token_expires_in': 1,20 'refresh_token_expire_time': 121 })22 self.assertEqual(1, sdk.get_platform().get_auth_data()['refresh_token_expires_in'])23 self.assertEqual(1, sdk.get_platform().get_auth_data()['refresh_token_expire_time'])24 caught = False25 try:26 sdk.get_platform().refresh()27 except Exception as e:28 caught = True29 self.assertEqual('Refresh token has expired', e.message)30 self.assertTrue(caught)31 def test_manual_refresh(self):32 sdk = self.get_sdk()33 sdk.get_context().get_mocks().add(RefreshMock()).add(GenericMock('/foo', {'foo': 'bar'}))34 self.assertEqual('ACCESS_TOKEN', sdk.get_platform().get_auth_data()['access_token'])35 sdk.get_platform().refresh()36 self.assertEqual('ACCESS_TOKEN_FROM_REFRESH', sdk.get_platform().get_auth_data()['access_token'])37 def test_automatic_refresh(self):38 sdk = self.get_sdk()39 sdk.get_context().get_mocks().add(RefreshMock()).add(GenericMock('/foo', {'foo': 'bar'}))40 self.assertEqual('ACCESS_TOKEN', sdk.get_platform().get_auth_data()['access_token'])41 sdk.get_platform().set_auth_data({42 'expires_in': 1,43 'expire_time': 144 })45 self.assertEqual(1, sdk.get_platform().get_auth_data()['expires_in'])46 self.assertEqual(1, sdk.get_platform().get_auth_data()['expire_time'])47 self.assertEqual('bar', sdk.get_platform().get('/foo').get_json().foo)48 self.assertEqual('ACCESS_TOKEN_FROM_REFRESH', sdk.get_platform().get_auth_data()['access_token'])49 def test_logout(self):50 sdk = self.get_sdk()51 sdk.get_context().get_mocks().add(LogoutMock())52 self.assertEqual('ACCESS_TOKEN', sdk.get_platform().get_auth_data()['access_token'])53 sdk.get_platform().logout()54 self.assertEqual('', sdk.get_platform().get_auth_data()['access_token'])55 self.assertEqual('', sdk.get_platform().get_auth_data()['refresh_token'])56 def test_api_url(self):57 sdk = self.get_sdk()58 exp1 = 'https://whatever/restapi/v1.0/account/~/extension/~?_method=POST&access_token=ACCESS_TOKEN'59 act1 = sdk.get_platform().api_url('/account/~/extension/~', add_server=True, add_method='POST', add_token=True)60 self.assertEqual(exp1, act1)61 exp2 = 'https://foo/account/~/extension/~?_method=POST&access_token=ACCESS_TOKEN'62 url2 = 'https://foo/account/~/extension/~'63 act2 = sdk.get_platform().api_url(url2, add_server=True, add_method='POST', add_token=True)64 self.assertEqual(exp2, act2)65if __name__ == '__main__':...
update.py
Source:update.py
1#!/usr/bin/python2# Copyright 2015 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Pulls down the current dart sdk to third_party/dart-sdk/.6You can manually force this to run again by removing7third_party/dart-sdk/STAMP_FILE, which contains the URL of the SDK that8was downloaded. Rolling works by updating LINUX_64_SDK to a new URL.9"""10import os11import shutil12import subprocess13import sys14# How to roll the dart sdk: Just change this url! We write this to the stamp15# file after we download, and then check the stamp file for differences.16SDK_URL_BASE = ('https://gsdview.appspot.com/dart-archive/channels/dev/raw/'17 '1.17.0-dev.4.1/sdk/')18LINUX_64_SDK = 'dartsdk-linux-x64-release.zip'19MACOS_64_SDK = 'dartsdk-macos-x64-release.zip'20# Path constants. (All of these should be absolute paths.)21THIS_DIR = os.path.abspath(os.path.dirname(__file__))22MOJO_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..'))23DART_SDK_DIR = os.path.join(MOJO_DIR, 'third_party', 'dart-sdk')24STAMP_FILE = os.path.join(DART_SDK_DIR, 'STAMP_FILE')25def RunCommand(command, fail_hard=True):26 """Run command and return success (True) or failure; or if fail_hard is27 True, exit on failure."""28 print 'Running %s' % (str(command))29 if subprocess.call(command, shell=False) == 0:30 return True31 print 'Failed.'32 if fail_hard:33 sys.exit(1)34 return False35def main():36 # Only get the SDK if we don't have a stamp for or have an out of date stamp37 # file.38 get_sdk = False39 if sys.platform.startswith('linux'):40 sdk_url = SDK_URL_BASE + LINUX_64_SDK41 output_file = os.path.join(DART_SDK_DIR, LINUX_64_SDK)42 elif sys.platform.startswith('darwin'):43 sdk_url = SDK_URL_BASE + MACOS_64_SDK44 output_file = os.path.join(DART_SDK_DIR, MACOS_64_SDK)45 else:46 print "Platform not supported"47 return 148 if not os.path.exists(STAMP_FILE):49 get_sdk = True50 else:51 # Get the contents of the stamp file.52 with open(STAMP_FILE, "r") as stamp_file:53 stamp_url = stamp_file.read().replace('\n', '')54 if stamp_url != sdk_url:55 get_sdk = True56 if get_sdk:57 # Completely remove all traces of the previous SDK.58 if os.path.exists(DART_SDK_DIR):59 shutil.rmtree(DART_SDK_DIR)60 os.mkdir(DART_SDK_DIR)61 # Download the Linux x64 based Dart SDK.62 # '-C -': Resume transfer if possible.63 # '--location': Follow Location: redirects.64 # '-o': Output file.65 curl_command = ['curl',66 '-C', '-',67 '--location',68 '-o', output_file,69 sdk_url]70 if not RunCommand(curl_command, fail_hard=False):71 print "Failed to get dart sdk from server."72 return 173 # Write our stamp file so we don't redownload the sdk.74 with open(STAMP_FILE, "w") as stamp_file:75 stamp_file.write(sdk_url)76 unzip_command = ['unzip', '-o', '-q', output_file, '-d', DART_SDK_DIR]77 if not RunCommand(unzip_command, fail_hard=False):78 print "Failed to unzip the dart sdk."79 return 180 return 081if __name__ == '__main__':...
platform_test.py
Source:platform_test.py
...3import unittest4from ..test import TestCase5class TestPlatform(TestCase):6 def test_key(self):7 sdk = self.get_sdk()8 self.assertEqual('d2hhdGV2ZXI6d2hhdGV2ZXI=', sdk.platform()._api_key())9 def test_login(self):10 sdk = self.get_sdk()11 self.assertTrue(sdk.platform().auth().data()['access_token'])12 def test_refresh_with_outdated_token(self):13 sdk = self.get_sdk()14 sdk.mock_registry().refresh_mock()15 sdk.platform().auth().set_data({16 'refresh_token_expires_in': 1,17 'refresh_token_expire_time': 118 })19 self.assertEqual(1, sdk.platform().auth().data()['refresh_token_expires_in'])20 self.assertEqual(1, sdk.platform().auth().data()['refresh_token_expire_time'])21 caught = False22 try:23 sdk.platform().refresh()24 except Exception as e:25 caught = True26 self.assertEqual('Refresh token has expired', e.message)27 self.assertTrue(caught)28 def test_manual_refresh(self):29 sdk = self.get_sdk()30 sdk.mock_registry().refresh_mock().generic_mock('GET', '/foo', {'foo': 'bar'})31 self.assertEqual('ACCESS_TOKEN', sdk.platform().auth().data()['access_token'])32 sdk.platform().refresh()33 self.assertEqual('ACCESS_TOKEN_FROM_REFRESH', sdk.platform().auth().data()['access_token'])34 def test_automatic_refresh(self):35 sdk = self.get_sdk()36 sdk.mock_registry().refresh_mock().generic_mock('GET', '/foo', {'foo': 'bar'})37 self.assertEqual('ACCESS_TOKEN', sdk.platform().auth().data()['access_token'])38 sdk.platform().auth().set_data({39 'expires_in': 1,40 'expire_time': 141 })42 self.assertEqual(1, sdk.platform().auth().data()['expires_in'])43 self.assertEqual(1, sdk.platform().auth().data()['expire_time'])44 self.assertEqual('bar', sdk.platform().get('/foo').json().foo)45 self.assertEqual('ACCESS_TOKEN_FROM_REFRESH', sdk.platform().auth().data()['access_token'])46 def test_logout(self):47 sdk = self.get_sdk()48 sdk.mock_registry().logout_mock()49 self.assertEqual('ACCESS_TOKEN', sdk.platform().auth().data()['access_token'])50 sdk.platform().logout()51 self.assertEqual('', sdk.platform().auth().data()['access_token'])52 self.assertEqual('', sdk.platform().auth().data()['refresh_token'])53 def test_api_url(self):54 sdk = self.get_sdk()55 exp1 = 'https://whatever/restapi/v1.0/account/~/extension/~?_method=POST&access_token=ACCESS_TOKEN'56 act1 = sdk.platform().create_url('/account/~/extension/~', add_server=True, add_method='POST', add_token=True)57 self.assertEqual(exp1, act1)58 exp2 = 'https://foo/account/~/extension/~?_method=POST&access_token=ACCESS_TOKEN'59 url2 = 'https://foo/account/~/extension/~'60 act2 = sdk.platform().create_url(url2, add_server=True, add_method='POST', add_token=True)61 self.assertEqual(exp2, act2)62if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!