How to use get_package_data method in autotest

Best Python code snippet using autotest_python

tests.py

Source:tests.py Github

copy

Full Screen

1""" Tests """2# Python3import json4from unittest.mock import patch5# Django6from django.test import TestCase, Client7from django.urls import reverse8# trcpck9from trckpck.app.models import Package, Company, AppUser10class PackageTest(TestCase):11 """ Test for packages """12 def setUp(self):13 """ set up """14 self.client = Client(HTTP_X_username='random_user')15 apple = Company.objects.create(company_name='apple')16 komplett = Company.objects.create(company_name='komplett')17 asus = Company.objects.create(company_name='asus')18 for i in range(6):19 Package.objects.create(company_owner=apple, tracker_id=str(i))20 for i in range(4):21 Package.objects.create(22 company_owner=komplett, tracker_id=str(i + 10))23 for i in range(2):24 Package.objects.create(company_owner=asus, tracker_id=str(i + 20))25 AppUser.objects.create(username='superuser', is_superuser=True)26 user = AppUser.objects.create(27 username='random_user', is_superuser=False)28 apple.appuser_set.add(user)29 asus.appuser_set.add(user)30 def dummy_data(self):31 """" Return dummy data """32 return 'test'33 def dummy_data_timestamp_and_position(self):34 """ return dummy data"""35 return 'some_timestamp', 'some position'36 @patch.object(Package, 'get_package_data', dummy_data)37 def get_packages_data_by_company_id(self):38 """ test get packages by company id """39 res = self.client.get(reverse('get_packages_data_by_company_id', args=[40 'apple']), format='JSON', HTTP_X_username='superuser')41 self.assertEqual(len(json.loads(res.content)), 6)42 @patch.object(Package, 'get_package_data', dummy_data)43 @patch.object(Package, 'get_latest_timestamp_and_position',44 dummy_data_timestamp_and_position)45 def test_get_tracker_data_no_q(self):46 """ Make sure that tracker_data returns 200"""47 res = self.client.get(reverse('tracker_data'),48 format='JSON', HTTP_X_username='superuser')49 self.assertEqual(res.status_code, 200)50 self.assertEqual(len(json.loads(res.content)), 12)51 @patch.object(Package, 'get_package_data', dummy_data)52 @patch.object(Package, 'get_latest_timestamp_and_position',53 dummy_data_timestamp_and_position)54 def test_get_tracker_data_id_q(self):55 """ Make sure that tracker_data returns 200 when given a existing pkg"""56 res = self.client.get(reverse('tracker_data') + "?id=1",57 format='JSON', HTTP_X_username='superuser')58 self.assertEqual(res.status_code, 200)59 @patch.object(Package, 'get_package_data', dummy_data)60 @patch.object(Package, 'get_latest_timestamp_and_position',61 dummy_data_timestamp_and_position)62 def test_get_tracker_data_id_q_404(self):63 """ Make sure that tracker_data returns 200 when given a existing pkg"""64 res = self.client.get(reverse('tracker_data') + "?id=9000",65 format='JSON', HTTP_X_username='superuser')66 self.assertEqual(res.status_code, 404)67 @patch.object(Package, 'get_package_data', dummy_data)68 @patch.object(Package, 'get_latest_timestamp_and_position',69 dummy_data_timestamp_and_position)70 def test_get_tracker_data_company_q(self):71 """ Make sure that tracker_data returns 200 when given a existing pkg"""72 res = self.client.get(reverse(73 'tracker_data') + "?company=apple", format='JSON', HTTP_X_username='superuser')74 self.assertEqual(res.status_code, 200)75 self.assertEqual(len(json.loads(res.content)), 6)76 @patch.object(Package, 'get_package_data', dummy_data)77 @patch.object(Package, 'get_latest_timestamp_and_position',78 dummy_data_timestamp_and_position)79 def test_get_user_data(self):80 """ Make sure a user gets all his data """81 response = self.client.get(82 reverse('user_data'), format='JSON', HTTP_X_username='random_user')83 response2 = self.client.get(84 reverse('user_data'), format='JSON', HTTP_X_username='not_existing_user')85 self.assertEqual(response.status_code, 200)86 self.assertEqual(len(json.loads(response.content)), 8)87 self.assertEqual(response2.status_code, 403)88 @patch.object(Package, 'get_package_data', dummy_data)89 @patch.object(Package, 'get_latest_timestamp_and_position',90 dummy_data_timestamp_and_position)91 def test_superuser_authorization(self):92 """ Make sure that superusers are authorized to do anything """93 response1 = self.client.get(94 reverse('tracker_data'), format='JSON', HTTP_X_username='superuser')95 response2 = self.client.get(reverse(96 'tracker_data') + "?company=apple", format='JSON', HTTP_X_username='superuser')97 response3 = self.client.get(98 reverse('tracker_data') + "?id=1", format='JSON', HTTP_X_username='superuser')99 self.assertEqual(response1.status_code, 200)100 self.assertEqual(response2.status_code, 200)101 self.assertEqual(response3.status_code, 200)102 @patch.object(Package, 'get_package_data', dummy_data)103 @patch.object(Package, 'get_latest_timestamp_and_position',104 dummy_data_timestamp_and_position)105 def test_not_authorized(self):106 """ Make sure that unauthorized users cannot do anything """107 response1 = self.client.get(reverse(108 'tracker_data'), format='JSON', HTTP_X_username='user_without_permissions')109 response2 = self.client.get(reverse(110 'tracker_data') + "?company=apple", format='JSON', HTTP_X_username='user_without_permissions')111 response3 = self.client.get(reverse(112 'tracker_data') + "?id=1", format='JSON', HTTP_X_username='user_without_permissions')113 self.assertEqual(response1.status_code, 403)114 self.assertEqual(response2.status_code, 403)115 self.assertEqual(response3.status_code, 403)116 @patch.object(Package, 'get_package_data', dummy_data)117 @patch.object(Package, 'get_latest_timestamp_and_position',118 dummy_data_timestamp_and_position)119 def test_partly_authorized(self):120 """ Make sure that partly authorized users only can do some things """121 response1 = self.client.get(122 reverse('tracker_data'), format='JSON', HTTP_X_username='random_user')123 response2 = self.client.get(reverse(124 'tracker_data') + "?company=apple", format='JSON', HTTP_X_username='random_user')125 response3 = self.client.get(reverse(126 'tracker_data') + "?company=asus", format='JSON', HTTP_X_username='random_user')127 response4 = self.client.get(reverse(128 'tracker_data') + "?company=komplett", format='JSON', HTTP_X_username='random_user')129 response5 = self.client.get(130 reverse('tracker_data') + "?id=1", format='JSON', HTTP_X_username='random_user')131 response6 = self.client.get(132 reverse('tracker_data') + "?id=7", format='JSON', HTTP_X_username='random_user')133 self.assertEqual(response1.status_code, 403)134 self.assertEqual(response2.status_code, 200)135 self.assertEqual(response3.status_code, 200)136 self.assertEqual(response4.status_code, 403)137 self.assertEqual(response5.status_code, 200)...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

