def test_register_and_run_checks(self): calls = [0] registry = CheckRegistry() @registry.register() def f(**kwargs): calls[0] += 1 return [1, 2, 3] errors = registry.run_checks() self.assertEqual(errors, [1, 2, 3]) self.assertEqual(calls[0], 1)
def test_register_run_checks_non_iterable(self): registry = CheckRegistry() @registry.register def return_non_iterable(**kwargs): return Error('Message') msg = ( 'The function %r did not return a list. All functions registered ' 'with the checks registry must return a list.' % return_non_iterable) with self.assertRaisesMessage(TypeError, msg): registry.run_checks()
def test_database_checks_not_run_by_default(self): """ `database` checks are only run when their tag is specified. """ def f1(**kwargs): return [5] registry = CheckRegistry() registry.register(Tags.database)(f1) errors = registry.run_checks() self.assertEqual(errors, []) errors2 = registry.run_checks(tags=[Tags.database]) self.assertEqual(errors2, [5])
def test_register_no_kwargs_error(self): registry = CheckRegistry() msg = 'Check functions must accept keyword arguments (**kwargs).' with self.assertRaisesMessage(TypeError, msg): @registry.register def no_kwargs(app_configs, databases): pass
def test_register_and_run_checks(self): def f(**kwargs): calls[0] += 1 return [1, 2, 3] def f2(**kwargs): return [4, ] def f3(**kwargs): return [5, ] calls = [0] # test register as decorator registry = CheckRegistry() registry.register()(f) registry.register("tag1", "tag2")(f2) registry.register("tag2", deploy=True)(f3) # test register as function registry2 = CheckRegistry() registry2.register(f) registry2.register(f2, "tag1", "tag2") registry2.register(f3, "tag2", deploy=True) # check results errors = registry.run_checks() errors2 = registry2.run_checks() self.assertEqual(errors, errors2) self.assertEqual(sorted(errors), [1, 2, 3, 4]) self.assertEqual(calls[0], 2) errors = registry.run_checks(tags=["tag1"]) errors2 = registry2.run_checks(tags=["tag1"]) self.assertEqual(errors, errors2) self.assertEqual(sorted(errors), [4]) errors = registry.run_checks(tags=["tag1", "tag2"], include_deployment_checks=True) errors2 = registry2.run_checks(tags=["tag1", "tag2"], include_deployment_checks=True) self.assertEqual(errors, errors2) self.assertEqual(sorted(errors), [4, 5])
def test_register_and_run_checks(self): def f(**kwargs): calls[0] += 1 return [1, 2, 3] def f2(**kwargs): return [ 4, ] def f3(**kwargs): return [ 5, ] calls = [0] # test register as decorator registry = CheckRegistry() registry.register()(f) registry.register("tag1", "tag2")(f2) registry.register("tag2", deploy=True)(f3) # test register as function registry2 = CheckRegistry() registry2.register(f) registry2.register(f2, "tag1", "tag2") registry2.register(f3, "tag2", deploy=True) # check results errors = registry.run_checks() errors2 = registry2.run_checks() self.assertEqual(errors, errors2) self.assertEqual(sorted(errors), [1, 2, 3, 4]) self.assertEqual(calls[0], 2) errors = registry.run_checks(tags=["tag1"]) errors2 = registry2.run_checks(tags=["tag1"]) self.assertEqual(errors, errors2) self.assertEqual(sorted(errors), [4]) errors = registry.run_checks(tags=["tag1", "tag2"], include_deployment_checks=True) errors2 = registry2.run_checks(tags=["tag1", "tag2"], include_deployment_checks=True) self.assertEqual(errors, errors2) self.assertEqual(sorted(errors), [4, 5])