Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created July 16, 2019 18:18
Show Gist options
  • Select an option

  • Save rg3915/b812ed1392df3167d1887da38b140dd6 to your computer and use it in GitHub Desktop.

Select an option

Save rg3915/b812ed1392df3167d1887da38b140dd6 to your computer and use it in GitHub Desktop.
TDD test if object exists Django tdd
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