How to use test_access method in pytest-django

Best Python code snippet using pytest-django_python

test_access.py

Source:test_access.py Github

copy

Full Screen

...320 self.test_access.read([test.id])321 test.field1322 test.field2323 transaction.cursor.cache.clear()324 test = self.test_access(test.id)325 # With field access326 # One access allowed for any group327 field_access_wo_group, = self.field_access.create([{328 'field': field1.id,329 'group': None,330 'perm_read': True,331 }])332 self.test_access.read([test.id], ['field1'])333 self.test_access.read([test.id], ['field2'])334 self.test_access.read([test.id])335 test.field1336 test.field2337 transaction.cursor.cache.clear()338 test = self.test_access(test.id)339 # One access disallowed for any group340 self.field_access.write([field_access_wo_group], {341 'perm_read': False,342 })343 self.assertRaises(Exception, self.test_access.read, [test.id],344 ['field1'])345 self.test_access.read([test.id], ['field2'])346 self.assertRaises(Exception, self.test_access.read, [test.id])347 self.assertRaises(Exception, getattr, test, 'field1')348 test.field2349 transaction.cursor.cache.clear()350 test = self.test_access(test.id)351 # Two access rules with one group allowed352 group = self.group.search([('users', '=', USER)])[0]353 field_access_w_group, = self.field_access.create([{354 'field': field1.id,355 'group': group.id,356 'perm_read': True,357 }])358 self.test_access.read([test.id], ['field1'])359 self.test_access.read([test.id], ['field2'])360 self.test_access.read([test.id])361 test.field1362 test.field2363 transaction.cursor.cache.clear()364 test = self.test_access(test.id)365 # Two access rules with both allowed366 self.field_access.write([field_access_wo_group], {367 'perm_read': True,368 })369 self.test_access.read([test.id], ['field1'])370 self.test_access.read([test.id], ['field2'])371 self.test_access.read([test.id])372 test.field1373 test.field2374 transaction.cursor.cache.clear()375 test = self.test_access(test.id)376 # Two access rules with any group allowed377 self.field_access.write([field_access_w_group], {378 'perm_read': False,379 })380 self.test_access.read([test.id], ['field1'])381 self.test_access.read([test.id], ['field2'])382 self.test_access.read([test.id])383 test.field1384 test.field2385 transaction.cursor.cache.clear()386 test = self.test_access(test.id)387 # Two access rules with both disallowed388 self.field_access.write([field_access_wo_group], {389 'perm_read': False,390 })391 self.assertRaises(Exception, self.test_access.read, [test.id],392 ['field1'])393 self.test_access.read([test.id], ['field2'])394 self.assertRaises(Exception, self.test_access.read, [test.id])395 self.assertRaises(Exception, getattr, test, 'field1')396 test.field2397 transaction.cursor.cache.clear()398 test = self.test_access(test.id)399 # One access disallowed for one group400 self.field_access.delete([field_access_wo_group])401 self.assertRaises(Exception, self.test_access.read, [test.id],402 ['field1'])403 self.test_access.read([test.id], ['field2'])404 self.assertRaises(Exception, self.test_access.read, [test.id])405 self.assertRaises(Exception, getattr, test, 'field1')406 test.field2407 transaction.cursor.cache.clear()408 test = self.test_access(test.id)409 # One access allowed for one group410 self.field_access.write([field_access_w_group], {411 'perm_read': True,412 })413 self.test_access.read([test.id], ['field1'])414 self.test_access.read([test.id], ['field2'])415 self.test_access.read([test.id])416 test.field1417 test.field2418 transaction.cursor.cache.clear()419 test = self.test_access(test.id)420 # One access allowed for one other group421 group, = self.group.create([{'name': 'Test'}])422 self.field_access.write([field_access_w_group], {423 'group': group.id,424 })425 self.test_access.read([test.id], ['field1'])426 self.test_access.read([test.id], ['field2'])427 self.test_access.read([test.id])428 test.field1429 test.field2430 transaction.cursor.cache.clear()431 test = self.test_access(test.id)432 # One access disallowed for one other group433 self.field_access.write([field_access_w_group], {434 'perm_read': False,435 })436 self.test_access.read([test.id], ['field1'])437 self.test_access.read([test.id], ['field2'])438 self.test_access.read([test.id])439 test.field1440 test.field2441 transaction.cursor.cache.clear()442 test = self.test_access(test.id)443 # Two access rules on both fields allowed444 self.field_access.delete([field_access_w_group])445 field_access1, = self.field_access.create([{446 'field': field1.id,447 'group': None,448 'perm_read': True,449 }])450 field_access2, = self.field_access.create([{451 'field': field2.id,452 'group': None,453 'perm_read': True,454 }])455 self.test_access.read([test.id], ['field1'])456 self.test_access.read([test.id], ['field2'])457 self.test_access.read([test.id])458 test.field1459 test.field2460 transaction.cursor.cache.clear()461 test = self.test_access(test.id)462 # Two access rules on both fields one allowed and one disallowed463 self.field_access.write([field_access2], {464 'perm_read': False,465 })466 self.test_access.read([test.id], ['field1'])467 self.assertRaises(Exception, self.test_access.read, [test.id],468 ['field2'])469 self.assertRaises(Exception, self.test_access.read, [test.id])470 test.field1471 self.assertRaises(Exception, getattr, test, 'field2')472 transaction.cursor.cache.clear()473 test = self.test_access(test.id)474 # Two access rules on both fields disallowed475 self.field_access.write([field_access1], {476 'perm_read': False,477 })478 self.assertRaises(Exception, self.test_access.read, [test.id],479 ['field1'])480 self.assertRaises(Exception, self.test_access.read, [test.id],481 ['field2'])482 self.assertRaises(Exception, self.test_access.read, [test.id])483 self.assertRaises(Exception, getattr, test, 'field1')484 self.assertRaises(Exception, getattr, test, 'field2')485 transaction.cursor.cache.clear()486 test = self.test_access(test.id)487 transaction.cursor.rollback()488 self.field_access._get_access_cache.clear()489 def test0010perm_write(self):490 '''491 Test Write Access492 '''493 with Transaction().start(DB_NAME, USER,494 context=CONTEXT) as transaction:495 field1, = self.field.search([496 ('model.model', '=', 'test.access'),497 ('name', '=', 'field1'),498 ])499 field2, = self.field.search([500 ('model.model', '=', 'test.access'),...

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 pytest-django 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