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


Python uuid.uuid4方法代码示例

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


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

示例1: test_object_PUT_at_id

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_object_PUT_at_id(self):
        """Create object in collection using PUT at specific ID."""
        index = self.client.get("/{}".format(self.API_NAME))
        assert index.status_code == 200
        endpoints = json.loads(index.data.decode('utf-8'))
        for endpoint in endpoints:
            collection_name = "/".join(endpoints[endpoint].split(
                "/{}/".format(self.API_NAME))[1:])
            if collection_name in self.doc.collections:
                collection = self.doc.collections[collection_name]["collection"]
                class_ = self.doc.parsed_classes[collection.class_.title]["class"]
                class_methods = [x.method for x in class_.supportedOperation]
                dummy_object = gen_dummy_object(
                    collection.class_.title, self.doc)
                if "PUT" in class_methods:
                    dummy_object = gen_dummy_object(
                        collection.class_.title, self.doc)
                    put_response = self.client.put('{}/{}'.format(
                        endpoints[endpoint], uuid.uuid4()), data=json.dumps(dummy_object))
                    assert put_response.status_code == 201 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:22,代码来源:test_app.py

示例2: test_object_PUT_at_ids

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_object_PUT_at_ids(self):
        index = self.client.get("/{}".format(self.API_NAME))
        assert index.status_code == 200
        endpoints = json.loads(index.data.decode('utf-8'))
        for endpoint in endpoints:
            collection_name = "/".join(endpoints[endpoint].split(
                "/{}/".format(self.API_NAME))[1:])
            if collection_name in self.doc.collections:
                collection = self.doc.collections[collection_name]["collection"]
                class_ = self.doc.parsed_classes[collection.class_.title]["class"]
                class_methods = [x.method for x in class_.supportedOperation]
                data_ = {"data": list()}
                objects = list()
                ids = ""
                for index in range(3):
                    objects.append(gen_dummy_object(
                        collection.class_.title, self.doc))
                    ids = "{},".format(uuid.uuid4())
                data_["data"] = objects
                if "PUT" in class_methods:
                    put_response = self.client.put(
                        '{}/add/{}'.format(endpoints[endpoint], ids),
                        data=json.dumps(data_))
                    assert put_response.status_code == 201 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:26,代码来源:test_app.py

示例3: setUp

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def setUp(self):
        for class_ in self.doc.parsed_classes:
            class_title = self.doc.parsed_classes[class_]["class"].title
            dummy_obj = gen_dummy_object(class_title, self.doc)
            crud.insert(
                dummy_obj,
                id_=str(
                    uuid.uuid4()),
                session=self.session)
            # If it's a collection class then add an extra object so
            # we can test pagination thoroughly.
            if class_ in self.doc.collections:
                crud.insert(
                    dummy_obj,
                    id_=str(
                        uuid.uuid4()),
                    session=self.session)
        # Add two dummy modification records
        crud.insert_modification_record(method="POST",
                                        resource_url="", session=self.session)
        crud.insert_modification_record(method="DELETE",
                                        resource_url="", session=self.session) 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:24,代码来源:test_app.py

示例4: test_update

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_update(self):
        """Test CRUD update."""
        random_class = random.choice(self.doc_collection_classes)
        object_ = gen_dummy_object(random_class, self.doc)
        new_object = gen_dummy_object(random_class, self.doc)
        id_ = str(uuid.uuid4())
        insert_response = crud.insert(
            object_=object_, id_=id_, session=self.session)
        update_response = crud.update(
            id_=id_,
            type_=object_["@type"],
            object_=new_object,
            session=self.session,
            api_name="api")
        test_object = crud.get(id_=id_, type_=object_[
                               "@type"], session=self.session, api_name="api")
        assert isinstance(insert_response, str)
        assert isinstance(update_response, str)
        assert insert_response == update_response
        assert test_object["@id"].split("/")[-1] == id_ 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:22,代码来源:test_crud.py

