def compile_po_files(lang_code="all", failure_ok=True): """Compile all po files in locale directory""" # before running compilemessages, ensure in correct directory move_to_project_root() if not lang_code or lang_code == "all": (out, err, rc) = call_command_with_output('compilemessages') else: (out, err, rc) = call_command_with_output('compilemessages', locale=lang_code) if err and not failure_ok: raise CommandError("Failure compiling po files: %s" % err) return out, err, rc
def compile_po_files(lang_code="all", failure_ok=True): """Compile all po files in locale directory""" # before running compilemessages, ensure in correct directory move_to_project_root() if not lang_code or lang_code == "all": (out, err, rc) = call_command_with_output('compilemessages') else: (out, err, rc) = call_command_with_output('compilemessages', locale=lang_code) if err and not failure_ok: raise CommandError("Failure compiling po files: %s" % err) return out, err, rc
def test_change_password_on_nonexistent_user(self): nonexistent_username = "******" (out, err, val) = call_command_with_output("changelocalpassword", nonexistent_username, noinput=True) self.assertEqual(out, '', "Expected no stdout; stdout is {}".format(out)) self.assertNotEqual(err, '', "Expected nonempty stderr") self.assertNotEqual(val, 0, 'Expected return code to be nonzero') self.browser_login_student(self.user.username, self.old_password) self.assertTrue(self.browser_is_logged_in(), "student's password was changed!")
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_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) self.browser_login_student(self.user.username, new_password) self.assertTrue(self.browser_is_logged_in(), "student's password did not change")
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_change_password_on_nonexistent_user(self): nonexistent_username = "******" (out, err, val) = call_command_with_output("changelocalpassword", nonexistent_username, noinput=True) self.assertEqual(out, '', "Expected no stdout; stdout is {}".format(out)) self.assertNotEqual(err, '', "Expected nonempty stderr") self.assertNotEqual(val, 0, 'Expected return code to be nonzero') self.browser_login_student(self.user.username, self.old_password) self.assertTrue(self.browser_is_logged_in(), "student's password was changed!")
def test_no_user(self): fake_username = self.user.username + "xxxxx" #with self.assertRaises(FacilityUser.DoesNotExist): (out,err,val) = call_command_with_output("changelocalpassword", fake_username, noinput=True) self.assertNotIn("Generated new password for user", out, "Did not set password") self.assertNotEquals(err, "", "some output on stderr") match = re.match(r"^.*Error: user '([^']+)' does not exist$", err.replace("\n",""), re.M) self.assertFalse(match is None, "could not parse stderr") self.assertEquals(match.groups()[0], fake_username, "Verify printed fake username") self.assertNotEquals(val, 0, "Verify exit code is non-zero")
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_change_password(self): # Now, re-retrieve the user, to check. (out,err,val) = call_command_with_output("changelocalpassword", self.user.username, noinput=True) self.assertEquals(err, "", "no output on stderr") self.assertNotEquals(out, "", "some output on stderr") self.assertEquals(val, 0, "Exit code is zero") match = re.match(r"^.*Generated new password for user '([^']+)': '([^']+)'", out.replace("\n",""), re.MULTILINE) self.assertFalse(match is None, "could not parse stdout") user = FacilityUser.objects.get(facility=self.facility, username=self.user.username) self.assertEquals(user.username, match.groups()[0], "Username reported correctly") self.assertTrue(user.check_password(match.groups()[1]), "New password works") self.assertFalse(user.check_password(self.user.clear_text_password), "NOT the old password")
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) self.browser_login_student(self.user.username, new_password) self.assertTrue(self.browser_is_logged_in(), "student's password did not change")
def test_no_user(self): fake_username = self.user.username + "xxxxx" #with self.assertRaises(FacilityUser.DoesNotExist): (out, err, val) = call_command_with_output("changelocalpassword", fake_username, noinput=True) self.assertNotIn("Generated new password for user", out, "Did not set password") self.assertNotEquals(err, "", "some output on stderr") match = re.match(r"^.*Error: user '([^']+)' does not exist$", err.replace("\n", ""), re.M) self.assertFalse(match is None, "could not parse stderr") self.assertEquals(match.groups()[0], fake_username, "Verify printed fake username") self.assertNotEquals(val, 0, "Verify exit code is non-zero")
def test_change_password(self): # Now, re-retrieve the user, to check. (out, err, val) = call_command_with_output("changelocalpassword", self.user.username, noinput=True) self.assertEquals(err, "", "no output on stderr") self.assertNotEquals(out, "", "some output on stderr") self.assertEquals(val, 0, "Exit code is zero") match = re.match( r"^.*Generated new password for user '([^']+)': '([^']+)'", out.replace("\n", ""), re.MULTILINE) self.assertFalse(match is None, "could not parse stdout") user = FacilityUser.objects.get(facility=self.facility, username=self.user.username) self.assertEquals(user.username, match.groups()[0], "Username reported correctly") self.assertTrue(user.check_password(match.groups()[1]), "New password works") self.assertFalse(user.check_password(self.user.clear_text_password), "NOT the old password")
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)
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)