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