Ejemplo n.º 1
0
class TestSystem(unittest.TestCase):
    def setUp(self):
        self.authorizer = AuthorizerFake()
        self.system = System(self.authorizer)
        ...

    def test_schedule_appointment_for_bob(self):
        self.system.schedule_appointment(self.request)
        ...
Ejemplo n.º 2
0
 def setUp(self):
     ...
     self.system = System(authorizer=None)
     ...
     self.system = System(authorizer=object())
     ...
     from unittest.mock import sentinel
     self.system = System(authorizer=sentinel.authorizer)
     ...
Ejemplo n.º 3
0
class TestSystem2(unittest.TestCase):
    def setUp(self):
        self.authorizer = Mock(return_value=True)
        self.system = System(self.authorizer)
        self.request = Mock(username='******', password='******')

    def test_successful_schedule_appointment(self):
        self.system.schedule_appointment(self.request)
        self.assertTrue(self.authorizer.authorize.called)
        ...
Ejemplo n.º 4
0
class TestSystem(unittest.TestCase):
    def setUp(self):
        self.authorizer = AuthorizerSpy()
        self.system = System(self.authorizer)
        ...

    def test_schedule_appointment(self):
        self.system.schedule_appointment(self.request)
        self.assertTrue(self.authorizer.authorized_was_called)
        ...
Ejemplo n.º 5
0
class TestSystem(unittest.TestCase):
    def setUp(self):
        self.authorizer = Mock()
        self.system = System(self.authorizer)
        self.request = ...

    def test_schedule_appointment(self):
        self.authorizer.configure_mock(...)
        self.system.schedule_appointment(self.request)
        ...
Ejemplo n.º 6
0
class TestSystem2(unittest.TestCase):
    def setUp(self):
        self.authorizer = Mock()
        self.system = System(self.authorizer)
        self.request = Mock(username='******', password='******')

    def test_schedule_appointment_for_bob(self):
        self.authorizer.side_effect = \
            lambda username, password: username == 'Bob'
        self.system.schedule_appointment(self.request)
        ...
Ejemplo n.º 7
0
def webhook():
    system = System()
    try:
        text = request.data.decode('utf8')
        data = json.loads(text)
        system.main(data)
    except Exception:
        system.log(traceback.format_exc())

    return 'OK'
Ejemplo n.º 8
0
 def setUp(self):
     self.authorizer = Mock(return_value=True)
     self.system = System(self.authorizer)
     self.request = Mock(username='******', password='******')
Ejemplo n.º 9
0
 def setUp(self):
     self.authorizer = AuthorizerSpy()
     self.system = System(self.authorizer)
     ...
Ejemplo n.º 10
0
]

tst_file = NamedTemporaryFile()
trn_file = NamedTemporaryFile()

with open(tst_file.name, "w") as file:
    file.writelines([
        "2 4 2 1 4 \n",
        "1 2 1 1 2 \n",
        "9 7 10 7 4 \n",
        "4 4 10 10 2 \n",
    ])

with open(trn_file.name, "w") as file:
    file.writelines([
        "1 3 1 1 2 \n",
        "10 3 2 1 2 \n",
        "2 3 1 1 2 \n",
        "10 9 7 1 4 \n",
        "3 5 2 2 4 \n",
        "2 3 1 1 4 \n",
    ])

tst = System("tst", tst_file.name)
trn = System("trn", trn_file.name)

classifier = NaiveBayesClassifier(tst, trn)
classifier.compute()

print(tst.decision_classes)
print(trn.decision_classes)
Ejemplo n.º 11
0
 def setUp(self):
     self.authorizer = Mock()
     self.system = System(self.authorizer)
     self.request = ...