Best Python code snippet using autotest_python
tests.py
Source:tests.py
...10 def test_get_meetings(self):11 connection = AdobeConnectAPI()12 meeting = connection.create_meeting(meeting_description=13 "fn-test-meeting-{0}".14 format(generate_random_id()),15 start_date=None,16 end_date=None)17 meetings = connection.get_meetings(None, None, None)18 self.assertGreater(len(meetings), 0)19 meetings_with_sco_id = connection.get_meetings([meeting.sco_id],20 None, None)21 self.assertGreater(len(meetings_with_sco_id), 0)22 def test_create_meeting(self):23 connection = AdobeConnectAPI()24 meeting = connection.create_meeting(meeting_description=25 "fn-test-meeting-{0}".26 format(generate_random_id()),27 start_date=None,28 end_date=None)29 self.assertIsNotNone(meeting.sco_id)30 def test_create_account_for_user(self):31 connection = AdobeConnectAPI()32 email = "create_account_test.{0}{1}".format(generate_random_id(),33 "@flashnotes.com")34 user = connection.create_account_for_user(generate_random_id(),35 generate_random_id(),36 email)37 self.assertEqual(user.login, email)38 def test_add_participants_to_meeting(self):39 connection = AdobeConnectAPI()40 host_email = "add_participants_test.{0}{1}".format(generate_random_id(),41 "@flashnotes.com")42 host_user = connection.create_account_for_user(generate_random_id(),43 generate_random_id(),44 host_email)45 mini_host_email = \46 "add_participants_test.{0}{1}".format(generate_random_id(),47 "@flashnotes.com")48 mini_host_user = \49 connection.create_account_for_user(generate_random_id(),50 generate_random_id(),51 mini_host_email)52 meeting = connection.create_meeting(meeting_description=53 "fn-test-meeting-{0}".54 format(generate_random_id()),55 start_date=None,56 end_date=None)57 connection.add_participant_to_meeting(host_user.principal_id,58 meeting.sco_id, "host")59 connection.add_participant_to_meeting(mini_host_user.principal_id,60 meeting.sco_id, "mini-host")61 def test_get_participants_from_meeting(self):62 connection = AdobeConnectAPI()63 host_email = "add_participants_test.{0}" + generate_random_id() + "@flashnotes.com"64 host_user = connection.create_account_for_user(generate_random_id(),65 generate_random_id(),66 host_email)67 mini_host_email = "add_participants_test." + generate_random_id() + "@flashnotes.com"68 mini_host_user = \69 connection.create_account_for_user(generate_random_id(),70 generate_random_id(),71 mini_host_email)72 meeting = connection.create_meeting(meeting_description=73 "fn-test-meeting-{0}".74 format(generate_random_id()),75 start_date=None,76 end_date=None)77 connection.add_participant_to_meeting(host_user.principal_id,78 meeting.sco_id, "host")79 connection.add_participant_to_meeting(mini_host_user.principal_id,80 meeting.sco_id, "mini-host")81 self.assertIsNotNone(connection.82 get_participants_for_meeting(meeting.sco_id))83 def test_get_meeting_url(self):84 connection = AdobeConnectAPI()85 email = "get_meeting_url_test.{0}{1}".format(generate_random_id(),86 "@flashnotes.com")87 user = connection.create_account_for_user(generate_random_id(),88 generate_random_id(),89 email)90 session_cookie = connection.authenticate_participant(user.login,91 "Flash!123")92 def test_delete_meeting_room(self):93 connection = AdobeConnectAPI()94 meeting = connection.create_meeting(meeting_description=95 "fn-test-meeting-{0}".96 format(generate_random_id()),97 start_date=None,98 end_date=None)99 connection.delete_meeting_room(meeting.sco_id)100 def test_authenticate_user(self):101 connection = AdobeConnectAPI()102 email = "authenticate_user_test.{0}{1}".format(generate_random_id(),103 "@flashnotes.com")104 user = connection.create_account_for_user(generate_random_id(),105 generate_random_id(),106 email)107 session_cookie = connection.authenticate_participant(user.login,108 "Flash!123")109 meeting = connection.create_meeting(meeting_description=110 "fn-test-meeting-{0}".111 format(generate_random_id()),112 start_date=None,113 end_date=None)114 connection.add_participant_to_meeting(user.principal_id,115 meeting.sco_id, "host")116 self.assertIsNotNone(session_cookie)117 def test_update_group_for_user(self):118 connection = AdobeConnectAPI()119 email = "create_account_test.{0}{1}".format(generate_random_id(),120 "@flashnotes.com")121 user = connection.create_account_for_user(generate_random_id(),122 generate_random_id(),123 email)124 # Add to group LIVE_ADMINS125 connection.update_group_for_user(user.principal_id, "LIVE_ADMINS")126 # Remove from group LIVE_ADMINS127 connection.update_group_for_user(user.principal_id, "LIVE_ADMINS", True)128 def test_get_users_in_group(self):129 connection = AdobeConnectAPI()130 users = connection.get_users_in_group("LIVE_ADMINS")131 self.assertGreater(len(users), 0)132 def test_show_user_in_correct_group(self):133 connection = AdobeConnectAPI()134 host_email = "add_participants_test.{0}{1}".format(generate_random_id(),135 "@flashnotes.com")136 host_user = connection.create_account_for_user(generate_random_id(),137 generate_random_id(),138 host_email)139 mini_host_email = \140 "add_participants_test.{0}{1}".format(generate_random_id(),141 "@flashnotes.com")142 mini_host_user = \143 connection.create_account_for_user(generate_random_id(),144 generate_random_id(),145 mini_host_email)146 meeting = connection.create_meeting(meeting_description=147 "fn-test-meeting-{0}".148 format(generate_random_id()),149 start_date=None,150 end_date=None)151 connection.update_group_for_user(host_user.principal_id, "LIVE_ADMINS")152 connection.add_participant_to_meeting(host_user.principal_id,153 meeting.sco_id, "host")154 connection.add_participant_to_meeting(mini_host_user.principal_id,155 meeting.sco_id, "mini-host")156 host_session = connection.authenticate_participant(host_user.login,157 "Flash!123")158 mini_host_session = connection.authenticate_participant(mini_host_user.login,159 "Flash!123")160 host_url = connection.get_meeting_url(meeting.sco_id, host_session)161 pres_url = connection.get_meeting_url(meeting.sco_id, mini_host_session)162@skip("Only run these tests on-demand due to Adobe resource dependency.")163class AdobeConnectUserTests(TestCase):164 def setUp(self):165 self.host = factories.User.create(email="testhost@fntest.com")166 self.attendee = factories.User.create(email="testlearner@fntest.com")167 from .models import adobe_connect_api168 self._ac_api = adobe_connect_api169 def test_exercise_user_workflow(self):170 # Register users171 self.host_user = AdobeConnectUser()172 self.host_user.register(self._ac_api, self.host)173 self.host_user._validate_acount()174 self.assertEqual(self.host_user.fn_user_email, self.host.email)175 self.assertEqual(self.host_user.fn_user.id, self.host.id)176 self.assertIsNotNone(self.host_user.pwd)177 self.attendee_user = AdobeConnectUser()178 self.attendee_user.register(self._ac_api, self.attendee)179 self.attendee_user._validate_acount()180 self.assertEqual(self.attendee_user.fn_user_email, self.attendee.email)181 self.assertEqual(self.attendee_user.fn_user.id, self.attendee.id)182 self.assertIsNotNone(self.attendee_user.pwd)183 # Add user to room184 room = self._ac_api.create_meeting(meeting_description=185 "fn-test-meeting-{0}".186 format(generate_random_id()),187 start_date=datetime.utcnow(),188 end_date=None)189 # Add participants190 # Host191 self.host_user.add_to_meeting_room(self._ac_api,192 room.sco_id, "host")193 # Attendee194 self.attendee_user.add_to_meeting_room(self._ac_api,195 room.sco_id, "mini-host")196 # Authenticate and get URL197 # host198 host_url = self.host_user.get_url_for_meeting_room(self._ac_api,199 room.sco_id)200 print host_url201 self.assertIn("https://flashnotes.adobeconnect.com", host_url)202 # attendee203 attendee_url = self.attendee_user.\204 get_url_for_meeting_room(self._ac_api, room.sco_id)205 print attendee_url206 self.assertIn("https://flashnotes.adobeconnect.com", attendee_url)207 # This is to clean up resources. If you want to test that the208 # host URL will log the user in as HOST you can comment out this line.209 self.host_user.remove_from_hosts_group(self._ac_api)210@skip("Only run these tests on-demand due to Adobe resource dependency.")211class AdobeConnectMeetingManagerTests(TestCase):212 """213 This test will use a Mock class214 """215 class AdobeConnectMeetingManagerMock(AdobeConnectMeetingManager):216 def __init__(self):217 self._adobe_connect_meeting_room = None218 self.host = factories.User.create(email="testhost@fntest.com")219 self.attendee = factories.User.create(email="testlearner@fntest.com")220 self.scheduled_start_time = pytz.UTC.localize(datetime.utcnow() +221 timedelta(minutes=1))222 self.some_other_user = factories.User.create(email="testother@fntest.com".223 format(generate_random_id(4)))224 def get_host(self):225 return self.host226 def get_meeting_room_template_type(self):227 return "TUTORING"228 def get_attendees(self):229 from django.contrib.auth.models import User230 return User.objects.filter(id=self.attendee.id)231 def get_adobe_connect_meeting_sco_id(self):232 return self._adobe_connect_meeting_room233 def set_adobe_connect_meeting_sco_id(self, sco_id, save=True):234 self._adobe_connect_meeting_room = sco_id235 def get_scheduled_start_time(self):236 return self.scheduled_start_time237 def test_create_resources_with_adobe_connect_meeting_manager(self):...
__init__.py
Source:__init__.py
...6 generate_random_item7)8# Client SignUp POST Request Details9client = {10 'id': generate_random_id(),11 'email': generate_random_email(),12 'username': generate_random_username(),13 'first_name': 'jane',14 'last_name': 'doe',15 'password': generate_random_password()16}17updated_client_data = {18 'bio': 'Bio updated'19}20successful_update = {'msg': 'User profile updated successfully'}21client_profile = {22 'email': generate_random_email(),23 'username': generate_random_username(),24 'first_name': 'jane',25 'last_name': 'doe',26 'bio': None,27 'avatar_url': None28}29exp_client = {30 'email': generate_random_email(),31 'username': generate_random_username(),32 'last_name': 'doe',33 'avatar_filename': None,34 'avatar_url': None,35 'bio': None,36 'id': 1,37 'avatar_uploaded': False,38}39# Mailgun Email, Email Subject, and Email Text Details40class EmailDetails:41 email = [generate_random_email()]42 subject = 'Account Verification'43 text = 'Hello, your account has been verified.'44# Client SignIn POST Request Details45client_signin = {46 'email': generate_random_email(),47 'password': generate_random_password()48}49# Github50github_authorized_response = {51 'status': 200,52 'access_token': 'access_token'53}54github_user_data = {55 'login': generate_random_username(),56 'email': generate_random_email(),57 'name': 'Jane Doe'58}59twitter_user_data = {60 'email': generate_random_email(),61 'screen_name': generate_random_username(),62 'name': 'jane doe',63}64google_user_data = {65 'email': generate_random_email(),66 'given_name': 'jane',67 'family_name': 'doe',68}69facebook_user_data = {70 'email': generate_random_email(),71 'short_name': generate_random_username(),72 'first_name': 'jane',73 'last_name': 'doe',74}75blocked_token = {76 'id': 1, 'jti': '1eb0f7f7-9c18-45c6-b297-15873258b328', 'client_id': 1, 'business_id': None}77searched_client = {78 'username': generate_random_username(),79 'bio': None,80 'avatar_url':81 'http://localhost:5001/static/images/assets/default-avatar.png',82 'first_name': 'jane',83 'last_name': 'doe',84 'email': generate_random_email()85}86cad_model_data = {87 'cad_model_name': 'Test CAD Model',88 'cad_model_height': 12.5,89 'cad_model_length': 12.5,90 'cad_model_width': 12.5,91 'cad_model_visibility': True,92 'cad_model_material': 'PLA',93 'cad_model_mesh_percent': 50,94 # 'cad_object_key': 'client_1/Test CAD Model'95}96cad_model_update_data = {97 'cad_model_name': 'Test CAD Model',98 'cad_model_height': 15,99 'cad_model_length': 15,100 'cad_model_width': 15,101 'cad_model_visibility': False,102 'cad_model_material': 'ABS',103 'cad_model_mesh_percent': 25,104}105# Business details106business_data = {107 'id': generate_random_id(),108 'business_name': generate_random_username(),109 'email': generate_random_email(),110 'username': generate_random_username(),111 'password': generate_random_password(),112 'bio': generate_random_username()113}114update_business_data = {115 'business_name': generate_random_username(),116 'email': generate_random_email(),117 'username': generate_random_username(),118 'password': generate_random_password(),119 'bio': generate_random_username()120}121# Printer details122print_materials = ('PLA', 'ABS', 'ASA', 'HIPS', 'PETG', 'NYLON', 'CFF', 'PCB', 'PVA',)123print_file_types = ('STL', 'OBJ', 'AMF', '_3MF', 'PLY', 'STEP', 'IGES')124printer_data = {125 "id": generate_random_id(),126 "name": generate_random_username(),127 "model": generate_random_username(),128 "base_width": generate_random_id(),129 "base_length": generate_random_id(),130 "height": generate_random_id(),131 "nozzle_diameter": generate_random_id(),132 "file_type": generate_random_item(print_file_types), # Enum (printer_file_type) of 5 popular file types133 "material": generate_random_item(print_materials) # Enum (printer_material) of 10 popular materials134}135printer_update_data = {136 "id": generate_random_id(),137 "name": generate_random_username(),138 "model": generate_random_username(),139 "base_width": generate_random_id(),140 "base_length": generate_random_id(),141 "height": generate_random_id(),142 "nozzle_diameter": generate_random_id(),143 "file_type": generate_random_item(print_file_types), # Enum (printer_file_type) of 5 popular file types144 "material": generate_random_item(print_materials) # Enum (printer_material) of 10 popular materials...
conftest.py
Source:conftest.py
1import pytest2import responses3from parrot_api.core import generate_random_id4issuer_list = [generate_random_id() for _ in range(3)]5audience_list = [generate_random_id() for _ in range(3)]6@pytest.fixture(scope='module')7def issuers():8 return issuer_list9@pytest.fixture(scope='module')10def audiences():11 return audience_list12@pytest.fixture(params=issuer_list)13def issuer(request):14 return request.param15@pytest.fixture(params=audience_list)16def audience(request):17 return request.param18@pytest.fixture()19def test_directory():20 import os21 return os.path.abspath(__file__).replace('conftest.py', '')22@pytest.fixture()23def app_settings(test_directory):24 from parrot_api.core import get_settings25 import os26 settings=get_settings(env_folder=os.path.join(test_directory, 'mocks/settings'), refresh=True)27 return settings28@pytest.fixture( )29def signing_key(test_directory):30 import os31 import json32 with open(os.path.join(test_directory, 'mocks/signing_key.json'), 'rt') as f:33 key = json.load(f)34 return key35@pytest.fixture( )36def public_keys(test_directory):37 import os38 import json39 with open(os.path.join(test_directory, 'mocks/public_keys.json'), 'rt') as f:40 key = json.load(f)41 return key42@pytest.fixture()43def client(test_directory):44 import os45 from parrot_api.core.server import create_server46 app = create_server(spec_dir=os.path.join(test_directory, 'mocks/schemas'))47 return app.app.test_client()48@pytest.fixture()49def valid_access_headers(app_settings, signing_key):50 from parrot_api.core import generate_oauth_headers51 from parrot_api.core.auth.jwt import format_access_token, sign_token52 from parrot_api.core.common import generate_random_id53 payload = format_access_token(54 user=generate_random_id(), machine_token=True, audiences=app_settings['audiences'],55 issuer=app_settings['issuers'][0],56 expiration_seconds=60 * 60,57 scopes=["get:hello"]58 )59 token = sign_token(payload=payload, signing_key=signing_key)60 return generate_oauth_headers(access_token=get_token(token, app_settings))61@pytest.fixture()62def invalid_access_headers(app_settings, issuer, signing_key):63 from parrot_api.core import generate_oauth_headers64 from parrot_api.core.auth.jwt import format_access_token, sign_token65 from parrot_api.core.common import generate_random_id66 payload = format_access_token(67 user=generate_random_id(), machine_token=True, audiences=app_settings['audiences'], issuer=generate_random_id(),68 expiration_seconds=60 * 60,69 scopes=[generate_random_id() for i in range(3)]70 )71 token = sign_token(payload=payload, signing_key=signing_key)72 return generate_oauth_headers(access_token=get_token(token, app_settings))73@pytest.fixture()74def unauthorized_access_headers(app_settings, signing_key):75 from parrot_api.core import generate_oauth_headers76 from parrot_api.core.auth.jwt import format_access_token, sign_token77 from parrot_api.core.common import generate_random_id78 payload = format_access_token(79 user=generate_random_id(), machine_token=True, audiences=app_settings['audiences'],80 issuer=app_settings['issuers'][0],81 expiration_seconds=60 * 60,82 scopes=[generate_random_id() for i in range(3)]83 )84 token = sign_token(payload=payload, signing_key=signing_key)85 return generate_oauth_headers(access_token=get_token(token, app_settings))86@pytest.fixture()87def user_access_headers(app_settings, signing_key):88 from parrot_api.core.requests import generate_oauth_headers89 from parrot_api.core.auth.jwt import format_access_token, sign_token90 from parrot_api.core.common import generate_random_id91 payload = format_access_token(92 user=generate_random_id(), machine_token=False, audiences=app_settings['audiences'],93 issuer=app_settings['issuers'][0],94 expiration_seconds=60 * 60,95 scopes=[]96 )97 token = sign_token(payload=payload, signing_key=signing_key)98 print(payload)99 return generate_oauth_headers(access_token=get_token(token, app_settings))100@responses.activate101def get_token(token, app_settings):102 from parrot_api.core.auth.oauth import get_service_access_token103 responses.add(104 responses.Response(method=responses.POST, url=app_settings['auth_server'],105 json=dict(access_token=token, expires_in=86400),106 status=200))...
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!!