Created
December 2, 2015 14:32
-
-
Save nonZero/473b8c3e394d442d4a7c to your computer and use it in GitHub Desktop.
m2m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import transaction | |
from django.test import TestCase | |
from users.models import User | |
from . import models | |
class MyTestCase(TestCase): | |
def test_create_expense(self): | |
user = User.objects.create(email="[email protected]") | |
tags = [ | |
models.Tag.objects.create(title="tag #{}".format(i+1)) for i in range(10) | |
] | |
with transaction.atomic(): | |
expense = models.Expense.objects.create( | |
user=user, | |
amount=3, | |
details="ASdasda" | |
) | |
expense.tags = tags[2:6] | |
expense.tags.add(tags[8]) | |
expense.tags.clear() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment