From 2019b398f164aa3f7edb8af439c92f1a32d2e920 Mon Sep 17 00:00:00 2001 From: JocelynDelalande Date: Sun, 7 Jan 2018 00:27:42 +0100 Subject: manage commands testing (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rename manage.ConfigTemplate → manage.GenerateConfig To be consistent with the CLI name: `generate-config`. * Add tests for manage.py commands * Run tests from pip-installed package To be able to detect packaging-related issues on test runs. refs #305 --- ihatemoney/tests/tests.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ihatemoney/tests') diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py index de53c58..d4b6d7a 100644 --- a/ihatemoney/tests/tests.py +++ b/ihatemoney/tests/tests.py @@ -4,6 +4,10 @@ try: import unittest2 as unittest except ImportError: import unittest # NOQA +try: + from unittest.mock import patch +except ImportError: + from mock import patch import os import json @@ -16,6 +20,7 @@ from flask import session from flask_testing import TestCase from ihatemoney.run import create_app, db, load_configuration +from ihatemoney.manage import GenerateConfig, GeneratePasswordHash from ihatemoney import models from ihatemoney import utils @@ -1406,5 +1411,27 @@ class ServerTestCase(IhatemoneyTestCase): self.assertStatus(200, req) +class CommandTestCase(BaseTestCase): + def test_generate_config(self): + """ Simply checks that all config file generation + - raise no exception + - produce something non-empty + """ + cmd = GenerateConfig() + for config_file in cmd.get_options()[0].kwargs['choices']: + with patch('sys.stdout', new=six.StringIO()) as stdout: + cmd.run(config_file) + print(stdout.getvalue()) + self.assertNotEqual(len(stdout.getvalue().strip()), 0) + + def test_generate_password_hash(self): + cmd = GeneratePasswordHash() + with patch('sys.stdout', new=six.StringIO()) as stdout, \ + patch('getpass.getpass', new=lambda prompt: 'secret'): # NOQA + cmd.run() + print(stdout.getvalue()) + self.assertEqual(len(stdout.getvalue().strip()), 187) + + if __name__ == "__main__": unittest.main() -- cgit v1.1