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

@@ -55,7 +55,7 @@ class TestOptoutCourseEmails(ModuleStoreTestCase):
response = self.client.get(url)
email_section = '<div class="vert-left send-email" id="section-send-email">'
# If this fails, it is likely because BulkEmailFlag.is_enabled() is set to False
self.assertTrue(email_section in response.content)
self.assertIn(email_section, response.content)
def test_optout_course(self):
"""

View File

@@ -166,4 +166,4 @@ class WikiRedirectTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
# and end up at the login page
resp = self.client.get(course_wiki_page, follow=True)
target_url, __ = resp.redirect_chain[-1]
self.assertTrue(reverse('signin_user') in target_url)
self.assertIn(reverse('signin_user'), target_url)

View File

@@ -124,7 +124,7 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase, Mil
Verifies that the staff debug control visibility is as expected (for staff only).
"""
content = self.get_courseware_page().content
self.assertTrue(self.sequential_display_name in content, "Subsection should be visible")
self.assertIn(self.sequential_display_name, content, "Subsection should be visible")
self.assertEqual(staff_debug_expected, 'Staff Debug Info' in content)
def get_problem(self):
@@ -147,7 +147,7 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase, Mil
Verifies that "Show Answer" is only present when expected (for staff only).
"""
problem_html = json.loads(self.get_problem().content)['html']
self.assertTrue(self.problem_display_name in problem_html)
self.assertIn(self.problem_display_name, problem_html)
self.assertEqual(show_answer_expected, "Show Answer" in problem_html)

View File

@@ -634,7 +634,7 @@ class ViewsTestCase(ModuleStoreTestCase, MilestonesTestCaseMixin):
})
response = self.client.get(url)
# Tests that we do not get an "Invalid x" response when passing correct arguments to view
self.assertFalse('Invalid' in response.content)
self.assertNotIn('Invalid', response.content)
def test_submission_history_xss(self):
# log into a staff account
@@ -649,7 +649,7 @@ class ViewsTestCase(ModuleStoreTestCase, MilestonesTestCaseMixin):
'location': '<script>alert("hello");</script>'
})
response = self.client.get(url)
self.assertFalse('<script>' in response.content)
self.assertNotIn('<script>', response.content)
# try it with a malicious user and a non-existent location
url = reverse('submission_history', kwargs={
@@ -658,7 +658,7 @@ class ViewsTestCase(ModuleStoreTestCase, MilestonesTestCaseMixin):
'location': 'dummy'
})
response = self.client.get(url)
self.assertFalse('<script>' in response.content)
self.assertNotIn('<script>', response.content)
def test_submission_history_contents(self):
# log into a staff account

View File

@@ -166,7 +166,7 @@ class TestSysAdminMongoCourseImport(SysadminBaseTestCase):
self._mkdir(settings.GIT_REPO_DIR)
def_ms = modulestore()
self.assertFalse('xml' == def_ms.get_modulestore_type(None))
self.assertNotEqual('xml', def_ms.get_modulestore_type(None))
self._add_edx4edx()
course = def_ms.get_course(SlashSeparatedCourseKey('MITx', 'edx4edx', 'edx4edx'))

View File

@@ -2323,7 +2323,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment
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)
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)

View File

@@ -49,18 +49,18 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
Test Pass E-commerce Tab is in the Instructor Dashboard
"""
response = self.client.get(self.url)
self.assertTrue(self.e_commerce_link in response.content)
self.assertIn(self.e_commerce_link, response.content)
# Coupons should show up for White Label sites with priced honor modes.
self.assertTrue('Coupon Code List' in response.content)
self.assertIn('Coupon Code List', response.content)
def test_user_has_finance_admin_rights_in_e_commerce_tab(self):
response = self.client.get(self.url)
self.assertTrue(self.e_commerce_link in response.content)
self.assertIn(self.e_commerce_link, response.content)
# Order/Invoice sales csv button text should render in e-commerce page
self.assertTrue('Total Credit Card Purchases' in response.content)
self.assertTrue('Download All Credit Card Purchases' in response.content)
self.assertTrue('Download All Invoices' in response.content)
self.assertIn('Total Credit Card Purchases', response.content)
self.assertIn('Download All Credit Card Purchases', response.content)
self.assertIn('Download All Invoices', response.content)
# removing the course finance_admin role of login user
CourseFinanceAdminRole(self.course.id).remove_users(self.instructor)
@@ -68,7 +68,7 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
# Order/Invoice sales csv button text should not be visible in e-commerce page if the user is not finance admin
url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(url)
self.assertFalse('Download All Invoices' in response.content)
self.assertNotIn('Download All Invoices', response.content)
def test_user_view_course_price(self):
"""
@@ -76,14 +76,14 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
the instructor dashboard
"""
response = self.client.get(self.url)
self.assertTrue(self.e_commerce_link in response.content)
self.assertIn(self.e_commerce_link, response.content)
# Total amount html should render in e-commerce page, total amount will be 0
course_honor_mode = CourseMode.mode_for_course(self.course.id, 'honor')
price = course_honor_mode.min_price
self.assertTrue('Course price per seat: <span>$' + str(price) + '</span>' in response.content)
self.assertFalse('+ Set Price</a></span>' in response.content)
self.assertIn('Course price per seat: <span>$' + str(price) + '</span>', response.content)
self.assertNotIn('+ Set Price</a></span>', response.content)
# removing the course finance_admin role of login user
CourseFinanceAdminRole(self.course.id).remove_users(self.instructor)
@@ -91,7 +91,7 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
# total amount should not be visible in e-commerce page if the user is not finance admin
url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.get(url)
self.assertFalse('+ Set Price</a></span>' in response.content)
self.assertNotIn('+ Set Price</a></span>', response.content)
def test_update_course_price_check(self):
price = 200
@@ -108,13 +108,13 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
set_course_price_url = reverse('set_course_mode_price', kwargs={'course_id': self.course.id.to_deprecated_string()})
data = {'course_price': price, 'currency': 'usd'}
response = self.client.post(set_course_price_url, data)
self.assertTrue('CourseMode price updated successfully' in response.content)
self.assertIn('CourseMode price updated successfully', response.content)
# Course A updated total amount should be visible in e-commerce page if the user is finance admin
url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.get(url)
self.assertTrue('Course price per seat: <span>$' + str(price) + '</span>' in response.content)
self.assertIn('Course price per seat: <span>$' + str(price) + '</span>', response.content)
def test_user_admin_set_course_price(self):
"""
@@ -126,18 +126,21 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
# Value Error course price should be a numeric value
response = self.client.post(set_course_price_url, data)
self.assertTrue("Please Enter the numeric value for the course price" in response.content)
self.assertIn("Please Enter the numeric value for the course price", response.content)
# validation check passes and course price is successfully added
data['course_price'] = 100
response = self.client.post(set_course_price_url, data)
self.assertTrue("CourseMode price updated successfully" in response.content)
self.assertIn("CourseMode price updated successfully", response.content)
course_honor_mode = CourseMode.objects.get(mode_slug='honor')
course_honor_mode.delete()
# Course Mode not exist with mode slug honor
response = self.client.post(set_course_price_url, data)
self.assertTrue("CourseMode with the mode slug({mode_slug}) DoesNotExist".format(mode_slug='honor') in response.content)
self.assertIn(
"CourseMode with the mode slug({mode_slug}) DoesNotExist".format(mode_slug='honor'),
response.content
)
def test_add_coupon(self):
"""
@@ -150,10 +153,15 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'ADSADASDSAD', 'created_by': self.instructor, 'discount': 5,
'expiration_date': '{month}/{day}/{year}'.format(month=expiration_date.month, day=expiration_date.day, year=expiration_date.year)
'expiration_date': '{month}/{day}/{year}'.format(
month=expiration_date.month, day=expiration_date.day, year=expiration_date.year
)
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) added successfully".format(code=data['code']) in response.content)
self.assertIn(
"coupon with the coupon code ({code}) added successfully".format(code=data['code']),
response.content
)
#now add the coupon with the wrong value in the expiration_date
# server will through the ValueError Exception in the expiration_date field
@@ -163,30 +171,30 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
'expiration_date': expiration_date.strftime('"%d/%m/%Y')
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("Please enter the date in this format i-e month/day/year" in response.content)
self.assertIn("Please enter the date in this format i-e month/day/year", response.content)
data = {
'code': 'A2314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'asdsasda', 'created_by': self.instructor, 'discount': 99
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("coupon with the coupon code ({code}) already exist".format(code='A2314') in response.content)
self.assertIn("coupon with the coupon code ({code}) already exist".format(code='A2314'), response.content)
response = self.client.post(self.url)
self.assertTrue('<td>ADSADASDSAD</td>' in response.content)
self.assertTrue('<td>A2314</td>' in response.content)
self.assertFalse('<td>111</td>' in response.content)
self.assertIn('<td>ADSADASDSAD</td>', response.content)
self.assertIn('<td>A2314</td>', response.content)
self.assertNotIn('<td>111</td>', response.content)
data = {
'code': 'A2345314', 'course_id': self.course.id.to_deprecated_string(),
'description': 'asdsasda', 'created_by': self.instructor, 'discount': 199
}
response = self.client.post(add_coupon_url, data)
self.assertTrue("Please Enter the Coupon Discount Value Less than or Equal to 100" in response.content)
self.assertIn("Please Enter the Coupon Discount Value Less than or Equal to 100", response.content)
data['discount'] = '25%'
response = self.client.post(add_coupon_url, data=data)
self.assertTrue('Please Enter the Integer Value for Coupon Discount' in response.content)
self.assertIn('Please Enter the Integer Value for Coupon Discount', response.content)
course_registration = CourseRegistrationCode(
code='Vs23Ws4j', course_id=unicode(self.course.id), created_by=self.instructor,
@@ -211,24 +219,33 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
coupon.save()
response = self.client.post(self.url)
self.assertTrue('<td>AS452</td>' in response.content)
self.assertIn('<td>AS452</td>', response.content)
# URL for remove_coupon
delete_coupon_url = reverse('remove_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(delete_coupon_url, {'id': coupon.id})
self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)
self.assertIn(
'coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id),
response.content
)
coupon.is_active = False
coupon.save()
response = self.client.post(delete_coupon_url, {'id': coupon.id})
self.assertTrue('coupon with the coupon id ({coupon_id}) is already inactive'.format(coupon_id=coupon.id) in response.content)
self.assertIn(
'coupon with the coupon id ({coupon_id}) is already inactive'.format(coupon_id=coupon.id),
response.content
)
response = self.client.post(delete_coupon_url, {'id': 24454})
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=24454) in response.content)
self.assertIn(
'coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=24454),
response.content
)
response = self.client.post(delete_coupon_url, {'id': ''})
self.assertTrue('coupon id is None' in response.content)
self.assertIn('coupon id is None', response.content)
def test_get_coupon_info(self):
"""
@@ -243,20 +260,29 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
# URL for edit_coupon_info
edit_url = reverse('get_coupon_info', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(edit_url, {'id': coupon.id})
self.assertTrue('coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id) in response.content)
self.assertIn(
'coupon with the coupon id ({coupon_id}) updated successfully'.format(coupon_id=coupon.id),
response.content
)
self.assertIn(coupon.display_expiry_date, response.content)
response = self.client.post(edit_url, {'id': 444444})
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=444444) in response.content)
self.assertIn(
'coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=444444),
response.content
)
response = self.client.post(edit_url, {'id': ''})
self.assertTrue('coupon id not found"' in response.content)
self.assertIn('coupon id not found"', response.content)
coupon.is_active = False
coupon.save()
response = self.client.post(edit_url, {'id': coupon.id})
self.assertTrue("coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id) in response.content)
self.assertIn(
"coupon with the coupon id ({coupon_id}) is already inactive".format(coupon_id=coupon.id),
response.content
)
def test_update_coupon(self):
"""
@@ -268,7 +294,7 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
)
coupon.save()
response = self.client.post(self.url)
self.assertTrue('<td>AS452</td>' in response.content)
self.assertIn('<td>AS452</td>', response.content)
data = {
'coupon_id': coupon.id, 'code': 'AS452', 'discount': '10', 'description': 'updated_description',
'course_id': coupon.course_id.to_deprecated_string()
@@ -276,18 +302,21 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
# URL for update_coupon
update_coupon_url = reverse('update_coupon', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon with the coupon id ({coupon_id}) updated Successfully'.format(coupon_id=coupon.id)in response.content)
self.assertIn(
'coupon with the coupon id ({coupon_id}) updated Successfully'.format(coupon_id=coupon.id),
response.content
)
response = self.client.post(self.url)
self.assertTrue('<td>updated_description</td>' in response.content)
self.assertIn('<td>updated_description</td>', response.content)
data['coupon_id'] = 1000 # Coupon Not Exist with this ID
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=1000) in response.content)
self.assertIn('coupon with the coupon id ({coupon_id}) DoesNotExist'.format(coupon_id=1000), response.content)
data['coupon_id'] = '' # Coupon id is not provided
response = self.client.post(update_coupon_url, data=data)
self.assertTrue('coupon id not found' in response.content)
self.assertIn('coupon id not found', response.content)
def test_verified_course(self):
"""Verify the e-commerce panel shows up for verified courses as well, without Coupons """
@@ -302,6 +331,6 @@ class TestECommerceDashboardViews(SharedModuleStoreTestCase):
# Get the response value, ensure the Coupon section is not included.
response = self.client.get(self.url)
self.assertTrue(self.e_commerce_link in response.content)
self.assertIn(self.e_commerce_link, response.content)
# Coupons should show up for White Label sites with priced honor modes.
self.assertFalse('Coupons List' in response.content)
self.assertNotIn('Coupons List', response.content)

View File

@@ -57,7 +57,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
self.assertIn(self.email_link, response.content)
send_to_label = '<div class="send_to_list">Send to:</div>'
self.assertTrue(send_to_label in response.content)
self.assertIn(send_to_label, response.content)
self.assertEqual(response.status_code, 200)
# The course is Mongo-backed but the flag is disabled (should not work)
@@ -65,7 +65,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
BulkEmailFlag.objects.create(enabled=False)
# Assert that the URL for the email view is not in the response
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
self.assertNotIn(self.email_link, response.content)
# Flag is enabled, but we require course auth and haven't turned it on for this course
def test_course_not_authorized(self):
@@ -74,7 +74,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
self.assertFalse(BulkEmailFlag.feature_enabled(self.course.id))
# Assert that the URL for the email view is not in the response
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
self.assertNotIn(self.email_link, response.content)
# Flag is enabled, we require course auth and turn it on for this course
def test_course_authorized(self):
@@ -83,7 +83,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
self.assertFalse(BulkEmailFlag.feature_enabled(self.course.id))
# Assert that the URL for the email view is not in the response
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
self.assertNotIn(self.email_link, response.content)
# Authorize the course to use email
cauth = CourseAuthorization(course_id=self.course.id, email_enabled=True)
@@ -93,7 +93,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
self.assertTrue(BulkEmailFlag.feature_enabled(self.course.id))
# Assert that the URL for the email view is in the response
response = self.client.get(self.url)
self.assertTrue(self.email_link in response.content)
self.assertIn(self.email_link, response.content)
# Flag is disabled, but course is authorized
def test_course_authorized_feature_off(self):
@@ -107,7 +107,7 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
self.assertTrue(CourseAuthorization.instructor_email_enabled(self.course.id))
# Assert that the URL for the email view IS NOT in the response
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
self.assertNotIn(self.email_link, response.content)
@attr('shard_1')
@@ -149,10 +149,10 @@ class TestNewInstructorDashboardEmailViewXMLBacked(SharedModuleStoreTestCase):
def test_email_flag_true_mongo_false(self):
BulkEmailFlag.objects.create(enabled=True, require_course_email_auth=False)
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
self.assertNotIn(self.email_link, response.content)
# The flag is disabled and the course is not Mongo-backed (should not work)
def test_email_flag_false_mongo_false(self):
BulkEmailFlag.objects.create(enabled=False, require_course_email_auth=False)
response = self.client.get(self.url)
self.assertFalse(self.email_link in response.content)
self.assertNotIn(self.email_link, response.content)

