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


Python Client.login方法代码示例

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


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

示例1: FormExportTest

# 需要导入模块: from django_digest.test import Client [as 别名]
# 或者: from django_digest.test.Client import login [as 别名]
class FormExportTest(TestCase):
    def setUp(self):
        self.app_id = 'kasdlfkjsldfkjsdlkjf'
        self.domain_name = 'form-export-test'
        self.domain = create_domain(self.domain_name)
        self.username = 'danny'
        self.couch_user = CommCareUser.create(self.domain_name, self.username,
                                              password='xxx')
        self.couch_user.save()
        self.client = Client()
        self.client.login(username=self.couch_user.username, password='xxx')
        self.url = reverse("receiver_post_with_app_id",
                           args=[self.domain_name, self.app_id])

        def post_it():
            f = StringIO(XML_DATA)
            f.name = 'form.xml'
            response = self.client.post(self.url, {'xml_submission_file': f})
        self.form1 = post_it()
        self.form2 = post_it()

        self.custom_export = FormExportSchema.wrap({
            'type': 'form',
            'app_id': self.app_id,
            'default_format': Format.JSON,
            'index': json.dumps([self.domain_name, XMLNS]),
            'tables': [{
                'index': '#',
                'display': 'Export',
                'columns': [{'index': 'form.name', 'display': 'Name'}],
            }]
        })

    def test_include_duplicates(self):

        self.custom_export.include_errors = True
        tmp, _ = self.custom_export.get_export_files()
        data = tmp.getvalue()
        data = json.loads(data)
        self.assertEqual(data['Export']['headers'], ['Name'])
        self.assertEqual(len(data['Export']['rows']), 2)

        self.custom_export.include_errors = False
        tmp, _ = self.custom_export.get_export_files()
        data = tmp.getvalue()
        data = json.loads(data)
        self.assertEqual(data['Export']['headers'], ['Name'])
        self.assertEqual(len(data['Export']['rows']), 1)
开发者ID:esoergel,项目名称:commcare-hq,代码行数:50,代码来源:test_form_export.py

示例2: test_pages

# 需要导入模块: from django_digest.test import Client [as 别名]
# 或者: from django_digest.test.Client import login [as 别名]
    def test_pages(self):
        """
        Confirm that all the groups/locations/users appear on the correct pages
        """
        client = Client()
        client.login(username=self.username, password=self.password)

        # expected_id_sets is a list of sets.
        # expected_id_sets is constructed such that
        # For option with index x yielded by the view:
        #   the option's id should be in expected_ids[x]
        expected_id_sets = [{"user_location"}, {"user_parent_location"}]

        for i in self.groups:
            expected_id_sets.append(self.group_ids)
        for i in self.locations:
            expected_id_sets.append(self.location_ids)
        for i in self.users:
            expected_id_sets.append(self.user_ids)

        page_size = 3  # using a small number because more pages will hopefully be more likely to reveal bugs
        expected_num_pages = int(math.ceil(len(expected_id_sets) / float(page_size)))
        for i in range(expected_num_pages):
            page = i + 1
            response = client.get(reverse(
                CallCenterOwnerOptionsView.url_name, args=[self.domain.name]),
                data={"page": page, "page_limit": page_size, "q": ""}
            )
            response_json = json.loads(response.content)
            self.assertEqual(response_json['total'], len(expected_id_sets))

            for item_index, item in enumerate(response_json['results']):
                id_ = item['id']
                option_index = ((page - 1) * page_size) + item_index
                self.assertTrue(
                    id_ in expected_id_sets[option_index],
                    "Unexpected item {} at index {}.".format(item, option_index)
                )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:40,代码来源:test_owner_options_view.py

示例3: FormExportTest

