def setUp(self): call_command_with_output("initdevice", "MyCentralDevice", "") self.zone = Zone.objects.create(name="MyZone") key = crypto.Key() self.remote_device = Device.objects.create(name="RemoteDevice", public_key=key.get_public_key_string()) self.remote_device.key = key self.device_zone = DeviceZone.objects.create(zone=self.zone, device=self.remote_device) self.facility = Facility.objects.create(name="MyFacility") self.facility.sign(device=self.remote_device) self.facility.save(imported=True)
def setUp(self): call_command_with_output("initdevice", "MyCentralDevice", "") self.zone = Zone.objects.create(name="MyZone") key = crypto.Key() self.remote_device = Device.objects.create( name="RemoteDevice", public_key=key.get_public_key_string()) self.remote_device.key = key self.device_zone = DeviceZone.objects.create(zone=self.zone, device=self.remote_device) self.facility = Facility.objects.create(name="MyFacility") self.facility.sign(device=self.remote_device) self.facility.save(imported=True)
def test_no_options(self): try: (out, err, rc) = call_command_with_output('readmodel', 'some.model') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "Please specify --id to fetch model.")
def test_no_options(self): try: (out, err, rc) = call_command_with_output('createmodel', 'some.model') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "Please specify input data as a json string")
def test_no_args(self): try: (out, err, rc) = call_command_with_output('readmodel') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "Please specify model class name.")
def test_no_options(self): try: (out, err, rc) = call_command_with_output('readmodel', 'some.model') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "Please specify --id to fetch model.")
def test_no_options(self): try: (out, err, rc) = call_command_with_output('createmodel', 'some.model') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "Please specify input data as a json string")
def compile_po_files(lang_codes=None, failure_ok=True): """ Compile all po files in locale directory. First argument (lang_codes) can be None (means all), a list/tuple, or even a string (shh...) """ # before running compilemessages, ensure in correct directory change_dir_to_project_root() if not lang_codes or len(lang_codes) > 1: (out, err, rc) = call_command_with_output('compilemessages') else: lang_code = lang_codes if isinstance(lang_codes, basestring) else lang_codes[0] (out, err, rc) = call_command_with_output('compilemessages', locale=lcode_to_django_dir(lang_code)) if err and not failure_ok: raise CommandError("Failure compiling po files: %s" % err) return out, err, rc
def test_save_model(self): MODEL_NAME = "kalite.facility.models.Facility" (out, err, rc) = call_command_with_output("createmodel", MODEL_NAME, json_data='{"name" : "kir1"}') self.assertEquals(rc, 0) module_path, model_name = MODEL_NAME.rsplit(".", 1) module = importlib.import_module(module_path) model = getattr(module, model_name) data = model.objects.get(pk=out.strip()) self.assertEquals(data.name, "kir1")
def test_fetch_model(self): MODEL_NAME = "kalite.facility.models.Facility" facility_name = "kir1" # Create a Facility object first that will be fetched. facility = Facility(name=facility_name) facility.save() (out, err, rc) = call_command_with_output("readmodel", MODEL_NAME, id=facility.id) data_map = json.loads(out) self.assertEquals(data_map["name"], facility_name)
def compile_po_files(lang_codes=None, failure_ok=True): """ Compile all po files in locale directory. First argument (lang_codes) can be None (means all), a list/tuple, or even a string (shh...) """ # before running compilemessages, ensure in correct directory logging.debug("Moving to project root directory") os.chdir(PROJECT_ROOT) if not lang_codes or len(lang_codes) > 1: (out, err, rc) = call_command_with_output('compilemessages') else: lang_code = lang_codes if isinstance(lang_codes, basestring) else lang_codes[0] (out, err, rc) = call_command_with_output('compilemessages', locale=lcode_to_django_dir(lang_code)) if err and not failure_ok: raise CommandError("Failure compiling po files: %s" % err) return out, err, rc
def test_fetch_model(self): MODEL_NAME = 'kalite.facility.models.Facility' facility_name = 'kir1' # Create a Facility object first that will be fetched. facility = Facility(name=facility_name) facility.save() (out, err, rc) = call_command_with_output('readmodel', MODEL_NAME, id=facility.id) data_map = json.loads(out) self.assertEquals(data_map['name'], facility_name)
def test_save_model(self): MODEL_NAME = 'kalite.facility.models.Facility' (out, err, rc) = call_command_with_output('createmodel', MODEL_NAME, json_data='{"name" : "kir1"}') self.assertEquals(rc, 0) module_path, model_name = MODEL_NAME.rsplit(".", 1) module = importlib.import_module(module_path) model = getattr(module, model_name) data = model.objects.get(pk=out.strip()) self.assertEquals(data.name, "kir1")
def test_change_password_on_existing_user(self): """Change the password on an existing user.""" # Now, re-retrieve the user, to check. (out,err,val) = call_command_with_output("changelocalpassword", self.user.username, noinput=True) self.assertEqual(err, "", "no output on stderr") self.assertNotEqual(out, "", "some output on stdout") self.assertEqual(val, 0, "Exit code is not zero") new_password = re.search(r"Generated new password for user .*: '(?P<password>.*)'", out).group('password') self.assertNotEqual(self.old_password, new_password) c = KALiteClient() success = c.login(username=self.user.username, password=new_password, facility=self.facility.id) self.assertTrue(success, "Was not able to login as the test user")
def test_no_args(self): try: (out, err, rc) = call_command_with_output('createmodel') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "No args specified")
def test_no_args(self): try: (out, err, rc) = call_command_with_output('readmodel') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "Please specify model class name.")
def test_no_args(self): try: (out, err, rc) = call_command_with_output('createmodel') self.assertFail() except CommandError as e: self.assertRegexpMatches(str(e), "No args specified")
def test_change_password_on_nonexistent_user(self): nonexistent_username = "******" with self.assertRaises(CommandError): (out, err, val) = call_command_with_output("changelocalpassword", nonexistent_username, noinput=True)