View File

@@ -46,8 +46,8 @@ class TestProctoringDashboardViews(SharedModuleStoreTestCase):
self.instructor.save()
response = self.client.get(self.url)
self.assertTrue(self.proctoring_link in response.content)
self.assertTrue('Allowance Section' in response.content)
self.assertIn(self.proctoring_link, response.content)
self.assertIn('Allowance Section', response.content)
def test_no_tab_non_global_staff(self):
"""
@@ -58,8 +58,8 @@ class TestProctoringDashboardViews(SharedModuleStoreTestCase):
self.instructor.save()
response = self.client.get(self.url)
self.assertFalse(self.proctoring_link in response.content)
self.assertFalse('Allowance Section' in response.content)
self.assertNotIn(self.proctoring_link, response.content)
self.assertNotIn('Allowance Section', response.content)
@patch.dict(settings.FEATURES, {'ENABLE_SPECIAL_EXAMS': False})
def test_no_tab_flag_unset(self):
@@ -71,5 +71,5 @@ class TestProctoringDashboardViews(SharedModuleStoreTestCase):
self.instructor.save()
response = self.client.get(self.url)
self.assertFalse(self.proctoring_link in response.content)
self.assertFalse('Allowance Section' in response.content)
self.assertNotIn(self.proctoring_link, response.content)
self.assertNotIn('Allowance Section', response.content)

View File

@@ -110,7 +110,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
total_amount = PaidCourseRegistration.get_total_amount_of_purchased_item(self.course.id)
response = self.client.get(self.url)
self.assertTrue('${amount}'.format(amount=total_amount) in response.content)
self.assertIn('${amount}'.format(amount=total_amount), response.content)
def test_course_name_xss(self):
"""Test that the instructor dashboard correctly escapes course names
@@ -155,7 +155,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
self.assertIn('<th scope="row">Professional</th>', response.content)
# dashboard link hidden
self.assertFalse(self.get_dashboard_enrollment_message() in response.content)
self.assertNotIn(self.get_dashboard_enrollment_message(), response.content)
@patch.dict(settings.FEATURES, {'DISPLAY_ANALYTICS_ENROLLMENTS': True})
@override_settings(ANALYTICS_DASHBOARD_URL='')
@@ -188,7 +188,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
# link to dashboard shown
expected_message = self.get_dashboard_enrollment_message()
self.assertTrue(expected_message in response.content)
self.assertIn(expected_message, response.content)
@override_settings(ANALYTICS_DASHBOARD_URL='')
@override_settings(ANALYTICS_DASHBOARD_NAME='')
@@ -198,7 +198,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
"""
response = self.client.get(self.url)
analytics_section = '<li class="nav-item"><a href="" data-section="instructor_analytics">Analytics</a></li>'
self.assertFalse(analytics_section in response.content)
self.assertNotIn(analytics_section, response.content)
@override_settings(ANALYTICS_DASHBOARD_URL='http://example.com')
@override_settings(ANALYTICS_DASHBOARD_NAME='Example')
@@ -208,11 +208,11 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
"""
response = self.client.get(self.url)
analytics_section = '<li class="nav-item"><a href="" data-section="instructor_analytics">Analytics</a></li>'
self.assertTrue(analytics_section in response.content)
self.assertIn(analytics_section, response.content)
# link to dashboard shown
expected_message = self.get_dashboard_analytics_message()
self.assertTrue(expected_message in response.content)
self.assertIn(expected_message, response.content)
def add_course_to_user_cart(self, cart, course_key):
"""

View File

@@ -92,8 +92,8 @@ class TestAnalyticsBasic(ModuleStoreTestCase):
# Check if list_problem_responses returned expected results:
self.assertEqual(len(problem_responses), len(mock_results))
for mock_result in mock_results:
self.assertTrue(
{'username': mock_result.student.username, 'state': mock_result.state} in
self.assertIn(
{'username': mock_result.student.username, 'state': mock_result.state},
problem_responses
)

View File

@@ -54,7 +54,7 @@ class TestIntegrationTask(InstructorTaskModuleTestCase):
self.assertEqual(instructor_task.requester.username, 'instructor')
self.assertEqual(instructor_task.task_type, task_type)
task_input = json.loads(instructor_task.task_input)
self.assertFalse('student' in task_input)
self.assertNotIn('student', task_input)
self.assertEqual(task_input['problem_url'], InstructorTaskModuleTestCase.problem_location(problem_url_name).to_deprecated_string())
status = json.loads(instructor_task.task_output)
self.assertEqual(status['exception'], 'ZeroDivisionError')
@@ -118,8 +118,8 @@ class TestRescoringTask(TestIntegrationTask):
attempts = state['attempts']
self.assertEqual(attempts, expected_attempts)
if attempts > 0:
self.assertTrue('correct_map' in state)
self.assertTrue('student_answers' in state)
self.assertIn('correct_map', state)
self.assertIn('student_answers', state)
self.assertGreater(len(state['correct_map']), 0)
self.assertGreater(len(state['student_answers']), 0)
@@ -209,7 +209,7 @@ class TestRescoringTask(TestIntegrationTask):
self.assertEqual(instructor_task.requester.username, 'instructor')
self.assertEqual(instructor_task.task_type, 'rescore_problem')
task_input = json.loads(instructor_task.task_input)
self.assertFalse('student' in task_input)
self.assertNotIn('student', task_input)
self.assertEqual(task_input['problem_url'], InstructorTaskModuleTestCase.problem_location(problem_url_name).to_deprecated_string())
status = json.loads(instructor_task.task_output)
self.assertEqual(status['attempted'], 1)
@@ -441,7 +441,7 @@ class TestDeleteProblemTask(TestIntegrationTask):
self.submit_student_answer(username, problem_url_name, [OPTION_1, OPTION_1])
# confirm that state exists:
for username in self.userlist:
self.assertTrue(self.get_student_module(username, descriptor) is not None)
self.assertIsNotNone(self.get_student_module(username, descriptor))
# run delete task:
self.delete_problem_state('instructor', location)
# confirm that no state can be found:

View File

@@ -191,7 +191,7 @@ class TestInstructorTasks(InstructorTaskModuleTestCase):
output = json.loads(entry.task_output)
self.assertEquals(output['exception'], 'TestTaskFailure')
self.assertEquals(output['message'], expected_message[:len(output['message']) - 3] + "...")
self.assertTrue('traceback' not in output)
self.assertNotIn('traceback', output)
def _test_run_with_short_error_msg(self, task_class):
"""

