def test_yes_yes_answer(self): self.assertNotEqual( BudgetMonthlyFigure.objects.filter( financial_year=self.current_year).count(), 0, ) self.assertNotEqual( ForecastMonthlyFigure.objects.filter( financial_year=self.current_year).count(), 0, ) self.assertNotEqual(FinancialCode.objects.all().count(), 0) with captured_stdin() as stdin: stdin.write("y\n") stdin.write("y") stdin.seek(0) call_command("clear_forecast") self.assertEqual( BudgetMonthlyFigure.objects.filter( financial_year=self.current_year).count(), 0, ) self.assertEqual( ForecastMonthlyFigure.objects.filter( financial_year=self.current_year).count(), 0, ) self.assertEqual(FinancialCode.objects.all().count(), 0)
def test_wet_run(self): stdout = StringIO() with captured_stdin() as stdin: stdin.write('Y\n') stdin.seek(0) call_command( 'sendbulkemail', '--recipients=staff', '--template=staff-test', '--subject=This is a test', stdout=stdout, ) self.assertIn('About to send the email to 2 recipient(s)', stdout.getvalue()) self.assertIn('Sending 2 email(s)', stdout.getvalue()) self.assertEqual(len(mail.outbox), 2) email = mail.outbox[0] self.assertEqual(email.to, ['*****@*****.**']) self.assertEqual(email.from_email, 'PyCon UK 2017 <*****@*****.**>') self.assertEqual(email.subject, f'This is a test | {self.alice.user_id}') self.assertIn('Hi Alice', email.body)
def test_user_no_answer(self): self.checks_before_command() self.create_user(True) with captured_stdin() as stdin: stdin.write("n\n") stdin.seek(0) with self.assertRaises(CommandError): call_command("new_financial_year", "--useremail", f"{self.user_email}") # Check that nothing has changed self.check_after_failed_command()
def test_user_yes_answer(self): self.checks_before_command() self.create_user(True) with captured_stdin() as stdin: stdin.write("y\n") stdin.seek(0) call_command("new_financial_year", "--useremail", f"{self.user_email}") self.assertEqual( BudgetMonthlyFigure.objects.filter( financial_year=self.current_year ).count(), 0, )
def test_stdin_read(self, select): with captured_stdin() as stdin, captured_stdout() as stdout: stdin.write('print(100)\n') stdin.seek(0) call_command('shell') self.assertEqual(stdout.getvalue().strip(), '100')
def test_stdin_read_inline_function_call(self, select): with captured_stdin() as stdin, captured_stdout() as stdout: stdin.write(self.script_with_inline_function) stdin.seek(0) call_command('shell') self.assertEqual(stdout.getvalue().strip(), __version__)
def test_stdin_read_globals(self, select): with captured_stdin() as stdin, captured_stdout() as stdout: stdin.write(self.script_globals) stdin.seek(0) call_command('shell') self.assertEqual(stdout.getvalue().strip(), 'True')
def test_make_password(self): with captured_stdin() as stdin, captured_stdout() as stdout: stdin.write('password123') stdin.seek(0) call_command('make_password') self.assertIn('Hashed password: pbkdf2_sha256$', stdout.getvalue())