How to use create_agent method in tempest

Best Python code snippet using tempest_python

tests.py

Source:tests.py Github

copy

Full Screen

...250 # print(response.data)251 self.assertEqual(response.status_code, status.HTTP_201_CREATED)252 def test_create_account_fail_username(self):253 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)254 agent = create_agent(self.username2, manager)255 client.force_authenticate(self.organizer1)256 response = client.post(257 user_prefix + USER_ULRS['account'],258 {259 'username': self.username2,260 'full_name': 'agent1',261 'designation': 'AGM',262 'parent': manager.id,263 'role': ROLE_DICT['Employee'],264 'org': manager.org.id,265 },266 format='json',267 )268 # print(response.data)269 self.assertEqual(response.status_code, 406)270 def test_get_profile_success(self):271 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)272 AppInfo.objects.create(273 current_version=10, app_name='manager'274 )275 AppInfo.objects.create(276 current_version=11, app_name='agent'277 )278 client.force_authenticate(manager)279 response = client.get(280 user_prefix + USER_ULRS['profile_id'].replace('<int:pk>', str(manager.id)),281 format='json',282 )283 self.assertEqual(response.status_code, status.HTTP_200_OK)284 self.assertEqual(response.data['current_version'], 10)285 # print(json.dumps(response.data))286 agent = create_agent(self.username2, manager)287 client.force_authenticate(None)288 client.force_authenticate(agent)289 response = client.get(290 user_prefix + USER_ULRS['profile_id'].replace('<int:pk>', str(agent.id)),291 format='json',292 )293 self.assertEqual(response.status_code, status.HTTP_200_OK)294 self.assertEqual(response.data['current_version'], 11)295 def test_get_account_success(self):296 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)297 agent = create_agent(self.username2, manager)298 client.force_authenticate(manager)299 response = client.get(300 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),301 format='json',302 )303 self.assertEqual(response.status_code, status.HTTP_200_OK)304 def test_get_account_fail_org(self):305 manager1 = create_manager(self.username1, self.organizer1, self.organizer1.org)306 manager2 = create_manager(self.username1, self.organizer2, self.organizer2.org)307 agent = create_agent(self.username3, manager2)308 client.force_authenticate(manager1)309 response = client.get(310 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),311 format='json',312 )313 self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)314 def test_get_account_list(self):315 manager1 = create_manager(self.username1, None, self.organizer1.org)316 manager11 = create_manager(self.username2, manager1, self.organizer1.org)317 agent11 = create_agent(self.username3, manager1)318 manager111 = create_manager(self.username7, manager11, self.organizer1.org)319 agent111 = create_agent(self.username8, manager11)320 agent112 = create_agent(self.username9, manager11)321 manager2 = create_manager(self.username4, self.organizer1, self.organizer1.org)322 manager21 = create_manager(self.username5, manager2, self.organizer1.org)323 agent22 = create_agent(self.username6, manager2)324 manager3 = create_manager(self.username20, None, self.organizer1.org)325 client.force_authenticate(manager1)326 response = client.get(327 user_prefix + USER_ULRS['account'],328 {329 },330 format='json',331 )332 self.assertEqual(response.status_code, 200)333 self.assertEqual(len(response.data), 6)334 response = client.get(335 user_prefix + USER_ULRS['account'],336 {337 'role': ROLE_DICT['Manager']338 },339 format='json',340 )341 self.assertEqual(response.status_code, 200)342 self.assertEqual(len(response.data), 3)343 client.force_authenticate(None)344 client.force_authenticate(self.organizer1)345 response = client.get(346 user_prefix + USER_ULRS['account'],347 {348 'role': ROLE_DICT['Manager']349 },350 format='json',351 )352 self.assertEqual(response.status_code, status.HTTP_200_OK)353 self.assertEqual(len(response.data), 6)354 response = client.get(355 user_prefix + USER_ULRS['account'],356 {357 'manager_id': manager11.id358 },359 format='json',360 )361 self.assertEqual(response.status_code, status.HTTP_200_OK)362 self.assertEqual(len(response.data), 3)363 response = client.get(364 user_prefix + USER_ULRS['account'],365 {366 'manager_id': self.organizer1.id367 },368 format='json',369 )370 self.assertEqual(response.status_code, status.HTTP_200_OK)371 # print(response.data)372 self.assertEqual(len(response.data), 2)373 def test_get_resource_list_success(self):374 manager1 = create_manager(self.username1, self.organizer1, self.organizer1.org)375 agent11 = create_agent(self.username2, manager1)376 agent12 = create_agent(self.username3, manager1)377 task1 = create_task('Task_test1', manager1, [agent11, agent12], status=TSTATE['In progress'])378 client.force_authenticate(manager1)379 response = client.get(380 user_prefix + USER_ULRS['resource_list'],381 {382 'status': 'working'383 },384 format='json',385 )386 self.assertEqual(response.status_code, status.HTTP_200_OK)387 self.assertEqual(len(response.data), 2)388 client.force_authenticate(None)389 client.force_authenticate(self.organizer1)390 response = client.get(391 user_prefix + USER_ULRS['resource_list'],392 {393 'status': 'working'394 },395 format='json',396 )397 self.assertEqual(response.status_code, status.HTTP_200_OK)398 self.assertEqual(len(response.data), 0)399 # print(response.data)400 def test_edit_account_success(self):401 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)402 agent = create_agent(self.username3, manager)403 client.force_authenticate(self.organizer1)404 response = client.patch(405 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),406 {407 'username': self.username4,408 'full_name': 'agent1',409 'parent': manager.id,410 'role': ROLE_DICT['Employee'],411 },412 format='json',413 )414 # print(response.data)415 self.assertEqual(response.status_code, status.HTTP_200_OK)416 agent = User.objects.get(id=agent.id)417 self.assertEqual(agent.username, create_username(agent.org.oid, self.username4))418 def test_change_manger_success(self):419 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)420 manager2 = create_manager(self.username5, self.organizer1, self.organizer1.org)421 agent = create_agent(self.username2, manager)422 client.force_authenticate(self.organizer1)423 response = client.patch(424 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),425 {426 'username': self.username2,427 'full_name': 'agent1',428 'parent': manager2.id,429 'role': ROLE_DICT['Employee'],430 },431 format='json',432 )433 # print(response.data)434 self.assertEqual(response.status_code, status.HTTP_200_OK)435 def test_set_manger_none_success(self):436 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)437 agent = create_agent(self.username2, manager)438 client.force_authenticate(self.organizer1)439 response = client.patch(440 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),441 {442 'username': self.username2,443 'full_name': 'agent1',444 'parent': None,445 'role': ROLE_DICT['Employee'],446 },447 format='json',448 )449 # print(response.data)450 self.assertEqual(response.status_code, status.HTTP_200_OK)451 def test_edit_account_fail_username_exists(self):452 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)453 agent = create_agent(self.username3, manager)454 agent2 = create_agent(self.username4, manager)455 client.force_authenticate(self.organizer1)456 response = client.patch(457 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),458 {459 'username': self.username4,460 'full_name': 'agent1',461 'parent': manager.id,462 'role': ROLE_DICT['Employee'],463 'org': manager.org.id,464 },465 format='json',466 )467 # print(response.data)468 self.assertEqual(response.status_code, 406)469 def test_edit_account_fail_username_with_spaces(self):470 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)471 agent = create_agent(self.username3, manager)472 agent2 = create_agent(self.username4, manager)473 client.force_authenticate(self.organizer1)474 response = client.patch(475 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),476 {477 'username': 'A User1',478 'full_name': 'agent1',479 'parent': manager.id,480 'role': ROLE_DICT['Employee'],481 'org': manager.org.id,482 },483 format='json',484 )485 # print(response.data)486 self.assertEqual(response.status_code, 400)487 def test_delete_account_success(self):488 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)489 agent = create_agent(self.username3, manager)490 client.force_authenticate(self.organizer1)491 response = client.delete(492 user_prefix + USER_ULRS['account_id'].replace('<int:pk>', str(agent.id)),493 {},494 format='json',495 )496 # print(response.data)497 self.assertEqual(response.status_code, status.HTTP_200_OK)498 self.assertEqual(User.objects.filter(phone=self.username3).exists(), False)499 def test_fb_token_update_success(self):500 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)501 token = uuid.uuid4()502 client.force_authenticate(manager)503 response = client.post(504 user_prefix + USER_ULRS['update_fb_token'],505 {506 'fb_token': token,507 },508 format='json',509 )510 self.assertEqual(response.status_code, status.HTTP_200_OK)511 # print(response.data)512 def test_get_dashboard_success(self):513 '''Team1 details'''514 manager1 = create_manager(self.username1, self.organizer1, self.organizer1.org)515 agent1 = create_agent(self.username2, manager1)516 agent2 = create_agent(self.username3, manager1)517 agent3 = create_agent(self.username4, manager1)518 agent4 = create_agent(self.username5, manager1)519 task1 = create_task('Retailer 1', manager1, [agent1, agent2], status=TSTATE['In progress'])520 task2 = create_task('Doctor Visit', manager1, [agent2])521 task3 = create_task('Survey 1', manager1, [agent3])522 task3.delayed = True523 task3.save()524 task4 = create_task('Survey 2', manager1, [agent4], status=TSTATE['Cancelled'])525 '''Team2 details'''526 manager2 = create_manager(self.username6, self.organizer1, self.organizer1.org)527 agent5 = create_agent(self.username7, manager2)528 task5 = create_task('Demand Collection', manager2, [agent5], status=TSTATE['In progress'])529 task5 = create_task('Delivery', manager2, [agent5], status=TSTATE['Cancelled'])530 client.force_authenticate(manager1)531 response = client.get(532 user_prefix + USER_ULRS['search_api_manager'].replace('<str:token>', 'survey'),533 {},534 format='json',535 )536 # print(response.data)537 self.assertEqual(response.status_code, status.HTTP_200_OK)538 client.force_authenticate(user=None)539 client.force_authenticate(manager2)540 response = client.get(541 user_prefix + USER_ULRS['manager_dashboard'],542 {},543 format='json',544 )545 # print(response.data)546 self.assertEqual(response.status_code, status.HTTP_200_OK)547 client.force_authenticate(user=None)548 client.force_authenticate(agent2)549 response = client.get(550 user_prefix + USER_ULRS['agent_dashboard'],551 {},552 format='json',553 )554 # print(response.data)555 self.assertEqual(response.status_code, status.HTTP_200_OK)556 self.assertEqual(len(response.data['current_task']), 1)557 self.assertEqual(response.data['current_task'][0]['title'], 'Retailer 1')558 def test_search_account_light_success(self):559 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)560 agent1 = create_agent(self.username3, manager)561 agent2 = create_agent(self.username4, manager)562 agent3 = create_agent('halios', manager)563 client.force_authenticate(self.organizer1)564 response = client.get(565 user_prefix + USER_ULRS['search_user'].replace('<str:token>', 'user'),566 {},567 format='json',568 )569 # print(response.data)570 self.assertEqual(response.status_code, status.HTTP_200_OK)571 self.assertEqual(len(response.data), 3)572 def test_search_account_in_list_success(self):573 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)574 agent1 = create_agent(self.username3, manager)575 agent2 = create_agent(self.username4, manager)576 agent3 = create_agent('halios', manager)577 client.force_authenticate(self.organizer1)578 response = client.get(579 user_prefix + USER_ULRS['accounts_paginated'],580 {581 'token': ''582 },583 format='json',584 )585 # print(response.data)586 self.assertEqual(response.status_code, status.HTTP_200_OK)587 self.assertEqual(len(response.data['results']), 4)588 client.force_authenticate(self.organizer1)589 response = client.get(590 user_prefix + USER_ULRS['accounts_paginated'],591 {592 'token': 'username'593 },594 format='json',595 )596 # print(response.data)597 self.assertEqual(response.status_code, status.HTTP_200_OK)598 self.assertEqual(len(response.data['results']), 3)599 def test_data_usage_upload_success(self):600 manager = create_manager(self.username1, self.organizer1, self.organizer1.org)601 agent1 = create_agent(self.username3, manager)602 agent2 = create_agent(self.username4, manager)603 mb_list1 = [0.5, 1.5, 0.5, 1.5, 2.0]604 # total1 = .5 + 1 + .5 + 1 + .5 = 3.5605 mb_list2 = [7.5, 8.5, 0.5, 1.5, 2.0]606 # total2 = 7.5 + 1 + .5 + 1 + .5 = 10.5607 for mb in mb_list1:608 upload_data(self, mb, agent1, '00:0a:95:9d:68:16')609 for mb in mb_list2:610 upload_data(self, mb, agent1, '00:0a:95:9d:68:17')611 for mb in mb_list1:612 upload_data(self, mb, agent2, '00:0a:95:9d:68:18')613 client.force_authenticate(None)614 client.force_authenticate(manager)615 response = client.get(616 user_prefix + USER_ULRS['data_usage'],...

