def test_cli_usage(): # Test the -h with pytest.raises(SystemExit) as excinfo: cli.main("-h") assert excinfo.code == 0 with pytest.raises(SystemExit) as excinfo: cli.main("--version") assert excinfo.code == 0
def facility_sync(syncserver, syncfacilityid): pid = os.fork() if pid == 0: main([ "manage", "sync", "--baseurl", syncserver, "--facility", syncfacilityid, "--verbosity", "3" ]) else: os.waitpid(pid, 0)
def start_django(): # remove this after Kolibri no longer needs it if sys.version[0] == "2": reload(sys) sys.setdefaultencoding("utf8") logging.info("Starting server...") from kolibri.utils.cli import main main(["start", "--foreground", "--port=5000"])
def test_do_rollover(self): archive_dir = os.path.join(os.environ["KOLIBRI_HOME"], "logs", "archive") orig_value = settings.LOGGING["handlers"]["file"]["when"] # Temporarily set the rotation time of the log file to be every second settings.LOGGING["handlers"]["file"]["when"] = "s" # make sure that kolibri will be running for more than one second cli.main(["--skipupdate", "manage", "help"]) sleep(1) cli.main(["--skipupdate", "manage", "help"]) # change back to the original rotation time settings.LOGGING["handlers"]["file"]["when"] = orig_value self.assertNotEqual(os.listdir(archive_dir), [])
def test_content_dir_not_writable(self, access_mock, logging_mock): with self.assertRaises(SystemExit): cli.main(["start"]) logging_mock.assert_called()
def test_old_log_file_exists(self, path_exists_mock, move_mock, initialize_mock): cli.main(["language", "setdefault", "en"]) # Check if the number of calls to shutil.move equals to the number of times # os.path.exists returns True self.assertEqual(move_mock.call_count, 2)
def test_port_occupied(self, status_mock, portend_mock, logging_mock): status_mock.side_effect = NotRunning("Kolibri not running") portend_mock.side_effect = portend.Timeout with self.assertRaises(SystemExit): cli.main(["start"]) logging_mock.assert_called()
def test_content_dir_dne(self, logging_mock, version_file=None, orig_version=None): version_file = cli.version_file() open(version_file, "w").write(orig_version) with self.assertRaises(SystemExit): cli.main(["start"]) logging_mock.assert_called()
from __future__ import absolute_import, print_function, unicode_literals import sys if __name__ == "__main__": from kolibri.utils.cli import main main(args=sys.argv[1:])
def test_other_kolibri_running(self, status_mock, logging_mock): with self.assertRaises(SystemExit): cli.main(["start"]) logging_mock.assert_called()
def test_plugin_cli(self): main(("plugin", "kolibri.plugins.example_plugin", "enable")) main(("plugin", "kolibri.plugins.example_plugin", "disable"))
def test_port_occupied(self, status_mock, socket_mock, logging_mock): status_mock.side_effect = NotRunning('Kolibri not running') socket_mock.return_value.bind.side_effect = socket.error with self.assertRaises(SystemExit): cli.main({'start': True}) logging_mock.assert_called()
def test_content_dir_dne(self, path_mock, logging_mock): with self.assertRaises(SystemExit): cli.main({'start': True}) logging_mock.assert_called()
def test_cli(self): logger.debug("This is a unit test in the main Kolibri app space") # Test the -h with self.assertRaises(SystemExit): main("-h")
def test_content_dir_writable(self, path_exists_mock, access_mock, logging_mock): with self.assertRaises(SystemExit): cli.main({'start': True}) logging_mock.assert_called
def test_cli_usage(): # Test the -h with pytest.raises(SystemExit, code=0): cli.main("-h") with pytest.raises(SystemExit, code=0): cli.main("--version")
def test_content_dir_dne(self, logging_mock, get_version): with self.assertRaises(SystemExit): cli.main(["manage"]) logging_mock.assert_called()
from __future__ import absolute_import from __future__ import print_function from __future__ import unicode_literals import sys if __name__ == "__main__": from kolibri.utils.cli import main main(args=sys.argv[1:])