View File

@@ -471,7 +471,7 @@ class TestInstructorDetailedEnrollmentReport(TestReportMixin, InstructorTaskCour
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)
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
@@ -505,7 +505,7 @@ class TestInstructorDetailedEnrollmentReport(TestReportMixin, InstructorTaskCour
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)
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
@@ -546,7 +546,7 @@ class TestInstructorDetailedEnrollmentReport(TestReportMixin, InstructorTaskCour
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)
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
@@ -953,7 +953,7 @@ class TestExecutiveSummaryReport(TestReportMixin, InstructorTaskCourseTestCase):
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)
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
@@ -999,7 +999,7 @@ class TestExecutiveSummaryReport(TestReportMixin, InstructorTaskCourseTestCase):
with report_store.storage.open(report_path) as html_file:
html_file_data = html_file.read()
for data in expected_data:
self.assertTrue(data in html_file_data)
self.assertIn(data, html_file_data)
@ddt.ddt

View File

@@ -170,7 +170,7 @@ class InstructorTaskReportTest(InstructorTaskTestCase):
mock_result.state = PENDING
output = self._test_get_status_from_result(task_id, mock_result)
for key in ['message', 'succeeded', 'task_progress']:
self.assertTrue(key not in output)
self.assertNotIn(key, output)
self.assertEquals(output['task_state'], 'PENDING')
self.assertTrue(output['in_progress'])
@@ -294,15 +294,15 @@ class InstructorTaskReportTest(InstructorTaskTestCase):
self.assertTrue(output['succeeded'])
output = self._get_output_for_task_success(0, 0, 1, student=self.student)
self.assertTrue("Unable to find submission to be rescored for student" in output['message'])
self.assertIn("Unable to find submission to be rescored for student", output['message'])
self.assertFalse(output['succeeded'])
output = self._get_output_for_task_success(1, 0, 1, student=self.student)
self.assertTrue("Problem failed to be rescored for student" in output['message'])
self.assertIn("Problem failed to be rescored for student", output['message'])
self.assertFalse(output['succeeded'])
output = self._get_output_for_task_success(1, 1, 1, student=self.student)
self.assertTrue("Problem successfully rescored for student" in output['message'])
self.assertIn("Problem successfully rescored for student", output['message'])
self.assertTrue(output['succeeded'])
def test_email_success_messages(self):

