From f9f6ea5e884115cab89d6a46294e26786d40b986 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sat, 11 Nov 2017 17:25:28 -0500 Subject: [PATCH] Add management command tests. --- babybuddy/management/commands/reset.py | 2 +- babybuddy/tests/tests_commands.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 babybuddy/tests/tests_commands.py diff --git a/babybuddy/management/commands/reset.py b/babybuddy/management/commands/reset.py index 7c563540..3055fb08 100644 --- a/babybuddy/management/commands/reset.py +++ b/babybuddy/management/commands/reset.py @@ -58,7 +58,7 @@ class Command(BaseCommand): 'password': 'admin' } ) - if options['verbosity'] > 0: + if verbosity > 0: self.stdout.write('Superuser created successfully.') fake = Fake() diff --git a/babybuddy/tests/tests_commands.py b/babybuddy/tests/tests_commands.py new file mode 100644 index 00000000..2b83ab97 --- /dev/null +++ b/babybuddy/tests/tests_commands.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase +from django.contrib.auth.models import User +from django.core.management import call_command + +from core.models import Child + + +class CommandsTestCase(TestCase): + def test_migrate(self): + call_command('migrate', verbosity=0) + self.assertIsInstance(User.objects.get(username='admin'), User) + + def test_fake(self): + call_command('migrate', verbosity=0) + call_command('fake', children=1, days=7, verbosity=0) + self.assertEqual(Child.objects.count(), 1) + call_command('fake', children=2, days=7, verbosity=0) + self.assertEqual(Child.objects.count(), 3) + + def test_reset(self): + call_command('reset', verbosity=0, interactive=False) + self.assertIsInstance(User.objects.get(username='admin'), User) + self.assertEqual(Child.objects.count(), 1)