def case_resolve_status_not_found(self, refresh_db_before): """ Try to resolve ServerStatus row which name does not exist.""" exception_raised = False try: ServerOp.resolve_status("TestStatus") except ServerStatusNotFoundError: exception_raised = True self.assertTrue(exception_raised)
def test_resolve_status_not_found(self, mock_status_op): """ Assumptions: - ServerStatusOp.get() returns no records """ mock_status_op.get.return_value = list() with self.assertRaisesRegex(ServerStatusNotFoundError, "Not found"): ServerOp.resolve_status("status_name") mock_status_get_calls = [mock.call(name="status_name")] mock_status_op.get.assert_has_calls(mock_status_get_calls)
def case_resolve_status_positive(self, refresh_db_before): """ Create ServerStatus rows, then resolve their names into ID.""" statuses = {"Status_one": 1, "Status_two": 2} for status in statuses.keys(): ServerStatusOp.add(status) for status_name, status_key in statuses.items(): resolved_id = ServerOp.resolve_status(status_name) self.assertEqual(status_key, resolved_id)
def test_resolve_status_positive(self, mock_status_op): """ Assumptions: - ServerStatusOp.get() returns one record """ mock_status = mock.MagicMock() mock_status.id = 1 mock_status_op.get.return_value = [mock_status] status_id = ServerOp.resolve_status("status_name") self.assertEqual(mock_status.id, status_id) mock_status_get_calls = [mock.call(name="status_name")] mock_status_op.get.assert_has_calls(mock_status_get_calls)