# 需要导入模块: from django_digest.test import Client [as 别名]
# 或者: from django_digest.test.Client import login [as 别名]
class FormExportTest(TestCase):
    def setUp(self):
        self.app_id = 'kasdlfkjsldfkjsdlkjf'
        self.domain_name = 'form-export-test'
        self.domain = create_domain(self.domain_name)
        self.username = 'danny'
        self.couch_user = CommCareUser.create(self.domain_name, self.username,
                                              password='xxx')
        self.couch_user.save()
        self.client = Client()
        self.client.login(username=self.couch_user.username, password='xxx')
        self.url = reverse("receiver_post_with_app_id",
                           args=[self.domain_name, self.app_id])
        self.custom_export = FormExportSchema.wrap({
            'type': 'form',
            'app_id': self.app_id,
            'default_format': Format.JSON,
            'index': json.dumps([self.domain_name, XMLNS]),
            'tables': [{
                'index': '#',
                'display': 'Export',
                'columns': [{'index': 'form.name', 'display': 'Name'}],
            }]
        })

    def tearDown(self):
        self.couch_user.delete()

    def post_it(self, user_id=None, form_id=XFORM_ID):
        user_id = user_id or self.couch_user._id
        f = StringIO(XML_DATA.format(
            user_id=user_id,
            xmlns=XMLNS,
            xform_id=form_id,
        ))
        f.name = 'form.xml'
        return self.client.post(self.url, {'xml_submission_file': f})

    def test_include_duplicates(self):
        self.post_it()
        self.post_it()

        self.custom_export.include_errors = True
        files = self.custom_export.get_export_files()
        data = json.loads(files.file.payload)
        self.assertEqual(data['Export']['headers'], ['Name'])
        self.assertEqual(len(data['Export']['rows']), 2)

        self.custom_export.include_errors = False
        files = self.custom_export.get_export_files()
        data = json.loads(files.file.payload)
        self.assertEqual(data['Export']['headers'], ['Name'])
        self.assertEqual(len(data['Export']['rows']), 1)

    def test_exclude_unknown_users(self):
        self.post_it(form_id='good', user_id=self.couch_user._id)
        files = self.custom_export.get_export_files()
        data = json.loads(files.file.payload)
        self.assertEqual(len(data['Export']['rows']), 1)

        # posting from a non-real user shouldn't update
        self.post_it(form_id='bad', user_id='notarealuser')
        files = self.custom_export.get_export_files()
        data = json.loads(files.file.payload)
        self.assertEqual(len(data['Export']['rows']), 1)

        # posting from the real user should update
        self.post_it(form_id='stillgood', user_id=self.couch_user._id)
        files = self.custom_export.get_export_files()
        data = json.loads(files.file.payload)
        self.assertEqual(len(data['Export']['rows']), 2)
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:73,代码来源:test_form_export.py

示例4: FormExportTest

# 需要导入模块: from django_digest.test import Client [as 别名]
# 或者: from django_digest.test.Client import login [as 别名]
class FormExportTest(TestCase):
    def setUp(self):
        self.app_id = "kasdlfkjsldfkjsdlkjf"
        self.domain_name = "form-export-test"
        self.domain = create_domain(self.domain_name)
        self.username = "danny"
        self.couch_user = CommCareUser.create(self.domain_name, self.username, password="xxx")
        self.couch_user.save()
        self.client = Client()
        self.client.login(username=self.couch_user.username, password="xxx")
        self.url = reverse("receiver_post_with_app_id", args=[self.domain_name, self.app_id])
        self.custom_export = FormExportSchema.wrap(
            {
                "type": "form",
                "app_id": self.app_id,
                "default_format": Format.JSON,
                "index": json.dumps([self.domain_name, XMLNS]),
                "tables": [{"index": "#", "display": "Export", "columns": [{"index": "form.name", "display": "Name"}]}],
            }
        )

    def tearDown(self):
        self.couch_user.delete()

    def post_it(self, user_id=None, form_id=XFORM_ID):
        user_id = user_id or self.couch_user._id
        f = StringIO(XML_DATA.format(user_id=user_id, xmlns=XMLNS, xform_id=form_id))
        f.name = "form.xml"
        return self.client.post(self.url, {"xml_submission_file": f})

    def test_include_duplicates(self):
        self.post_it()
        self.post_it()

        self.custom_export.include_errors = True
        tmp, _ = self.custom_export.get_export_files()
        data = json.loads(tmp.getvalue())
        self.assertEqual(data["Export"]["headers"], ["Name"])
        self.assertEqual(len(data["Export"]["rows"]), 2)

        self.custom_export.include_errors = False
        tmp, _ = self.custom_export.get_export_files()
        data = json.loads(tmp.getvalue())
        self.assertEqual(data["Export"]["headers"], ["Name"])
        self.assertEqual(len(data["Export"]["rows"]), 1)

    def test_exclude_unknown_users(self):
        self.post_it(form_id="good", user_id=self.couch_user._id)
        tmp, _ = self.custom_export.get_export_files()
        data = json.loads(tmp.getvalue())
        self.assertEqual(len(data["Export"]["rows"]), 1)

        # posting from a non-real user shouldn't update
        self.post_it(form_id="bad", user_id="notarealuser")
        tmp, _ = self.custom_export.get_export_files()
        data = json.loads(tmp.getvalue())
        self.assertEqual(len(data["Export"]["rows"]), 1)

        # posting from the real user should update
        self.post_it(form_id="stillgood", user_id=self.couch_user._id)
        tmp, _ = self.custom_export.get_export_files()
        data = json.loads(tmp.getvalue())
        self.assertEqual(len(data["Export"]["rows"]), 2)
开发者ID:rigambhir,项目名称:commcare-hq,代码行数:65,代码来源:test_form_export.py


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