当前位置: 首页>>代码示例>>Python>>正文


Python factories.CtsUserFactory类代码示例

本文整理汇总了Python中accounts.tests.factories.CtsUserFactory的典型用法代码示例。如果您正苦于以下问题:Python CtsUserFactory类的具体用法?Python CtsUserFactory怎么用?Python CtsUserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CtsUserFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: APITest

class APITest(BaseAPITest):
    @classmethod
    def setUpClass(cls):
        super(APITest, cls).setUpClass()
        bootstrap_permissions()

    def setUp(self):
        super(APITest, self).setUp()
        self.email = '[email protected]'
        self.password = 'liszt'
        self.user = CtsUserFactory(email=self.email,
                                   password=self.password)

    def test_api_root(self):
        # we should get back a nice JSON listing of what's available
        rsp = self.call_api('/api/')
        self.assertEqual(200, rsp.status_code)
        data_json = rsp.content
        data = json.loads(data_json)
        self.assertIn(u'auth/users', data)
        self.assertIn(u'catalog/items', data)

    def test_api_users(self):
        # The users API should list our test user
        rsp = self.call_api('/api/auth/users/')
        self.assertEqual(200, rsp.status_code)
        data = json.loads(rsp.content)['results']
        user = data[0]
        self.assertEqual(user['email'], self.email)
        self.assertEqual(user['is_active'], True)
        self.assertEqual(user['is_superuser'], False)

    def test_auth(self):
        rsp = self.call_api('/api/auth/users/', token='invalidkey')
        self.assertEqual(401, rsp.status_code)

    def test_model_permissions(self):
        self.user.role = ROLE_PARTNER  # No permissions on users
        self.user.save()
        rsp = self.call_api('/api/auth/users/')
        self.assertEqual(403, rsp.status_code)

    def test_post_user(self):
        # The API is read-only. Any POST should return a 405
        user = CtsUserFactory(name="barney fife")
        rsp = self.call_api('/api/auth/users/%d/' % user.pk)
        self.assertEqual(200, rsp.status_code)
        data = json.loads(rsp.content)
        data['name'] = "Freddy Fife"
        rsp = self.post_api('/api/auth/users/%d/' % user.pk, data=data)
        self.assertEqual(405, rsp.status_code)
开发者ID:aqueiroz,项目名称:CTS,代码行数:51,代码来源:tests.py

示例2: test_mobile_validator

 def test_mobile_validator(self):
     # text
     user = CtsUserFactory(mobile='555aaa')
     with self.assertRaises(ValidationError):
         user.full_clean()
     # optional +
     user.mobile = '+555'
     user.full_clean()
     # optional -
     user.mobile = '555-555-555'
     user.full_clean()
开发者ID:aqueiroz,项目名称:CTS,代码行数:11,代码来源:test_models.py

示例3: setUp

 def setUp(self):
     super(ReportTestMixin, 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")
     self.url = reverse(self.report_class.get_report_url_name())
开发者ID:colima,项目名称:CTS,代码行数:7,代码来源:test_views.py

示例4: TestReportList

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])
开发者ID:stbenjam,项目名称:CTS,代码行数:42,代码来源:test_views.py

示例5: test_save_sets_groups

 def test_save_sets_groups(self):
     user = CtsUserFactory(role=ROLE_PARTNER)
     self.assertTrue(user.groups.filter(name=ROLE_PARTNER).exists())
     self.assertFalse(user.groups.filter(name=ROLE_OFFICER).exists())
     self.assertFalse(user.groups.filter(name=ROLE_COORDINATOR).exists())
     user.role = ROLE_OFFICER
     user.save()
     self.assertFalse(user.groups.filter(name=ROLE_PARTNER).exists())
     self.assertTrue(user.groups.filter(name=ROLE_OFFICER).exists())
     self.assertFalse(user.groups.filter(name=ROLE_COORDINATOR).exists())
     user.role = ROLE_COORDINATOR
     user.save()
     self.assertFalse(user.groups.filter(name=ROLE_PARTNER).exists())
     self.assertTrue(user.groups.filter(name=ROLE_OFFICER).exists())
     self.assertTrue(user.groups.filter(name=ROLE_COORDINATOR).exists())
     user.role = ROLE_PARTNER
     user.save()
     self.assertTrue(user.groups.filter(name=ROLE_PARTNER).exists())
     self.assertFalse(user.groups.filter(name=ROLE_OFFICER).exists())
     self.assertFalse(user.groups.filter(name=ROLE_COORDINATOR).exists())
开发者ID:aqueiroz,项目名称:CTS,代码行数:20,代码来源:test_models.py

示例6: KitDeleteViewTest

class KitDeleteViewTest(TestCase):
    @classmethod
    def setUpClass(cls):
        bootstrap_permissions()

    def setUp(self):
        self.user = CtsUserFactory(email="[email protected]", password="6pack", role=ROLE_COORDINATOR)
        assert self.client.login(email="[email protected]", password="6pack")
        assert self.user.has_perm('shipments.delete_kit')

    def test_delete_referenced_kit(self):
        kit = KitFactory()
        KitItemFactory(kit=kit)
        PackageItemFactory(package__kit=kit)

        url = reverse('kit_delete', kwargs={'pk': kit.pk})
        rsp = self.client.post(url)
        success_url = reverse('catalog_list')
        self.assertRedirects(rsp, success_url)
        self.assertFalse(Kit.objects.filter(pk=kit.pk).exists())
开发者ID:stbenjam,项目名称:CTS,代码行数:20,代码来源:test_views.py

示例7: ReportTestMixin

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')
开发者ID:stbenjam,项目名称:CTS,代码行数:99,代码来源:test_views.py

示例8: setUp

 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")
开发者ID:stbenjam,项目名称:CTS,代码行数:6,代码来源:test_views.py