View File

@@ -61,11 +61,11 @@ class UserManagementHelperTest(TestCase):
def test_random_username_generator(self):
for _idx in range(1000):
username = users.generate_random_edx_username()
self.assertTrue(len(username) <= 30, 'Username too long')
self.assertLessEqual(len(username), 30, 'Username too long')
# Check that the username contains only allowable characters
for char in range(len(username)):
self.assertTrue(
username[char] in string.ascii_letters + string.digits,
self.assertIn(
username[char], string.ascii_letters + string.digits,
"Username has forbidden character '{}'".format(username[char])
)

View File

@@ -68,7 +68,7 @@ class TestUserInfoApi(MobileAPITestCase, MobileAuthTestMixin):
self.login()
response = self.api_response(expected_response_code=302)
self.assertTrue(self.username in response['location'])
self.assertIn(self.username, response['location'])
@attr('shard_2')

View File

@@ -590,12 +590,12 @@ class TestVideoSummaryList(TestVideoAPITestCase, MobileAuthTestMixin, MobileCour
course_outline = self.api_response().data
self.assertEqual(len(course_outline), 3)
vid = course_outline[0]
self.assertTrue('test_subsection_omega_%CE%A9' in vid['section_url'])
self.assertTrue('test_subsection_omega_%CE%A9/1' in vid['unit_url'])
self.assertTrue(u'test_video_omega_\u03a9' in vid['summary']['id'])
self.assertIn('test_subsection_omega_%CE%A9', vid['section_url'])
self.assertIn('test_subsection_omega_%CE%A9/1', vid['unit_url'])
self.assertIn(u'test_video_omega_\u03a9', vid['summary']['id'])
self.assertEqual(vid['summary']['video_url'], self.video_url)
self.assertEqual(vid['summary']['size'], 12345)
self.assertTrue('en' in vid['summary']['transcripts'])
self.assertIn('en', vid['summary']['transcripts'])
self.assertFalse(vid['summary']['only_on_web'])
self.assertEqual(course_outline[1]['summary']['video_url'], self.html5_video_url)
self.assertEqual(course_outline[1]['summary']['size'], 0)

View File

@@ -376,7 +376,7 @@ class ApiTest(TestCase):
content = json.loads(resp.content)
for expected_key in ('total', 'rows'):
self.assertTrue(expected_key in content)
self.assertIn(expected_key, content)
if 'expected_total' in test:
self.assertEqual(content['total'], test['expected_total'])
@@ -386,7 +386,7 @@ class ApiTest(TestCase):
self.assertEqual(len(content['rows']), test['expected_rows'])
for row in content['rows']:
self.assertTrue('id' in row)
self.assertIn('id', row)
class NoteTest(TestCase):
@@ -445,4 +445,4 @@ class NoteTest(TestCase):
d = note.as_dict()
self.assertNotIsInstance(d, basestring)
self.assertEqual(d['user_id'], self.student.id)
self.assertTrue('course_id' not in d)
self.assertNotIn('course_id', d)

View File

@@ -598,7 +598,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
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)
@@ -629,7 +629,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
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)
@@ -1097,7 +1097,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
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)
@@ -1124,7 +1124,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
resp = self.client.get(redeem_url)
self.assertEquals(resp.status_code, 200)
# check button text
self.assertTrue('Activate Course Enrollment' in resp.content)
self.assertIn('Activate Course Enrollment', resp.content)
#now activate the user by enrolling him/her to the course
resp = self.client.post(redeem_url)
@@ -1278,7 +1278,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
#now activate the user by enrolling him/her to the course
response = self.client.post(redeem_url)
self.assertEquals(response.status_code, 200)
self.assertTrue('View Dashboard' in response.content)
self.assertIn('View Dashboard', response.content)
# now view the receipt page again to see if any registration codes
# has been expired or not

