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


Python CtsUserFactory.save方法代码示例

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


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

示例1: APITest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
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,代码行数:53,代码来源:tests.py

示例2: test_is_just_partner

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
 def test_is_just_partner(self):
     user = CtsUserFactory(role=ROLE_PARTNER, is_superuser=False)
     self.assertTrue(user.is_just_partner())
     user.role = ROLE_COORDINATOR
     user.save()
     self.assertFalse(user.is_just_partner())
     user.role = ROLE_PARTNER
     user.is_superuser = True
     user.save()
     self.assertFalse(user.is_just_partner())
     user = CtsUserFactory(role=ROLE_PARTNER, is_superuser=False)
     self.assertTrue(user.is_just_partner())
     manager_group = Group.objects.get(name=ROLE_MANAGER)
     user.groups.add(manager_group)
     self.assertFalse(user.is_just_partner())
开发者ID:aqueiroz,项目名称:CTS,代码行数:17,代码来源:test_models.py

示例3: TestReportList

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [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])
开发者ID:stbenjam,项目名称:CTS,代码行数:44,代码来源:test_views.py

示例4: test_save_sets_groups

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
 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,代码行数:22,代码来源:test_models.py

示例5: ReportTestMixin

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [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')
开发者ID:stbenjam,项目名称:CTS,代码行数:101,代码来源:test_views.py

示例6: CtsUserViewTest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(rsp.status_code, 200)
        user2 = CtsUser.objects.get(email=email)
        self.assertEqual(user.pk, user2.pk)
        self.assertEqual(user2.role, ROLE_PARTNER)

    def test_password_change(self):
        # Change a user's password
        old_password = '6pack'
        user = self.user
        old_email = user.email
        self.assertEqual(user, authenticate(email=old_email, password=old_password))
        url = reverse('edit_cts_user_modal', args=[user.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        # Submit the new object
        new_email = "[email protected]"
        new_password = 'foobar'
        data = {
            'name': 'test',
            'email': new_email,
            'mobile': '999',
            'skype': 'testtest',
            'role': ROLE_PARTNER,
            'password1': new_password,
            'password2': new_password,
        }
        rsp = self.client.post(url, data=data)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertEqual(rsp.status_code, 200)
        user = CtsUser.objects.get(pk=user.pk)
        self.assertEqual(user, authenticate(email=new_email, password=new_password))

    def test_delete(self):
        # Delete a user
        # Need to be logged in as one user, then delete another user
        user = CtsUserFactory()
        url = reverse('user_delete', args=[user.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertContains(rsp, 'Confirm')
        CtsUser.objects.get(pk=user.pk)
        # Now delete it!
        # Should really just change them to not active.
        rsp = self.client.post(url)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertRedirects(rsp, reverse('user_list'))
        user = CtsUser.objects.get(pk=user.pk)
        self.assertFalse(user.is_active)

    def test_edit_modal(self):
        user = self.user
        url = reverse('edit_cts_user_modal', kwargs={'pk': user.pk})
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertTemplateUsed(rsp, 'accounts/ctsuser_edit_modal.html')

    def test_reset_api_token_get(self):
        user = self.user
        url = reverse('reset_api_token', kwargs={'pk': user.pk})
        rsp = self.client.get(url)
        self.assertEqual(405, rsp.status_code)

    def test_reset_api_token_post(self):
        user = self.user
        original_token = user.auth_token.key
        url = reverse('reset_api_token', kwargs={'pk': user.pk})
        rsp = self.client.post(url)
        self.assertRedirects(rsp, reverse('user_list'))
        user = CtsUser.objects.get(pk=user.pk)
        self.assertNotEqual(original_token, user.auth_token.key)

    def test_reset_api_token_post_without_permission(self):
        self.user.role = ROLE_PARTNER  # least permissions
        self.user.save()
        user = CtsUserFactory()
        original_token = user.auth_token.key
        url = reverse('reset_api_token', kwargs={'pk': user.pk})
        rsp = self.client.post(url)
        self.assertEqual(403, rsp.status_code)
        user = CtsUser.objects.get(pk=user.pk)
        self.assertEqual(original_token, user.auth_token.key)

    def test_home_view_not_logged_in(self):
        self.client.logout()
        rsp = self.client.get(reverse('home'))
        self.assertRedirects(rsp, reverse('account_login'))

    def test_home_view_with_catalog_perms(self):
        self.user.role = ROLE_OFFICER
        self.user.save()
        rsp = self.client.get(reverse('home'))
        self.assertRedirects(rsp, reverse('catalog_list'))

    def test_home_view_without_catalog_perms(self):
        self.user.role = ROLE_PARTNER
        self.user.save()
        rsp = self.client.get(reverse('home'))
        self.assertRedirects(rsp, reverse('reports_list'))
开发者ID:aqueiroz,项目名称:CTS,代码行数:104,代码来源:test_views.py

示例7: DonorCodeViewTest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
class DonorCodeViewTest(TestCase):
    @classmethod
    def setUpClass(cls):
        super(DonorCodeViewTest, cls).setUpClass()
        bootstrap_permissions()

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

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

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

    def test_list(self):
        donorcode = DonorCodeT1Factory()
        rsp = self.client.get(reverse('donorcode_list'))
        self.assertEqual(200, rsp.status_code)
        self.assertContains(rsp, donorcode.code, msg_prefix=rsp.content.decode('utf-8'))

    def test_create(self):
        # Create a donorcode
        # Get the form page
        url = reverse('new_donorcode_modal')
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('form', rsp.context)
        # Submit the new object
        data = {
            'code': 'test',
            'donor_code_type': 't1',
        }
        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)
        DonorCode.objects.get(code='test')

    def test_update(self):
        # Update a donorcode
        donorcode = DonorCodeT1Factory()
        url = reverse('edit_donorcode_modal', args=[donorcode.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        # Submit the new object
        code = "edited"
        data = {
            'code': code,
            'donor_code_type': 't1',
        }
        rsp = self.client.post(url, data=data)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertEqual(rsp.status_code, 200)
        donorcode2 = DonorCode.objects.get(code=code)
        self.assertEqual(donorcode.pk, donorcode2.pk)

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

    def test_edit_modal(self):
        donorcode = DonorCodeT1Factory()
        url = reverse('edit_donorcode_modal', kwargs={'pk': donorcode.pk})
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertTemplateUsed(rsp, 'catalog/donorcode_edit_modal.html')
开发者ID:aqueiroz,项目名称:CTS,代码行数:91,代码来源:test_views.py

示例8: DonorViewTest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
class DonorViewTest(TestCase):
    @classmethod
    def setUpClass(cls):
        super(DonorViewTest, cls).setUpClass()
        bootstrap_permissions()

    def setUp(self):
        super(DonorViewTest, self).setUp()
        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('donor_list'))
        expected_url = reverse('account_login') + '?next=' + reverse('donor_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('donor_list'))
        expected_url = reverse('account_login') + '?next=' + reverse('donor_list')
        self.assertRedirects(rsp, expected_url)

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

    def test_create(self):
        # Create a donor
        # Get the form page
        url = reverse('new_donor_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)
        Donor.objects.get(name='test')

    def test_update(self):
        # Update a donor
        donor = DonorFactory()
        url = reverse('edit_donor_modal', args=[donor.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)
        donor2 = Donor.objects.get(name=name)
        self.assertEqual(donor.pk, donor2.pk)

    def test_update_and_create_new_codes(self):
        # Update a donor, create some new codes, and add them to the donor
        donor = DonorFactory()
        url = reverse('edit_donor_modal', args=[donor.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        t1_codeA = DonorCode.objects.create(code='t1A', donor_code_type=DonorCode.T1)
        t1_codeB = DonorCode.objects.create(code='t1B', donor_code_type=DonorCode.T1)
        t3_codeA = DonorCode.objects.create(code='t1A', donor_code_type=DonorCode.T3)
        # Submit the new object
        name = "edited"
        data = {
            'name': name,
            't1_codes_1': [t1_codeA.pk, t1_codeB.pk],
            'new_t1_codes': 'New code C, t1A',
            't3_codes_1': [t3_codeA.pk],
        }
        rsp = self.client.post(url, data=data)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertEqual(rsp.status_code, 200)
        donor2 = Donor.objects.get(name=name)
        self.assertEqual(donor.pk, donor2.pk)
        code_c = DonorCode.objects.get(code='New code C', donor_code_type=DonorCode.T1)
        self.assertIn(code_c, donor2.t1_codes.all())
        self.assertIn(t1_codeA, donor2.t1_codes.all())
        self.assertIn(t3_codeA, donor2.t3_codes.all())

    def test_delete(self):
        # Delete a donor
        donor = DonorFactory()
        url = reverse('donor_delete', args=[donor.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
#.........这里部分代码省略.........
开发者ID:aqueiroz,项目名称:CTS,代码行数:103,代码来源:test_views.py

示例9: CategoryViewTest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
class CategoryViewTest(TestCase):
    @classmethod
    def setUpClass(cls):
        super(CategoryViewTest, cls).setUpClass()
        bootstrap_permissions()

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

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

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

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

    def test_create(self):
        # Create a category
        # Get the form page
        url = reverse('new_category_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)
        ItemCategory.objects.get(name='test')

    def test_update(self):
        # Update a category
        category = ItemCategoryFactory()
        url = reverse('edit_category_modal', args=[category.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)
        category2 = ItemCategory.objects.get(name=name)
        self.assertEqual(category.pk, category2.pk)

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

    def test_edit_modal(self):
        category = ItemCategoryFactory()
        url = reverse('edit_category_modal', kwargs={'pk': category.pk})
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertTemplateUsed(rsp, 'catalog/category_edit_modal.html')
开发者ID:aqueiroz,项目名称:CTS,代码行数:89,代码来源:test_views.py

示例10: CatalogViewTest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
class CatalogViewTest(TestCase):
    @classmethod
    def setUpClass(cls):
        super(CatalogViewTest, cls).setUpClass()
        bootstrap_permissions()

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

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

    def test_role_required(self):
        # Need OFFICER to work with catalog
        self.user.role = ROLE_PARTNER
        self.user.save()
        rsp = self.client.get(reverse('catalog_list'))
        expected_url = reverse('account_login') + '?next=' + reverse('catalog_list')
        self.assertRedirects(rsp, expected_url)

    def test_list(self):
        cat = ItemCategoryFactory()
        description = "The meow of a cat"
        CatalogItemFactory(item_category=cat, description=description)
        rsp = self.client.get(reverse('catalog_list'))
        self.assertEqual(200, rsp.status_code)
        self.assertContains(rsp, description, msg_prefix=rsp.content.decode('utf-8'))

    def test_create(self):
        # Create an item
        ItemCategoryFactory(name="horse")
        ItemCategoryFactory(name="snowcat")
        cat = ItemCategoryFactory(name="cat")
        ItemCategoryFactory(name="catapult")
        description = "The meow of a cat"
        # Get the form page
        url = reverse('new_catalog_item_modal')
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('form', rsp.context)
        # Submit the new object
        data = {
            'item_code': '007',
            'description': description,
            'unit': 'purr',
            'weight': str(1.005),
            'price_local': '1.23',
            'price_usd': '4.072',
            'item_category': cat.name.upper(),
        }
        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)
        item = CatalogItem.objects.get(description=description)
        self.assertEqual(cat, item.item_category)
        self.assertEqual('007', item.item_code)
        self.assertEqual(1.005, item.weight)
        self.assertEqual(Decimal('4.072'), item.price_usd)

    def test_update(self):
        # Update an item
        cat = ItemCategoryFactory()
        description = "The meow of a cat"
        item = CatalogItemFactory(item_category=cat, description=description)
        url = reverse('edit_catalog_item_modal', args=[item.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
        # Submit the new object
        description2 = "The bark of a dog"
        data = {
            'item_code': item.item_code,
            'description': description2,
            'unit': 'purr',
            'weight': str(1.005),
            'price_local': '1.23',
            'price_usd': '4.07',
            'item_category': cat.pk,
            'quantity': 3,
        }
        rsp = self.client.post(url, data=data)
        if rsp.status_code == 400:
            self.fail(rsp.context['form'].errors)
        self.assertEqual(rsp.status_code, 200)
        item2 = CatalogItem.objects.get(description=description2)
        self.assertEqual(item.pk, item2.pk)

    def test_delete(self):
        # Delete an item
        cat = ItemCategoryFactory()
        description = "The meow of a cat"
        item = CatalogItemFactory(item_category=cat, description=description)
        url = reverse('catalog_delete', args=[item.pk])
        rsp = self.client.get(url)
        self.assertEqual(200, rsp.status_code)
#.........这里部分代码省略.........
开发者ID:aqueiroz,项目名称:CTS,代码行数:103,代码来源:test_views.py

示例11: TransporterViewTest

# 需要导入模块: from accounts.tests.factories import CtsUserFactory [as 别名]
# 或者: from accounts.tests.factories.CtsUserFactory import save [as 别名]
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,代码行数:87,代码来源:test_views.py


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