From 5442d3416cd0d12854f24bd700949b443efda17a Mon Sep 17 00:00:00 2001 From: Andy Chosak Date: Mon, 7 Nov 2016 14:23:38 -0500 Subject: [PATCH] test fixes, hide verbose test output --- paying_for_college/tests/test_commands.py | 4 ++++ paying_for_college/tests/test_load_programs.py | 7 +++++++ paying_for_college/tests/test_models.py | 8 +++++--- paying_for_college/tests/test_scripts.py | 10 +++++++++- paying_for_college/tests/test_search_index.py | 16 ++++++++-------- paying_for_college/tests/test_views.py | 4 ++-- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/paying_for_college/tests/test_commands.py b/paying_for_college/tests/test_commands.py index a4bc65d..d3a4766 100644 --- a/paying_for_college/tests/test_commands.py +++ b/paying_for_college/tests/test_commands.py @@ -6,6 +6,10 @@ class CommandTests(unittest.TestCase): + def setUp(self): + stdout_patch = mock.patch('sys.stdout') + stdout_patch.start() + self.addCleanup(stdout_patch.stop) @mock.patch('paying_for_college.management.commands.' 'update_pfc_national_stats.nat_stats.' diff --git a/paying_for_college/tests/test_load_programs.py b/paying_for_college/tests/test_load_programs.py index 7f3933e..4840dda 100644 --- a/paying_for_college/tests/test_load_programs.py +++ b/paying_for_college/tests/test_load_programs.py @@ -89,6 +89,13 @@ class TestLoadPrograms(django.test.TestCase): u'completers': 'NUMBER', u'completion_cohort': 'NUMBER'} + def setUp(self): + print_patch = mock.patch( + 'paying_for_college.disclosures.scripts.load_programs.print' + ) + print_patch.start() + self.addCleanup(print_patch.stop) + def test_standardize_rate(self): self.assertTrue(standardize_rate(u'1.7') == u'0.017') self.assertTrue(standardize_rate(u'0.017') == u'0.017') diff --git a/paying_for_college/tests/test_models.py b/paying_for_college/tests/test_models.py index 7b1e624..c274c81 100644 --- a/paying_for_college/tests/test_models.py +++ b/paying_for_college/tests/test_models.py @@ -121,9 +121,11 @@ def test_school_related_models(self): noti = self.create_notification(s) self.assertTrue(isinstance(noti, Notification)) self.assertTrue(noti.oid in noti.__unicode__()) - self.assertTrue(print_vals(s) is None) - self.assertTrue("Emerald City" in print_vals(s, val_list=True)) - self.assertTrue("Emerald City" in print_vals(s, val_dict=True)['city']) + self.assertIsInstance(print_vals(s, noprint=True), basestring) + self.assertTrue( + 'Emerald City' in print_vals(s, val_list=True, noprint=True) + ) + self.assertTrue("Emerald City" in print_vals(s, val_dict=True, noprint=True)['city']) self.assertTrue("Emerald City" in print_vals(s, noprint=True)) self.assertTrue(s.convert_ope6() == '005555') self.assertTrue(s.convert_ope8() == '00555500') diff --git a/paying_for_college/tests/test_scripts.py b/paying_for_college/tests/test_scripts.py index 974c827..01ee70e 100644 --- a/paying_for_college/tests/test_scripts.py +++ b/paying_for_college/tests/test_scripts.py @@ -3,6 +3,7 @@ import json import datetime import string +import os import mock from mock import mock_open, patch @@ -20,7 +21,7 @@ OID, ERRORS) from django.conf import settings -PFC_ROOT = settings.REPOSITORY_ROOT +PFC_ROOT = os.path.join(os.path.dirname(__file__), '../..') YEAR = api_utils.LATEST_YEAR MOCK_YAML = """\ completion_rate:\n\ @@ -146,6 +147,13 @@ class TestScripts(django.test.TestCase): 'metadata': {'page': 0} } + def setUp(self): + for method in ('print', 'sys.stdout'): + base = 'paying_for_college.disclosures.scripts.update_colleges.' + patcher = patch(base + method) + patcher.start() + self.addCleanup(patcher.stop) + def test_icomma(self): icomma_test = update_ipeds.icomma(445999) self.assertTrue(icomma_test == '445,999') diff --git a/paying_for_college/tests/test_search_index.py b/paying_for_college/tests/test_search_index.py index 423b80d..a739350 100644 --- a/paying_for_college/tests/test_search_index.py +++ b/paying_for_college/tests/test_search_index.py @@ -1,21 +1,21 @@ #!/usr/bin/env python # -*- coding: utf8 -*- -import json +from paying_for_college.models import School +from paying_for_college.search_indexes import SchoolIndex from django.test import TestCase -from paying_for_college.search_indexes import SchoolIndex -from paying_for_college.models import School class SchoolIndexTest(TestCase): - - fixtures = ['paying_for_college/fixtures/test_fixture.json'] + fixtures = ['test_fixture.json'] MOCK_INDEX = SchoolIndex() - mock_obj = School.objects.get(pk=155317) def test_index(self): self.assertTrue(self.MOCK_INDEX.get_model() == School) self.assertTrue(self.MOCK_INDEX.index_queryset().count() == School.objects.count()) - self.assertTrue('Jayhawks' in - self.MOCK_INDEX.prepare_autocomplete(self.mock_obj)) + + mock_obj = School.objects.get(pk=155317) + self.assertTrue( + 'Jayhawks' in self.MOCK_INDEX.prepare_autocomplete(mock_obj) + ) diff --git a/paying_for_college/tests/test_views.py b/paying_for_college/tests/test_views.py index 9f16c5e..700f80a 100644 --- a/paying_for_college/tests/test_views.py +++ b/paying_for_college/tests/test_views.py @@ -21,6 +21,7 @@ Feedback, EmailLink, SchoolRepresentation, + STANDALONE, school_search_api) client = Client() @@ -104,6 +105,7 @@ def test_get_program_length(self): # response = client.get(reverse(url_name)) # self.assertTrue('base_template' in response.context_data.keys()) + @unittest.skipIf(not STANDALONE, 'not running as standalone project') def test_standalone_landing_views(self): for url_name in self.standalone_landing_page_views: response = client.get(reverse(url_name)) @@ -383,9 +385,7 @@ def test_verify_view_school_has_no_contact(self): post_data = copy.copy(self.post_data) post_data['iped'] = '408039' post_data['oid'] = 'f38283b5b7c939a058889f997949efa566c616c4' - print("\n\n\n***SCHOOL is {}\nSCHOOL CONTACT IS {}\n".format(School.objects.get(pk=408039), School.objects.get(pk=408039).contact)) resp = client.post(self.url, data=post_data) - print("RESPONSE is {}\n***\n\n\n".format(resp.content)) self.assertTrue(resp.status_code == 400) def test_verify_view_bad_id(self):