示例5: test_delete

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_delete(self):
        """Test CRUD delete."""
        object_ = gen_dummy_object(random.choice(
            self.doc_collection_classes), self.doc)
        id_ = str(uuid.uuid4())
        insert_response = crud.insert(
            object_=object_, id_=id_, session=self.session)
        delete_response = crud.delete(
            id_=id_, type_=object_["@type"], session=self.session)
        assert isinstance(insert_response, str)
        response_code = None
        try:
            get_response = crud.get(
                id_=id_,
                type_=object_["@type"],
                session=self.session,
                api_name="api")
        except Exception as e:
            error = e.get_HTTP()
            response_code = error.code
        assert 404 == response_code 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:23,代码来源:test_crud.py

示例6: test_delete_type

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_delete_type(self):
        """Test CRUD delete when wrong/undefined class is given."""
        object_ = gen_dummy_object(random.choice(
            self.doc_collection_classes), self.doc)
        id_ = str(uuid.uuid4())
        insert_response = crud.insert(
            object_=object_, id_=id_, session=self.session)
        assert isinstance(insert_response, str)
        assert insert_response == id_
        response_code = None
        try:
            delete_response = crud.delete(
                id_=id_, type_="otherClass", session=self.session)
        except Exception as e:
            error = e.get_HTTP()
            response_code = error.code
        assert 400 == response_code 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:19,代码来源:test_crud.py

示例7: test_delete_id

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_delete_id(self):
        """Test CRUD delete when wrong/undefined ID is given."""
        object_ = gen_dummy_object(random.choice(
            self.doc_collection_classes), self.doc)
        id_ = str(uuid.uuid4())
        insert_response = crud.insert(
            object_=object_, id_=id_, session=self.session)
        response_code = None
        try:
            delete_response = crud.delete(
                id_=999, type_=object_["@type"], session=self.session)
        except Exception as e:
            error = e.get_HTTP()
            response_code = error.code
        assert 404 == response_code
        assert isinstance(insert_response, str)
        assert insert_response == id_ 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:19,代码来源:test_crud.py

示例8: test_delete_ids

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_delete_ids(self):
        objects = list()
        ids = "{},{}".format(str(uuid.uuid4()), str(uuid.uuid4()))
        for index in range(len(ids.split(','))):
            object = gen_dummy_object(random.choice(
                self.doc_collection_classes), self.doc)
            objects.append(object)
        insert_response = crud.insert_multiple(objects_=objects,
                                               session=self.session, id_=ids)
        delete_response = crud.delete_multiple(
            id_=ids, type_=objects[0]["@type"], session=self.session)

        response_code = None
        id_list = ids.split(',')
        try:
            for index in range(len(id_list)):
                get_response = crud.get(
                    id_=id_list[index],
                    type_=objects[index]["@type"],
                    session=self.session,
                    api_name="api")
        except Exception as e:
            error = e.get_HTTP()
            response_code = error.code
        assert 404 == response_code 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:27,代码来源:test_crud.py

示例9: test_build_data_insert_iwth_collected_date

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_build_data_insert_iwth_collected_date(self, blank_state):
        """Test that build data can be inserted specifying collection date."""
        build_data_fields = {
            'node_name': 'foo',
            'generator': 'hello_world',
            'data_format': 'text/plain',
            'data_element': 'Hello World!',
            'task_id': uuid.uuid4(),
            'collected_date': datetime.utcnow(),
        }

        build_data = objects.BuildData(**build_data_fields)

        result = blank_state.post_build_data(build_data)

        assert result 
开发者ID:airshipit,项目名称:drydock,代码行数:18,代码来源:test_postgres_builddata.py

示例10: test_build_data_select

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_build_data_select(self, blank_state):
        """Test that build data can be deserialized from the database."""
        build_data_fields = {
            'node_name': 'foo',
            'generator': 'hello_world',
            'data_format': 'text/plain',
            'data_element': 'Hello World!',
            'task_id': uuid.uuid4(),
            'collected_date': datetime.utcnow(),
        }

        build_data = objects.BuildData(**build_data_fields)

        result = blank_state.post_build_data(build_data)

        assert result

        bd_list = blank_state.get_build_data()

        assert len(bd_list) == 1

        assert bd_list[0].to_dict() == build_data.to_dict() 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:test_postgres_builddata.py