示例9: TransporterViewTest

class TransporterViewTest(TestCase):
    @classmethod
    def setUpClass(cls):
        bootstrap_permissions()

    def setUp(self):
        self.user = CtsUserFactory(email="[email protected]", password="6pack")
        assert self.client.login(email="[email protected]", password="6pack")

    def test_login_required(self):
        self.client.logout()
        rsp = self.client.get(reverse('transporter_list'))
        expected_url = reverse('account_login') + '?next=' + reverse('transporter_list')
        self.assertRedirects(rsp, expected_url)

    def test_role_required(self):
        # Need coordinator role
        self.user.role = ROLE_OFFICER
        self.user.save()
        rsp = self.client.get(reverse('transporter_list'))
        expected_url = reverse('account_login') + '?next=' + reverse('transporter_list')
        self.assertRedirects(rsp, expected_url)

    def test_list(self):
        transporter = TransporterFactory()
        rsp = self.client.get(reverse('transporter_list'))
        self.assertEqual(200, rsp.status_code)
        self.assertContains(rsp, transporter.name, msg_prefix=rsp.content.decode('utf-8'))

    def test_create(self):
        # Create a transporter
        # Get the form page
        url = reverse('new_transporter_modal')
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('form', rsp.context)
        # Submit the new object
        data = {
            'name': 'test',
        }
        rsp = self.client.post(url, data=data)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors.as_text())
        self.assertEqual(rsp.status_code, 200)
        Transporter.objects.get(name='test')

    def test_update(self):
        # Update a transporter
        transporter = TransporterFactory()
        url = reverse('edit_transporter_modal', args=[transporter.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        # Submit the new object
        name = "edited"
        data = {
            'name': name,
        }
        rsp = self.client.post(url, data=data)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertEqual(rsp.status_code, 200)
        transporter2 = Transporter.objects.get(name=name)
        self.assertEqual(transporter.pk, transporter2.pk)

    def test_delete(self):
        # Delete a transporter
        transporter = TransporterFactory()
        url = reverse('transporter_delete', args=[transporter.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertContains(rsp, 'Confirm')
        Transporter.objects.get(pk=transporter.pk)
        # Now delete it!
        rsp = self.client.post(url)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertRedirects(rsp, reverse('transporter_list'))
        self.assertFalse(Transporter.objects.filter(pk=transporter.pk).exists())

    def test_edit_modal(self):
        transporter = TransporterFactory()
        url = reverse('edit_transporter_modal', kwargs={'pk': transporter.pk})
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertTemplateUsed(rsp, 'catalog/transporter_edit_modal.html')
开发者ID:stbenjam,项目名称:CTS,代码行数:85,代码来源:test_views.py

示例10: setUp

 def setUp(self):
     super(CtsUserViewTest, self).setUp()
     self.user = CtsUserFactory(email='[email protected]', password='6pack')
     assert self.client.login(email='[email protected]', password="6pack")
开发者ID:aqueiroz,项目名称:CTS,代码行数:4,代码来源:test_views.py

示例11: setUp

 def setUp(self):
     self.user = CtsUserFactory(email="[email protected]", password="6pack", role=ROLE_COORDINATOR)
     assert self.client.login(email="[email protected]", password="6pack")
开发者ID:stbenjam,项目名称:CTS,代码行数:3,代码来源:test_views.py

示例12: test_skype_validator

 def test_skype_validator(self):
     # space
     user = CtsUserFactory(skype='aaa aaa')
     with self.assertRaises(ValidationError):
         user.full_clean()
     # starts with non-letter
     user.skype = '$asdfasdf'
     with self.assertRaises(ValidationError):
         user.full_clean()
     # < 5 chars
     user.skype = 'asdff'
     with self.assertRaises(ValidationError):
         user.full_clean()
     # > 32 chars
     user.skype = ''.join(random.choice(string.lowercase) for i in range(33))
     with self.assertRaises(ValidationError):
         user.full_clean()
     user.skype = ''.join(random.choice(string.lowercase) for i in range(10))
     user.full_clean()
开发者ID:aqueiroz,项目名称:CTS,代码行数:19,代码来源:test_models.py

示例13: test_hex_color

 def test_hex_color(self):
     # missing #
     user = CtsUserFactory(colour='555aaa')
     with self.assertRaises(ValidationError):
         user.full_clean()
     # not 3 or 6
     user = CtsUserFactory(colour='#5544')
     with self.assertRaises(ValidationError):
         user.full_clean()
     # alpha out of range
     user = CtsUserFactory(colour='#JJJKKK')
     with self.assertRaises(ValidationError):
         user.full_clean()
     # short version
     user.colour = '#FFF'
     user.full_clean()
     # long version
     user.colour = '#FFFCCC'
     user.full_clean()
开发者ID:aqueiroz,项目名称:CTS,代码行数:19,代码来源:test_models.py

示例14: test_has_role

 def test_has_role(self):
     user = CtsUserFactory(role=ROLE_PARTNER)
     self.assertTrue(user.has_role(ROLE_PARTNER))
     self.assertFalse(user.has_role(ROLE_COORDINATOR))
     user.groups.add(Group.objects.get(name=ROLE_COORDINATOR))
     self.assertTrue(user.has_role(ROLE_COORDINATOR))
开发者ID:aqueiroz,项目名称:CTS,代码行数:6,代码来源:test_models.py

示例15: setUp

 def setUp(self):
     super(DonorViewTest, self).setUp()
     self.user = CtsUserFactory(email="[email protected]", password="6pack")
     assert self.client.login(email="[email protected]", password="6pack")
开发者ID:aqueiroz,项目名称:CTS,代码行数:4,代码来源:test_views.py


注:本文中的accounts.tests.factories.CtsUserFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。