當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。