View File

@@ -169,12 +169,12 @@ class SurveyModelsTests(TestCase):
all_answers = survey.get_answers()
self.assertEquals(len(all_answers.keys()), 1)
self.assertTrue(self.student.id in all_answers)
self.assertIn(self.student.id, all_answers)
self.assertEquals(all_answers[self.student.id], self.student_answers)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertTrue(self.student.id in answers)
self.assertIn(self.student.id, answers)
self.assertEquals(all_answers[self.student.id], self.student_answers)
# check that the course_id was set
@@ -205,19 +205,19 @@ class SurveyModelsTests(TestCase):
all_answers = survey.get_answers()
self.assertEquals(len(all_answers.keys()), 2)
self.assertTrue(self.student.id in all_answers)
self.assertTrue(self.student2.id in all_answers)
self.assertIn(self.student.id, all_answers)
self.assertIn(self.student2.id, all_answers)
self.assertEquals(all_answers[self.student.id], self.student_answers)
self.assertEquals(all_answers[self.student2.id], self.student2_answers)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertTrue(self.student.id in answers)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers)
answers = survey.get_answers(self.student2)
self.assertEquals(len(answers.keys()), 1)
self.assertTrue(self.student2.id in answers)
self.assertIn(self.student2.id, answers)
self.assertEquals(answers[self.student2.id], self.student2_answers)
def test_update_answers(self):
@@ -232,7 +232,7 @@ class SurveyModelsTests(TestCase):
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertTrue(self.student.id in answers)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers)
# update
@@ -240,7 +240,7 @@ class SurveyModelsTests(TestCase):
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertTrue(self.student.id in answers)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers_update)
# update with just a subset of the origin dataset
@@ -248,7 +248,7 @@ class SurveyModelsTests(TestCase):
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertTrue(self.student.id in answers)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers_update2)
def test_limit_num_users(self):

View File

@@ -62,7 +62,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
"""
field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
self.assertTrue('start_date' in filter_dictionary)
self.assertIn('start_date', filter_dictionary)
self.assertIn(unicode(self.courses[0].id), field_dictionary['course'])
self.assertIn(unicode(self.courses[1].id), field_dictionary['course'])
@@ -75,7 +75,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
course_id=unicode(self.courses[0].id)
)
self.assertTrue('start_date' in filter_dictionary)
self.assertIn('start_date', filter_dictionary)
self.assertEqual(unicode(self.courses[0].id), field_dictionary['course'])
def test_user_not_provided(self):
@@ -84,7 +84,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
"""
field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters()
self.assertTrue('start_date' in filter_dictionary)
self.assertIn('start_date', filter_dictionary)
self.assertEqual(0, len(field_dictionary['course']))
def test_excludes_site_org(self):