def test_activate_fail(self): user = UserFactory(is_active=True) count = self._get_users().inactive().activate(self.admin_user_id) self.assertEqual(count, 0) user.refresh_from_db() self.assertTrue(user.is_active) logs_count = self._get_logs_count() self.assertEqual(logs_count, 0)
def test_deactivate_success(self): user = UserFactory(is_active=True) count = self._get_users().active().deactivate(self.admin_user_id) self.assertEqual(count, 1) user.refresh_from_db() self.assertFalse(user.is_active) logs_count = self._get_logs_count() self.assertEqual(logs_count, 1)
def test_simple_multiple(self): UserFactory(is_active=False) UserFactory(is_active=False) UserFactory(is_active=True) active_users = User.objects.all().active() inactive_users = User.objects.all().inactive() self.assertEqual(inactive_users.count(), 2) self.assertEqual(active_users.count(), 1)
def test_activate_fail_2(self): user = UserFactory(is_active=True) count = self._get_users().active().activate(self.admin_user_id) self.assertEqual( count, 1, "activate method must not care about incorrectly filtered queryset", ) user.refresh_from_db() self.assertTrue(user.is_active) logs_count = self._get_logs_count() self.assertEqual(logs_count, 1)
def test_simple_active(self): user = UserFactory(is_active=True) active_users = User.objects.all().active() inactive_users = User.objects.all().inactive() self.assertEqual(inactive_users.count(), 0) self.assertEqual(active_users.count(), 1) self.assertEqual(active_users.first().id, user.id)
def test_simple(self): user = UserFactory(first_name="Anna", last_name="Weekend") self.assertEqual(user.full_name, "Anna Weekend")
def test_empty_last_name(self): user = UserFactory(last_name="") self.assertEqual(user.full_name, user.first_name)
def test_empty_first_and_last_names(self): user = UserFactory(first_name="", last_name="") self.assertEqual(user.full_name, User.DEFAULT_FULL_NAME)
def setUpClass(cls): super().setUpClass() cls.admin_user = UserFactory() cls.admin_user_id = cls.admin_user.id