...80def get_data_files():81 return (tko.setup.get_data_files() +82 utils.setup.get_data_files() +83 mirror.setup.get_data_files())84def get_package_data():85 return _combine_dicts([86 _fix_data_paths(client.setup.get_package_data()),87 _fix_data_paths(frontend.setup.get_package_data()),88 _fix_data_paths(cli.setup.get_package_data()),89 _fix_data_paths(server.setup.get_package_data()),90 _fix_data_paths(scheduler.setup.get_package_data()),91 _fix_data_paths(database_legacy.setup.get_package_data()),92 _fix_data_paths(utils.setup.get_package_data())93 ])94def get_scripts():95 return (client.setup.get_scripts() +96 frontend.setup.get_scripts() +97 cli.setup.get_scripts() +98 server.setup.get_scripts() +99 scheduler.setup.get_scripts() +100 database_legacy.setup.get_scripts() +101 tko.setup.get_scripts() +102 installation_support.setup.get_scripts())103def run():104 setup(name='autotest',105 description='Autotest test framework',106 maintainer='Lucas Meneghel Rodrigues',107 maintainer_email='lmr@redhat.com',108 version=version.get_version(),109 url='http://autotest.github.com',110 package_dir=get_package_dir(),111 package_data=get_package_data(),112 packages=get_packages(),113 scripts=get_scripts(),114 data_files=get_data_files(),115 cmdclass=cmdclass,116 command_options=command_options,117 include_package_data=True,118 )119if __name__ == '__main__':...

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