diff options
Diffstat (limited to 'CeibalEncuesta/gtk3/CeibalEncuesta/tests.py')
-rw-r--r-- | CeibalEncuesta/gtk3/CeibalEncuesta/tests.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/CeibalEncuesta/gtk3/CeibalEncuesta/tests.py b/CeibalEncuesta/gtk3/CeibalEncuesta/tests.py new file mode 100644 index 0000000..c804742 --- /dev/null +++ b/CeibalEncuesta/gtk3/CeibalEncuesta/tests.py @@ -0,0 +1,75 @@ +import unittest +import os +import shutil +import glob + +from CeibalEncuesta import CeibalEncuesta + +WORKPATH = 'test_files' +TEMPPATH = os.path.join(WORKPATH, "fixture_enc_simple.encuesta") + + +class MockDialog(object): + + def run(self): + pass + + def destroy(self): + pass + + +class MockPanel(object): + + def __init__(self): + self.encuestados = 'dadsa' + self.encuesta = 'blah' + + +class MockInfoWidget(object): + + def get_info(self): + return {'poll_name': 'test_poll'} + + +class MockCeibalEncuesta(CeibalEncuesta): + + def __init__(self, fixture): + self.panel = MockPanel() + self.infowidget = MockInfoWidget() + self._CeibalEncuesta__save_json = self._save_json + self.path = TEMPPATH + self.backup_path = os.path.join(WORKPATH, fixture) + + def _save_json(self, path=None): + return '' + + def _alert_dialog(self, parent_window, label): + return MockDialog() + + +class NoBorraTempAlExportarTest(unittest.TestCase): + """Este test hace referencia al issue #4143""" + + def setUp(self): + self.fixture_tmp = 'fixture_tmp.encuesta' + + def test_exporta_y_no_borra_temp(self): + fixture = 'fixture_enc_simple.encuesta' + fixture_tmp_full = WORKPATH + '/' + self.fixture_tmp + shutil.copy2(WORKPATH + '/' + fixture, fixture_tmp_full) + + ce = MockCeibalEncuesta(self.fixture_tmp) + ce._CeibalEncuesta__save_results(widget=None, chosen_path=WORKPATH) + + self.assertTrue(os.path.exists(fixture_tmp_full)) + + def tearDown(self): + for f in glob.glob(WORKPATH + '/' + '*.poll_result'): + os.remove(f) + + if os.path.exists(WORKPATH + '/' + self.fixture_tmp): + os.remove(WORKPATH + '/' + self.fixture_tmp) + + +if __name__ == '__main__': + unittest.main() |