示例11: test_maas_fabric

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_maas_fabric(self):
        client_config = config.DrydockConfig.node_driver['maasdriver']

        maas_client = client.MaasRequestFactory(client_config['api_url'],
                                                client_config['api_key'])

        fabric_name = str(uuid.uuid4())

        fabric_list = maas_fabric.Fabrics(maas_client)
        fabric_list.refresh()

        test_fabric = maas_fabric.Fabric(
            maas_client, name=fabric_name, description='Test Fabric')
        test_fabric = fabric_list.add(test_fabric)

        assert test_fabric.name == fabric_name
        assert test_fabric.resource_id is not None

        query_fabric = maas_fabric.Fabric(
            maas_client, resource_id=test_fabric.resource_id)
        query_fabric.refresh()

        assert query_fabric.name == test_fabric.name 
开发者ID:airshipit,项目名称:drydock,代码行数:25,代码来源:test_maasdriver_network.py

示例12: test_process_request_user

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def test_process_request_user(self):
        ''' AuthMiddleware is expected to correctly identify the headers
            added to an authenticated request by keystonemiddleware in a
            PasteDeploy configuration
        '''

        req_env = TestAuthMiddleware.ks_user_env

        project_id = str(uuid.uuid4().hex)
        req_env['HTTP_X_PROJECT_ID'] = project_id
        user_id = str(uuid.uuid4().hex)
        req_env['HTTP_X_USER_ID'] = user_id
        token = str(uuid.uuid4().hex)
        req_env['HTTP_X_AUTH_TOKEN'] = token

        middleware = AuthMiddleware()
        request = DrydockRequest(req_env)
        response = falcon.Response()

        middleware.process_request(request, response)

        assert request.context.authenticated
        assert request.context.user_id == user_id 
开发者ID:airshipit,项目名称:drydock,代码行数:25,代码来源:test_auth_middleware.py

示例13: session_id

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def session_id(self):
        """A unique session ID every time the user uses the workflow.

        .. versionadded:: 1.25

        The session ID persists while the user is using this workflow.
        It expires when the user runs a different workflow or closes
        Alfred.

        """
        if not self._session_id:
            from uuid import uuid4
            self._session_id = uuid4().hex
            self.setvar('_WF_SESSION_ID', self._session_id)

        return self._session_id 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:18,代码来源:workflow3.py

示例14: insert_calendar_token

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def insert_calendar_token(resource_type: str, semester: str, identifier: str) -> str:
    """
    生成日历令牌,写入数据库并返回字符串类型的令牌。此时的 last_used_time 是 NULL。

    :param resource_type: student/teacher
    :param semester: 学期字符串
    :param identifier: 学号或教工号
    :return: token 字符串
    """
    token = uuid.uuid4()

    with pg_conn_context() as conn, conn.cursor() as cursor:
        insert_query = """
        INSERT INTO calendar_tokens (type, identifier, semester, token, create_time)
            VALUES (%s,%s,%s,%s,%s);
        """
        cursor.execute(insert_query, (resource_type, identifier, semester, token, datetime.datetime.now()))
        conn.commit()
    return str(token) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:21,代码来源:calendar_token.py

示例15: _new_request

# 需要导入模块: import uuid [as 别名]
# 或者: from uuid import uuid4 [as 别名]
def _new_request(cls, identifier: str, verification_method: str, status: str, password: str = None) -> str:
        """
        新增一条注册请求

        :param identifier: 学号/教工号
        :param verification_method: password or email
        :param status: status of the request
        :param password: if register by password, fill everyclass password here
        :return: the `request_id`
        """
        if verification_method not in (cls.METHOD_PASSWORD, cls.METHOD_EMAIL):
            raise ValueError("verification_method must be one of email and password")

        request_id = uuid.uuid4()

        extra_doc = {}
        if password:
            extra_doc.update({"password": generate_password_hash(password)})

        request = VerificationRequest(request_id=request_id, identifier=identifier, method=verification_method,
                                      status=status, extra=extra_doc)
        db_session.add(request)
        db_session.commit()

        return str(request_id) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:27,代码来源:verification_request.py


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