本文整理汇总了Python中accounts.tests.factories.CtsUserFactory.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python CtsUserFactory.set_password方法的具体用法?Python CtsUserFactory.set_password怎么用?Python CtsUserFactory.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.tests.factories.CtsUserFactory
的用法示例。
在下文中一共展示了CtsUserFactory.set_password方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestReportList
# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import set_password [as 别名]
class TestReportList(TestCase):
url_name = 'reports_list'
template_name = 'reports/reports_list.html'
def setUp(self):
super(TestReportList, self).setUp()
self.user = CtsUserFactory(email="[email protected]")
self.user.set_password("password")
self.user.save()
assert self.client.login(email="[email protected]", password="password")
def get_expected_reports(self):
"""Update this list each time a report is added or removed."""
return [
PackageReport,
DonorByShipmentReport,
DonorByCategoryReport,
ItemReport,
ShipmentReport,
ReceivedItemsByShipmentReport,
ReceivedItemsByDonorOrPartnerReport,
ShipmentMonthlySummaryReport,
# add new reports above the test report
BadReportClassForTesting,
]
def test_unauthenticated(self):
"""View requires authentication."""
self.client.logout()
response = self.client.get(reverse(self.url_name))
self.assertEqual(response.status_code, 302)
def test_expected_reports(self):
"""Basic check that the correct reports are returned."""
response = self.client.get(reverse(self.url_name))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, self.template_name)
self.assertTrue('reports' in response.context)
expected = self.get_expected_reports()
actual = response.context['reports']
self.assertEqual([c.__name__ for c in actual],
[c.__name__ for c in expected])
示例2: ReportTestMixin
# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import set_password [as 别名]
class ReportTestMixin(object):
report_class = None
template_name = 'reports/report.html'
important_date = date(1972, 11, 3)
day_before = date(1972, 11, 2)
day_after = date(1972, 11, 4)
def setUp(self):
self.user = CtsUserFactory(email="[email protected]")
self.user.set_password("password")
self.user.save()
assert self.client.login(email="[email protected]", password="password")
self.url = reverse(self.report_class.get_report_url_name())
@classmethod
def setUpClass(cls):
bootstrap_permissions()
cls.partner1 = PartnerFactory()
cls.partner2 = PartnerFactory()
cls.partner3 = PartnerFactory()
cls.donor1 = DonorFactory()
cls.donor2 = DonorFactory()
cls.donor3 = DonorFactory()
cls.category1 = ItemCategoryFactory()
cls.category2 = ItemCategoryFactory()
cls.category3 = ItemCategoryFactory()
cls.shipment1 = ShipmentFactory(partner=cls.partner1,
shipment_date=cls.day_before,
status=Shipment.STATUS_IN_TRANSIT)
cls.package1 = PackageFactory(shipment=cls.shipment1,
status=Shipment.STATUS_IN_TRANSIT)
cls.item1 = PackageItemFactory(package=cls.package1, donor=cls.donor1,
item_category=cls.category1)
cls.shipment2 = ShipmentFactory(partner=cls.partner2,
shipment_date=cls.important_date,
status=Shipment.STATUS_RECEIVED)
cls.package2 = PackageFactory(shipment=cls.shipment2,
status=Shipment.STATUS_RECEIVED)
cls.item2 = PackageItemFactory(package=cls.package2, donor=cls.donor2,
item_category=cls.category2)
cls.shipment3 = ShipmentFactory(partner=cls.partner3,
shipment_date=cls.day_after,
status=Shipment.STATUS_CANCELED)
cls.package3 = PackageFactory(shipment=cls.shipment3,
status=Shipment.STATUS_CANCELED)
cls.item3 = PackageItemFactory(package=cls.package3, donor=cls.donor3,
item_category=cls.category3)
@classmethod
def tearDownClass(cls):
PackageItem.objects.all().delete()
CatalogItem.objects.all().delete()
Package.objects.all().delete()
Shipment.objects.all().delete()
CtsUser.objects.all().delete()
ItemCategory.objects.all().delete()
Donor.objects.all().delete()
def ajax_get(self, *args, **kwargs):
"""Like self.client.get, but looks like it came via ajax"""
kwargs['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
return self.client.get(*args, **kwargs)
def csv_get(self, url, *args, **kwargs):
"""Like self.client.get, but asks for response as CSV"""
parm_name = "%s-%s" % (DEFAULT_PARAM_PREFIX,
self.report_class.table_class.__name__.lower())
if "?" in url:
url = url + "&" + parm_name + "=csv"
else:
url = url + "?" + parm_name + "=csv"
return self.client.get(url, *args, **kwargs)
def test_200(self):
rsp = self.client.get(self.url)
self.assertEqual(200, rsp.status_code)
self.assertTemplateUsed(rsp, self.template_name)
def test_ajax_200(self):
rsp = self.ajax_get(self.url)
self.assertEqual(200, rsp.status_code)
self.assertEqual(rsp['content-type'], 'text/html; charset=utf-8')
self.assertTemplateUsed(rsp, self.ajax_template_name)
def test_report_title(self):
self.assertEqual(self.expected_report_title, self.report_class.get_report_title())
def test_csv_200(self):
rsp = self.csv_get(self.url)
self.assertEqual(200, rsp.status_code)
self.assertEqual(rsp['content-type'], 'text/csv; charset=utf-8')