Created
July 16, 2019 18:18
-
-
Save rg3915/b812ed1392df3167d1887da38b140dd6 to your computer and use it in GitHub Desktop.
TDD test if object exists Django tdd
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.test import TestCase | |
| from myproject.crm.models import Occupation | |
| class OccupationTest(TestCase): | |
| def setUp(self): | |
| Occupation.objects.create(occupation='Manager') | |
| Occupation.objects.create(occupation='Director') | |
| def test_exists(self): | |
| expected = ['Manager', 'Director'] | |
| occupations = Occupation.objects.filter(occupation__in=expected)\ | |
| .values_list('occupation', flat=True) | |
| self.assertQuerysetEqual( | |
| occupations, expected, transform=str, ordered=False | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment