Fix many wrong-assert-type errors

This commit is contained in:
Ned Batchelder
2016-07-31 10:47:17 -04:00
parent eef964f5f6
commit 8571ceabeb
51 changed files with 228 additions and 199 deletions

View File

@@ -99,8 +99,8 @@ class IPFilterFormTest(TestCase):
form = IPFilterForm(data=form_data)
self.assertTrue(form.is_valid())
form.save()
self.assertTrue(len(IPFilter.current().whitelist) == 0)
self.assertTrue(len(IPFilter.current().blacklist) == 0)
self.assertEqual(len(IPFilter.current().whitelist), 0)
self.assertEqual(len(IPFilter.current().blacklist), 0)
def test_add_invalid_ips(self):
# test adding invalid ip addresses

View File

@@ -50,7 +50,7 @@ class EmbargoModelsTest(CacheIsolationTestCase):
currently_blocked = EmbargoedState.current().embargoed_countries_list
for state in blocked_states + good_states:
self.assertFalse(state in currently_blocked)
self.assertNotIn(state, currently_blocked)
# Block
cauth = EmbargoedState(embargoed_countries='US, AQ')
@@ -58,9 +58,9 @@ class EmbargoModelsTest(CacheIsolationTestCase):
currently_blocked = EmbargoedState.current().embargoed_countries_list
for state in good_states:
self.assertFalse(state in currently_blocked)
self.assertNotIn(state, currently_blocked)
for state in blocked_states:
self.assertTrue(state in currently_blocked)
self.assertIn(state, currently_blocked)
# Change embargo - block Isle of Man too
blocked_states.append('IM')
@@ -69,25 +69,25 @@ class EmbargoModelsTest(CacheIsolationTestCase):
currently_blocked = EmbargoedState.current().embargoed_countries_list
for state in good_states:
self.assertFalse(state in currently_blocked)
self.assertNotIn(state, currently_blocked)
for state in blocked_states:
self.assertTrue(state in currently_blocked)
self.assertIn(state, currently_blocked)
def test_ip_blocking(self):
whitelist = '127.0.0.1'
blacklist = '18.244.51.3'
cwhitelist = IPFilter.current().whitelist_ips
self.assertFalse(whitelist in cwhitelist)
self.assertNotIn(whitelist, cwhitelist)
cblacklist = IPFilter.current().blacklist_ips
self.assertFalse(blacklist in cblacklist)
self.assertNotIn(blacklist, cblacklist)
IPFilter(whitelist=whitelist, blacklist=blacklist).save()
cwhitelist = IPFilter.current().whitelist_ips
self.assertTrue(whitelist in cwhitelist)
self.assertIn(whitelist, cwhitelist)
cblacklist = IPFilter.current().blacklist_ips
self.assertTrue(blacklist in cblacklist)
self.assertIn(blacklist, cblacklist)
def test_ip_network_blocking(self):
whitelist = '1.0.0.0/24'
@@ -96,14 +96,14 @@ class EmbargoModelsTest(CacheIsolationTestCase):
IPFilter(whitelist=whitelist, blacklist=blacklist).save()
cwhitelist = IPFilter.current().whitelist_ips
self.assertTrue('1.0.0.100' in cwhitelist)
self.assertTrue('1.0.0.10' in cwhitelist)
self.assertFalse('1.0.1.0' in cwhitelist)
self.assertIn('1.0.0.100', cwhitelist)
self.assertIn('1.0.0.10', cwhitelist)
self.assertNotIn('1.0.1.0', cwhitelist)
cblacklist = IPFilter.current().blacklist_ips
self.assertTrue('1.1.0.0' in cblacklist)
self.assertTrue('1.1.0.1' in cblacklist)
self.assertTrue('1.1.1.0' in cblacklist)
self.assertFalse('1.2.0.0' in cblacklist)
self.assertIn('1.1.0.0', cblacklist)
self.assertIn('1.1.0.1', cblacklist)
self.assertIn('1.1.1.0', cblacklist)
self.assertNotIn('1.2.0.0', cblacklist)
class RestrictedCourseTest(CacheIsolationTestCase):

View File

@@ -227,7 +227,7 @@ class SSLClientTest(ModuleStoreTestCase):
# Test that they do signin if they don't have a cert
response = self.client.get(reverse('signin_user'))
self.assertEqual(200, response.status_code)
self.assertTrue('login-and-registration-container' in response.content)
self.assertIn('login-and-registration-container', response.content)
# And get directly logged in otherwise
response = self.client.get(
@@ -348,7 +348,7 @@ class SSLClientTest(ModuleStoreTestCase):
CourseEnrollment.enroll(user, course.id)
course_private_url = '/courses/MITx/999/Robot_Super_Course/courseware'
self.assertFalse(SESSION_KEY in self.client.session)
self.assertNotIn(SESSION_KEY, self.client.session)
response = self.client.get(
course_private_url,
@@ -380,7 +380,7 @@ class SSLClientTest(ModuleStoreTestCase):
CourseStaffRole(course.id).add_users(user)
course_private_url = reverse('course_handler', args=(unicode(course.id),))
self.assertFalse(SESSION_KEY in self.client.session)
self.assertNotIn(SESSION_KEY, self.client.session)
response = self.client.get(
course_private_url,

View File

@@ -46,8 +46,8 @@ class PerformanceTrackingTest(TestCase):
self.assertEqual(logged_value['referer'], '')
self.assertEqual(logged_value['value'], '')
logged_time = dateutil.parser.parse(logged_value['time']).replace(tzinfo=None)
self.assertTrue(pre_time <= logged_time)
self.assertTrue(post_time >= logged_time)
self.assertLessEqual(pre_time, logged_time)
self.assertGreaterEqual(post_time, logged_time)
def test_empty_post(self):
request = self.request_factory.post('/performance')
@@ -66,8 +66,8 @@ class PerformanceTrackingTest(TestCase):
self.assertEqual(logged_value['referer'], '')
self.assertEqual(logged_value['value'], '')
logged_time = dateutil.parser.parse(logged_value['time']).replace(tzinfo=None)
self.assertTrue(pre_time <= logged_time)
self.assertTrue(post_time >= logged_time)
self.assertLessEqual(pre_time, logged_time)
self.assertGreaterEqual(post_time, logged_time)
def test_populated_get(self):
request = self.request_factory.get('/performance',
@@ -97,8 +97,8 @@ class PerformanceTrackingTest(TestCase):
self.assertEqual(logged_value['referer'], 'https://www.edx.org/evilpage')
self.assertEqual(logged_value['value'], '100234')
logged_time = dateutil.parser.parse(logged_value['time']).replace(tzinfo=None)
self.assertTrue(pre_time <= logged_time)
self.assertTrue(post_time >= logged_time)
self.assertLessEqual(pre_time, logged_time)
self.assertGreaterEqual(post_time, logged_time)
def test_populated_post(self):
request = self.request_factory.post('/performance',
@@ -128,5 +128,5 @@ class PerformanceTrackingTest(TestCase):
self.assertEqual(logged_value['referer'], 'https://www.edx.org/evilpage')
self.assertEqual(logged_value['value'], '100234')
logged_time = dateutil.parser.parse(logged_value['time']).replace(tzinfo=None)
self.assertTrue(pre_time <= logged_time)
self.assertTrue(post_time >= logged_time)
self.assertLessEqual(pre_time, logged_time)
self.assertGreaterEqual(post_time, logged_time)

View File

@@ -45,4 +45,4 @@ class CeleryConfigTest(unittest.TestCase):
# but we can assert that they take the right form
self.assertIsInstance(result_dict['task_id'], unicode)
self.assertIsInstance(result_dict['time'], float)
self.assertTrue(result_dict['time'] > 0.0)
self.assertGreater(result_dict['time'], 0.0)

View File

@@ -58,7 +58,7 @@ class TestStudentDashboardEmailView(SharedModuleStoreTestCase):
BulkEmailFlag.objects.create(enabled=True, require_course_email_auth=False)
# Assert that the URL for the email view is in the response
response = self.client.get(self.url)
self.assertTrue(self.email_modal_link in response.content)
self.assertIn(self.email_modal_link, response.content)
def test_email_flag_false(self):
BulkEmailFlag.objects.create(enabled=False)
@@ -85,7 +85,7 @@ class TestStudentDashboardEmailView(SharedModuleStoreTestCase):
# Assert that the URL for the email view is not in the response
# if this course isn't authorized
response = self.client.get(self.url)
self.assertTrue(self.email_modal_link in response.content)
self.assertIn(self.email_modal_link, response.content)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@@ -125,10 +125,10 @@ class TestStudentDashboardEmailViewXMLBacked(SharedModuleStoreTestCase):
# The flag is enabled, and since REQUIRE_COURSE_EMAIL_AUTH is False, all courses should
# be authorized to use email. But the course is not Mongo-backed (should not work)
response = self.client.get(self.url)
self.assertFalse(self.email_modal_link in response.content)
self.assertNotIn(self.email_modal_link, response.content)
def test_email_flag_false_xml_store(self):
BulkEmailFlag.objects.create(enabled=False, require_course_email_auth=False)
# Email disabled, shouldn't see link.
response = self.client.get(self.url)
self.assertFalse(self.email_modal_link in response.content)
self.assertNotIn(self.email_modal_link, response.content)

View File

@@ -413,7 +413,7 @@ class LoginTest(CacheIsolationTestCase):
if value is not None:
msg = ("'%s' did not contain '%s'" %
(str(response_dict['value']), str(value)))
self.assertTrue(value in response_dict['value'], msg)
self.assertIn(value, response_dict['value'], msg)
def _assert_audit_log(self, mock_audit_log, level, log_strings):
"""

View File

@@ -335,7 +335,7 @@ class DashboardTest(ModuleStoreTestCase):
response = self.client.get(redeem_url)
self.assertEquals(response.status_code, 200)
# check button text
self.assertTrue('Activate Course Enrollment' in response.content)
self.assertIn('Activate Course Enrollment', response.content)
#now activate the user by enrolling him/her to the course
response = self.client.post(redeem_url)

View File

@@ -158,7 +158,7 @@ class StoreUploadedFileTestCase(TestCase):
def success_validator(storage, filename):
""" Validation test function that is a no-op """
self.assertTrue("success_file" in os.path.basename(filename))
self.assertIn("success_file", os.path.basename(filename))
store_file_data(storage, filename)
with self.assertRaises(FileValidationException) as error:
@@ -216,7 +216,7 @@ class StoreUploadedFileTestCase(TestCase):
self.request, "nonunique_file", [".txt"], requested_file_name, self.default_max_size
)
self.assertNotEqual(first_stored_file_name, second_stored_file_name)
self.assertTrue(requested_file_name in second_stored_file_name)
self.assertIn(requested_file_name, second_stored_file_name)
self._verify_successful_upload(file_storage, second_stored_file_name, file_content)
def _verify_successful_upload(self, storage, file_name, expected_content):

View File

@@ -68,9 +68,9 @@ class SubmitFeedbackTest(TestCase):
"""
self.assertEqual(response.status_code, 400)
resp_json = json.loads(response.content)
self.assertTrue("field" in resp_json)
self.assertIn("field", resp_json)
self.assertEqual(resp_json["field"], field)
self.assertTrue("error" in resp_json)
self.assertIn("error", resp_json)
# There should be absolutely no interaction with Zendesk
self.assertFalse(zendesk_mock_class.return_value.mock_calls)
self.assertFalse(datadog_mock.mock_calls)

View File

@@ -544,7 +544,7 @@ class MatlabTest(unittest.TestCase):
test_capa_system().xqueue['interface'].send_to_queue.assert_called_with(header=ANY, body=ANY)
self.assertTrue(response['success'])
self.assertTrue(self.the_input.input_state['queuekey'] is not None)
self.assertIsNotNone(self.the_input.input_state['queuekey'])
self.assertEqual(self.the_input.input_state['queuestate'], 'queued')
def test_plot_data_failure(self):
@@ -572,8 +572,8 @@ class MatlabTest(unittest.TestCase):
queue_msg = json.dumps({'msg': inner_msg})
the_input.ungraded_response(queue_msg, queuekey)
self.assertTrue(input_state['queuekey'] is None)
self.assertTrue(input_state['queuestate'] is None)
self.assertIsNone(input_state['queuekey'])
self.assertIsNone(input_state['queuestate'])
self.assertEqual(input_state['queue_msg'], inner_msg)
@patch('capa.inputtypes.time.time', return_value=10)

View File

@@ -71,7 +71,7 @@ class ResponseTest(unittest.TestCase):
def assert_answer_format(self, problem): # pylint: disable=missing-docstring
answers = problem.get_question_answers()
self.assertTrue(answers['1_2_1'] is not None)
self.assertIsNotNone(answers['1_2_1'])
def assert_multiple_grade(self, problem, correct_answers, incorrect_answers): # pylint: disable=missing-docstring
for input_str in correct_answers:

View File

@@ -67,7 +67,7 @@ class SymmathCheckTest(TestCase):
# Expect that an incorrect response is marked incorrect
result = symmath_check(expected_str, input_str, dynamath=[dynamath])
self.assertTrue('ok' in result and not result['ok'])
self.assertFalse('fail' in result['msg'])
self.assertNotIn('fail', result['msg'])
def _symmath_check_numbers(self, number_list):

View File

@@ -199,7 +199,7 @@ class ModuleStoreSettingsMigration(TestCase):
def test_update_settings(self, default_store):
mixed_setting = self.ALREADY_UPDATED_MIXED_CONFIG
update_module_store_settings(mixed_setting, default_store=default_store)
self.assertTrue(get_mixed_stores(mixed_setting)[0]['NAME'] == default_store)
self.assertEqual(get_mixed_stores(mixed_setting)[0]['NAME'], default_store)
def test_update_settings_error(self):
mixed_setting = self.ALREADY_UPDATED_MIXED_CONFIG

View File

@@ -1230,7 +1230,7 @@ class CapaModuleTest(unittest.TestCase):
def test_no_max_attempts(self):
module = CapaFactory.create(max_attempts='')
html = module.get_problem_html()
self.assertTrue(html is not None)
self.assertIsNotNone(html)
# assert that we got here without exploding
def test_get_problem_html(self):
@@ -1365,7 +1365,7 @@ class CapaModuleTest(unittest.TestCase):
# Try to render the module with DEBUG turned off
html = module.get_problem_html()
self.assertTrue(html is not None)
self.assertIsNotNone(html)
# Check the rendering context
render_args, _ = module.system.render_template.call_args
@@ -1395,7 +1395,7 @@ class CapaModuleTest(unittest.TestCase):
# Try to render the module with DEBUG turned on
html = module.get_problem_html()
self.assertTrue(html is not None)
self.assertIsNotNone(html)
# Check the rendering context
render_args, _ = module.system.render_template.call_args
@@ -1419,7 +1419,7 @@ class CapaModuleTest(unittest.TestCase):
# Get the seed
# By this point, the module should have persisted the seed
seed = module.seed
self.assertTrue(seed is not None)
self.assertIsNotNone(seed)
# If we're not rerandomizing, the seed is always set
# to the same value (1)
@@ -1490,7 +1490,7 @@ class CapaModuleTest(unittest.TestCase):
# Get the seed
# By this point, the module should have persisted the seed
seed = module.seed
self.assertTrue(seed is not None)
self.assertIsNotNone(seed)
# We do NOT want the seed to reset if rerandomize
# is set to 'never' -- it should still be 1
@@ -1510,7 +1510,7 @@ class CapaModuleTest(unittest.TestCase):
# to generate a different seed
success = _retry_and_check(5, lambda: _reset_and_get_seed(module) != seed)
self.assertTrue(module.seed is not None)
self.assertIsNotNone(module.seed)
msg = 'Could not get a new seed from reset after 5 tries'
self.assertTrue(success, msg)
@@ -1543,7 +1543,7 @@ class CapaModuleTest(unittest.TestCase):
# Get the seed
# By this point, the module should have persisted the seed
seed = module.seed
self.assertTrue(seed is not None)
self.assertIsNotNone(seed)
#the seed should never change because the student hasn't finished the problem
self.assertEqual(seed, _reset_and_get_seed(module))

View File

@@ -248,7 +248,7 @@ class CohortConfigurationTest(EventsTestMixin, UniqueCourseTest, CohortTestMixin
Create a new cohort and verify the new and existing settings.
"""
start_time = datetime.now(UTC)
self.assertFalse(cohort_name in self.cohort_management_page.get_cohorts())
self.assertNotIn(cohort_name, self.cohort_management_page.get_cohorts())
self.cohort_management_page.add_cohort(cohort_name, assignment_type=assignment_type)
# After adding the cohort, it should automatically be selected
EmptyPromise(
@@ -306,7 +306,7 @@ class CohortConfigurationTest(EventsTestMixin, UniqueCourseTest, CohortTestMixin
confirmation_messages = self.cohort_management_page.get_cohort_settings_messages()
self.assertEqual(["Saved cohort"], confirmation_messages)
self.assertEqual(new_cohort_name, self.cohort_management_page.cohort_name_in_header)
self.assertTrue(new_cohort_name in self.cohort_management_page.get_cohorts())
self.assertIn(new_cohort_name, self.cohort_management_page.get_cohorts())
self.assertEqual(1, self.cohort_management_page.get_selected_cohort_count())
self.assertEqual(
new_assignment_type,

View File

@@ -898,7 +898,7 @@ class UnitPublishingTest(ContainerBase):
unit.wait_for_ajax()
self._verify_publish_title(unit, self.PUBLISHED_LIVE_STATUS)
self._view_published_version(unit)
self.assertTrue(modified_content in self.courseware.xblock_component_html_content(0))
self.assertIn(modified_content, self.courseware.xblock_component_html_content(0))
def test_cancel_does_not_create_draft(self):
"""
@@ -1019,8 +1019,8 @@ class UnitPublishingTest(ContainerBase):
"""
Verifies that last published and last saved messages respectively contain the given strings.
"""
self.assertTrue(expected_published_prefix in unit.last_published_text)
self.assertTrue(expected_saved_prefix in unit.last_saved_text)
self.assertIn(expected_published_prefix, unit.last_published_text)
self.assertIn(expected_saved_prefix, unit.last_saved_text)
def _verify_explicit_lock_overrides_implicit_lock_information(self, unit_page):
"""

View File

@@ -76,7 +76,7 @@ class CMSVideoBaseTest(UniqueCourseTest):
# Why 2? One video component is created by default for each test. Please see
# test_studio_video_module.py:CMSVideoTest._create_course_unit
# And we are creating second video component here.
self.assertTrue(video_xblocks == 2)
self.assertEqual(video_xblocks, 2)
def _install_course_fixture(self):
"""