Full Screen

Full Screen

test_agent_factory.py

Source:test_agent_factory.py Github

copy

Full Screen

...12class TestAgentFactory(TestCase):13 def setUp(self):14 self.factory = InfrastructureAgentFactory()15 def test_create_agent_ec2(self):16 agent = self.factory.create_agent('ec2')17 self.assertIsInstance(agent, EC2Agent)18 def test_create_agent_euca(self):19 agent = self.factory.create_agent('euca')20 self.assertIsInstance(agent, EucalyptusAgent)21 def test_create_agent_azure(self):22 agent = self.factory.create_agent('azure')23 self.assertIsInstance(agent, AzureAgent)24 def test_create_agent_gce(self):25 agent = self.factory.create_agent('gce')26 self.assertIsInstance(agent, GCEAgent)27 def test_create_agent_openstack(self):28 agent = self.factory.create_agent('openstack')29 self.assertIsInstance(agent, OpenStackAgent)30 def test_create_invalid_infrastructure(self):31 """32 Ensure that the correct exception is thrown if the create_agent method is33 given an invalid parameter (agent)34 """...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.urls import path2from reports.views import create_agent, get_agents, create_report, get_reports3urlpatterns = [4 path("create_agent", create_agent.create_agent, name="create_agent"),5 path("get_agents", get_agents.get_agents, name="get_agents"),6 path("create_report", create_report.create_report, name="create_report"),7 path("get_reports", get_reports.get_reports, name="get_reports"),8 path("get_reports/<id>", get_reports.get_reports, name="get_reports"),...

Full Screen

Full Screen

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 tempest 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