from django.contrib.auth.models import Userfrom django.test import TestCase
class FooTest(TestCase): def test_bar(self): with transaction.atomic(): user = User.objects.create_user(username="abc", password="pass")
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ecff11bd-9d35-4130-9d3a-0d48f70af73f%40googlegroups.com.
I don't think the subclass of TestCase need to use transaction.atomic. Why can't you just remove the transaction.atomic?
Pada tanggal Sel, 12 Mei 2020 04.02, Uri Kogan <urk...@gmail.com> menulis:
--Hello,I am using TestCase and trying to create an object during test.There is a log activated on MySQL server, so I see all the queries being executed there.This "transaction.atomic" sets a SAVEPOINT in the database thinking that the transaction is already started. The problem is that there is no "TRANSACTION START". So, when exiting "with transaction.atomic()" block the whole thing crashes with "SAVEPOINT xxx DOES NOT EXIST"The following states that TestCase "tests within two nested atomic() blocks", so it should execute "TRANSACTION START"
from django.contrib.auth.models import Userfrom django.test import TestCaseclass FooTest(TestCase):def test_bar(self):with transaction.atomic():user = User.objects.create_user(username="abc", password="pass")
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3741328a-941b-4864-a20d-5e2d9c4937d5%40googlegroups.com.
from django.contrib.auth.models import Userfrom django.test import TestCase
from rolepermissions.roles import assign_role
class FooTest(TestCase): def test_bar(self): u = User.objects.create_user(username="abc", password="pass") assign_role(u, "role_admin")
retrieve_and_analyze_view_using_u_credentials()
I am testing that my permission routines work by creating a user, assigning permissions to the user, retrieving the view and analyzing it. That "assign_role" call of django-role-permissions uses "transaction.atomic". Which, of course, I would not want to change, as this is an external library.To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3741328a-941b-4864-a20d-5e2d9c4937d5%40googlegroups.com.
TestCase
class. For instance, you cannot test that a block of code is executing within a transaction, as is required when using select_for_update()
. In those cases, you should use TransactionTestCase
.To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/91984522-1535-4f37-8fb8-ae76c7095298%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/91984522-1535-4f37-8fb8-ae76c7095298%40googlegroups.com.
from django.contrib.auth.models import Userfrom django.test import TransactionTestCasefrom django.db import transaction
class FooTest(TransactionTestCase): def test_bar(self): with transaction.atomic(): with transaction.atomic():
u = User.objects.create_user(username="abc", password="pass")
print("created user: {}".format(u.username))