-
-
Notifications
You must be signed in to change notification settings - Fork 449
/
Copy pathtest_registry.py
51 lines (36 loc) · 1.52 KB
/
test_registry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from django.test import TestCase
from two_factor.plugins.registry import (
GeneratorMethod, MethodBase, MethodNotFoundError, registry,
)
class FakeMethod(MethodBase):
code = 'fake-method'
class RegistryTest(TestCase):
def setUp(self) -> None:
self.old_methods = list(registry._methods)
return super().setUp()
def tearDown(self) -> None:
registry._methods = self.old_methods
return super().tearDown()
def test_register(self):
previous_length = len(registry._methods)
expected_length = previous_length + 1
registry.register(FakeMethod())
self.assertEqual(len(registry._methods), expected_length)
def test_register_twice(self):
previous_length = len(registry._methods)
expected_length = previous_length
registry.register(GeneratorMethod())
self.assertEqual(len(registry._methods), expected_length)
def test_unregister(self):
previous_length = len(registry._methods)
expected_length = previous_length - 1
registry.unregister('generator')
self.assertEqual(len(registry._methods), expected_length)
def test_unregister_non_registered(self):
previous_length = len(registry._methods)
expected_length = previous_length
registry.unregister('fake-method')
self.assertEqual(len(registry._methods), expected_length)
def test_unknown_method(self):
with self.assertRaises(MethodNotFoundError):
registry.get_method("not-existing-method")