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


Python ProjectFactory.add_tag方法代码示例

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


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

示例1: create_fake_conference_nodes

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
def create_fake_conference_nodes(n, endpoint):
    nodes = []
    for i in range(n):
        node = ProjectFactory(is_public=True)
        node.add_tag(endpoint, Auth(node.creator))
        node.save()
        nodes.append(node)
    return nodes
开发者ID:mattspitzer,项目名称:osf.io,代码行数:10,代码来源:test_conferences.py

示例2: create_fake_project

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name, is_registration):
    auth = Auth(user=creator)
    project_title = name if name else fake.science_sentence()
    if not is_registration:
        project = ProjectFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
    else:
        project = RegistrationFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
    project.set_privacy(privacy)
    for _ in range(n_users):
        contrib = create_fake_user()
        project.add_contributor(contrib, auth=auth)
    if isinstance(n_components, int):
        for _ in range(n_components):
            NodeFactory(project=project, title=fake.science_sentence(), description=fake.science_paragraph(),
                        creator=creator)
    elif isinstance(n_components, list):
        render_generations_from_node_structure_list(project, creator, n_components)
    for _ in range(n_tags):
        project.add_tag(fake.science_word(), auth=auth)
    if presentation_name is not None:
        project.add_tag(presentation_name, auth=auth)
        project.add_tag('poster', auth=auth)

    project.save()
    logger.info('Created project: {0}'.format(project.title))
    return project
开发者ID:545zhou,项目名称:osf.io,代码行数:28,代码来源:create_fakes.py

示例3: ApiSearchTestCase

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
class ApiSearchTestCase(ApiTestCase):

    def setUp(self):
        super(ApiSearchTestCase, self).setUp()

        self.user = AuthUserFactory()
        self.user_one = AuthUserFactory(fullname='Kanye Omari West')
        self.user_one.schools = [{
            'degree': 'English',
            'institution': 'Chicago State University'
        }]
        self.user_one.jobs = [{
            'title': 'Producer',
            'institution': 'GOOD Music, Inc.'
        }]
        self.user_one.save()

        self.user_two = AuthUserFactory(fullname='Chance The Rapper')

        self.project = ProjectFactory(title='The Life of Pablo', creator=self.user_one, is_public=True)
        self.project.set_description('Name one genius who ain\'t crazy', auth=Auth(self.user_one), save=True)
        self.project.add_tag('Yeezus', auth=Auth(self.user_one), save=True)

        self.project_two = ProjectFactory(title='Graduation', creator=self.user_one, is_public=True)
        self.private_project = ProjectFactory(title='Coloring Book', creator=self.user_two)

        self.component = NodeFactory(parent=self.project, title='Ultralight Beam', creator=self.user_two, is_public=True)
        self.component.set_description('This is my part, nobody else speak', auth=Auth(self.user_two), save=True)
        self.component.add_tag('trumpets', auth=Auth(self.user_two), save=True)

        self.component_two = NodeFactory(parent=self.project, title='Highlights', creator=self.user_one, is_public=True)
        self.private_component = NodeFactory(parent=self.project, title='Wavves', creator=self.user_one)

        self.file = utils.create_test_file(self.component, self.user_one, filename='UltralightBeam.mp3')
        self.file_two = utils.create_test_file(self.component_two, self.user_one, filename='Highlights.mp3')
        self.private_file = utils.create_test_file(self.private_component, self.user_one, filename='Wavves.mp3')

    def tearDown(self):
        super(ApiSearchTestCase, self).tearDown()
        search.delete_all()
开发者ID:alexschiller,项目名称:osf.io,代码行数:42,代码来源:test_views.py

示例4: create_fake_project

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
def create_fake_project(creator, n_users, privacy, n_components, name, n_tags, presentation_name):
    auth = Auth(user=creator)
    project_title = name if name else fake.science_sentence()
    project = ProjectFactory(title=project_title, description=fake.science_paragraph(), creator=creator)
    project.set_privacy(privacy)
    for _ in range(n_users):
        contrib = create_fake_user()
        project.add_contributor(contrib, auth=auth)
    for _ in range(n_components):
        NodeFactory(project=project, title=fake.science_sentence(), description=fake.science_paragraph(),
                    creator=creator)
    for _ in range(n_tags):
        project.add_tag(fake.science_word(), auth=auth)
    if presentation_name is not None:
        project.add_tag(presentation_name, auth=auth)
        project.add_tag('poster', auth=auth)

    project.save()
    logger.info('Created project: {0}'.format(project.title))
    return project
开发者ID:Alpani,项目名称:osf.io,代码行数:22,代码来源:create_fakes.py

示例5: TestPublicNodes

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
class TestPublicNodes(SearchTestCase):

    def setUp(self):
        super(TestPublicNodes, self).setUp()
        self.user = UserFactory(usename='Doug Bogie')
        self.title = 'Red Special'
        self.consolidate_auth = Auth(user=self.user)
        self.project = ProjectFactory(
            title=self.title,
            creator=self.user,
            is_public=True,
        )
        self.component = NodeFactory(
            parent=self.project,
            title=self.title,
            creator=self.user,
            is_public=True
        )
        self.registration = ProjectFactory(
            title=self.title,
            creator=self.user,
            is_public=True,
            is_registration=True
        )

    def test_make_private(self):
        """Make project public, then private, and verify that it is not present
        in search.
        """
        self.project.set_privacy('private')
        docs = query('category:project AND ' + self.title)['results']
        assert_equal(len(docs), 0)

        self.component.set_privacy('private')
        docs = query('category:component AND ' + self.title)['results']
        assert_equal(len(docs), 0)
        self.registration.set_privacy('private')
        docs = query('category:registration AND ' + self.title)['results']
        assert_equal(len(docs), 0)

    def test_public_parent_title(self):
        self.project.set_title('hello & world', self.consolidate_auth)
        self.project.save()
        docs = query('category:component AND ' + self.title)['results']
        assert_equal(len(docs), 1)
        assert_equal(docs[0]['parent_title'], 'hello & world')
        assert_true(docs[0]['parent_url'])

    def test_make_parent_private(self):
        """Make parent of component, public, then private, and verify that the
        component still appears but doesn't link to the parent in search.
        """
        self.project.set_privacy('private')
        docs = query('category:component AND ' + self.title)['results']
        assert_equal(len(docs), 1)
        assert_equal(docs[0]['parent_title'], '-- private project --')
        assert_false(docs[0]['parent_url'])

    def test_delete_project(self):
        """

        """
        self.component.remove_node(self.consolidate_auth)
        docs = query('category:component AND ' + self.title)['results']
        assert_equal(len(docs), 0)

        self.project.remove_node(self.consolidate_auth)
        docs = query('category:project AND ' + self.title)['results']
        assert_equal(len(docs), 0)

    def test_change_title(self):
        """

        """
        title_original = self.project.title
        self.project.set_title(
            'Blue Ordinary', self.consolidate_auth, save=True)

        docs = query('category:project AND ' + title_original)['results']
        assert_equal(len(docs), 0)

        docs = query('category:project AND ' + self.project.title)['results']
        assert_equal(len(docs), 1)

    def test_add_tags(self):

        tags = ['stonecoldcrazy', 'just a poor boy', 'from-a-poor-family']

        for tag in tags:
            docs = query('tags:"{}"'.format(tag))['results']
            assert_equal(len(docs), 0)
            self.project.add_tag(tag, self.consolidate_auth, save=True)

        for tag in tags:
            docs = query('tags:"{}"'.format(tag))['results']
            assert_equal(len(docs), 1)

    def test_remove_tag(self):

        tags = ['stonecoldcrazy', 'just a poor boy', 'from-a-poor-family']
#.........这里部分代码省略.........
开发者ID:PatrickEGorman,项目名称:osf.io,代码行数:103,代码来源:test_elastic.py

示例6: TestRegistrationFiltering

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
class TestRegistrationFiltering(ApiTestCase):

    def setUp(self):
        super(TestRegistrationFiltering, self).setUp()
        self.user_one = AuthUserFactory()
        self.user_two = AuthUserFactory()
        self.project_one = ProjectFactory(title="Project One", description='Two', is_public=True, creator=self.user_one, category='hypothesis')
        self.project_two = ProjectFactory(title="Project Two", description="One Three", is_public=True, creator=self.user_one)
        self.project_three = ProjectFactory(title="Three", is_public=True, creator=self.user_two)


        self.private_project_user_one = ProjectFactory(title="Private Project User One",
                                                       is_public=False,
                                                       creator=self.user_one)
        self.private_project_user_two = ProjectFactory(title="Private Project User Two",
                                                       is_public=False,
                                                       creator=self.user_two)

        self.project_one.add_tag('tag1', Auth(self.project_one.creator), save=False)
        self.project_one.add_tag('tag2', Auth(self.project_one.creator), save=False)
        self.project_one.save()
        self.project_two.add_tag('tag1', Auth(self.project_two.creator), save=True)
        self.project_two.save()

        self.project_one_reg = RegistrationFactory(creator=self.user_one, project=self.project_one, is_public=True)
        self.project_two_reg = RegistrationFactory(creator=self.user_one, project=self.project_two, is_public=True)
        self.project_three_reg = RegistrationFactory(creator=self.user_two, project=self.project_three, is_public=True)
        self.private_project_user_one_reg = RegistrationFactory(creator=self.user_one, project=self.private_project_user_one, is_public=False)
        self.private_project_user_two_reg = RegistrationFactory(creator=self.user_two, project=self.private_project_user_two, is_public=False)

        self.folder = FolderFactory()
        self.dashboard = DashboardFactory()

        self.url = "/{}registrations/".format(API_BASE)

    def tearDown(self):
        super(TestRegistrationFiltering, self).tearDown()
        Node.remove()

    def test_filtering_by_category(self):
        url = '/{}registrations/?filter[category]=hypothesis'.format(API_BASE)
        res = self.app.get(url, auth=self.user_one.auth)
        registration_json = res.json['data']
        ids = [each['id'] for each in registration_json]

        assert_in(self.project_one_reg._id, ids)
        assert_not_in(self.project_two_reg._id, ids)
        assert_not_in(self.project_three_reg._id, ids)
        assert_not_in(self.private_project_user_one_reg._id, ids)
        assert_not_in(self.private_project_user_two_reg._id, ids)

    def test_filtering_by_public(self):
        url = '/{}registrations/?filter[public]=false'.format(API_BASE)
        res = self.app.get(url, auth=self.user_one.auth)
        reg_json = res.json['data']

        # No public projects returned
        assert_false(
            any([each['attributes']['public'] for each in reg_json])
        )

        ids = [each['id'] for each in reg_json]
        assert_not_in(self.project_one_reg._id, ids)
        assert_not_in(self.project_two_reg._id, ids)

        url = '/{}registrations/?filter[public]=true'.format(API_BASE)
        res = self.app.get(url, auth=self.user_one.auth)
        reg_json = res.json['data']

        # No private projects returned
        assert_true(
            all([each['attributes']['public'] for each in reg_json])
        )

        ids = [each['id'] for each in reg_json]
        assert_in(self.project_one_reg._id, ids)
        assert_in(self.project_two_reg._id, ids)
        assert_in(self.project_three_reg._id, ids)
        assert_not_in(self.private_project_user_one_reg._id, ids)
        assert_not_in(self.private_project_user_two_reg._id, ids)

    def test_filtering_tags(self):

        # both project_one and project_two have tag1
        url = '/{}registrations/?filter[tags]={}'.format(API_BASE, 'tag1')

        res = self.app.get(url, auth=self.project_one.creator.auth)
        reg_json = res.json['data']

        ids = [each['id'] for each in reg_json]
        assert_in(self.project_one_reg._id, ids)
        assert_in(self.project_two_reg._id, ids)
        assert_not_in(self.project_three_reg._id, ids)
        assert_not_in(self.private_project_user_one_reg._id, ids)
        assert_not_in(self.private_project_user_two_reg._id, ids)

        # filtering two tags
        # project_one has both tags; project_two only has one
        url = '/{}registrations/?filter[tags]={}&filter[tags]={}'.format(API_BASE, 'tag1', 'tag2')

#.........这里部分代码省略.........
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:103,代码来源:test_registration_list.py

示例7: TestNodeLogList

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
class TestNodeLogList(ApiTestCase):
    def setUp(self):
        super(TestNodeLogList, self).setUp()
        self.user = AuthUserFactory()
        self.contrib = AuthUserFactory()
        self.creator = AuthUserFactory()
        self.user_auth = Auth(self.user)
        self.NodeLogFactory = ProjectFactory()
        self.pointer = ProjectFactory()

        self.private_project = ProjectFactory(is_public=False, creator=self.user)
        self.private_url = '/{}nodes/{}/logs/'.format(API_BASE, self.private_project._id)

        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        self.public_url = '/{}nodes/{}/logs/'.format(API_BASE, self.public_project._id)

    def tearDown(self):
        super(TestNodeLogList, self).tearDown()
        NodeLog.remove()

    def test_add_tag(self):
        user_auth = Auth(self.user)
        self.public_project.add_tag("Jeff Spies", auth=user_auth)
        assert_equal("tag_added", self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'tag_added')
        assert_equal("Jeff Spies", self.public_project.logs[OSF_LATEST].params['tag'])

    def test_remove_tag(self):
        user_auth = Auth(self.user)
        self.public_project.add_tag("Jeff Spies", auth=user_auth)
        assert_equal("tag_added", self.public_project.logs[OSF_LATEST].action)
        self.public_project.remove_tag("Jeff Spies", auth=self.user_auth)
        assert_equal("tag_removed", self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'tag_removed')
        assert_equal("Jeff Spies", self.public_project.logs[OSF_LATEST].params['tag'])

    def test_project_created(self):
        res = self.app.get(self.public_url)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(self.public_project.logs[OSF_FIRST].action, "project_created")
        assert_equal(self.public_project.logs[OSF_FIRST].action,res.json['data'][API_LATEST]['attributes']['action'])

    def test_log_create_on_public_project(self):
        res = self.app.get(self.public_url)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_datetime_equal(parse_date(res.json['data'][API_FIRST]['attributes']['date']),
                              self.public_project.logs[OSF_FIRST].date)
        assert_equal(res.json['data'][API_FIRST]['attributes']['action'], self.public_project.logs[OSF_FIRST].action)

    def test_log_create_on_private_project(self):
        res = self.app.get(self.private_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_datetime_equal(datetime.datetime.strptime(res.json['data'][API_FIRST]['attributes']['date'], "%Y-%m-%dT%H:%M:%S.%f"),
                              self.private_project.logs[OSF_FIRST].date)
        assert_equal(res.json['data'][API_FIRST]['attributes']['action'], self.private_project.logs[OSF_FIRST].action)

    def test_add_addon(self):
        self.public_project.add_addon('github', auth=self.user_auth)
        assert_equal('addon_added', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'addon_added')

    def test_project_add_remove_contributor(self):
        self.public_project.add_contributor(self.contrib, auth=self.user_auth)
        assert_equal('contributor_added', self.public_project.logs[OSF_LATEST].action)
        self.public_project.remove_contributor(self.contrib, auth=self.user_auth)
        assert_equal('contributor_removed', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'contributor_removed')
        assert_equal(res.json['data'][1]['attributes']['action'], 'contributor_added')

    def test_remove_addon(self):
        self.public_project.add_addon('github', auth=self.user_auth)
        assert_equal('addon_added', self.public_project.logs[OSF_LATEST].action)
        self.public_project.delete_addon('github', auth=self.user_auth)
        assert_equal('addon_removed', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'addon_removed')

    def test_add_pointer(self):
        self.public_project.add_pointer(self.pointer, auth=Auth(self.user), save=True)
        assert_equal('pointer_created', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
#.........这里部分代码省略.........
开发者ID:HalcyonChimera,项目名称:osf.io,代码行数:103,代码来源:test_node_logs.py

示例8: TestPublicNodes

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_tag [as 别名]
class TestPublicNodes(SearchTestCase):
    def setUp(self):
        super(TestPublicNodes, self).setUp()
        self.user = UserFactory(usename="Doug Bogie")
        self.title = "Red Special"
        self.consolidate_auth = Auth(user=self.user)
        self.project = ProjectFactory(title=self.title, creator=self.user, is_public=True)
        self.component = NodeFactory(parent=self.project, title=self.title, creator=self.user, is_public=True)
        self.registration = ProjectFactory(title=self.title, creator=self.user, is_public=True, is_registration=True)

    def test_make_private(self):
        """Make project public, then private, and verify that it is not present
        in search.
        """
        self.project.set_privacy("private")
        docs = query("category:project AND " + self.title)["results"]
        assert_equal(len(docs), 0)

        self.component.set_privacy("private")
        docs = query("category:component AND " + self.title)["results"]
        assert_equal(len(docs), 0)
        self.registration.set_privacy("private")
        docs = query("category:registration AND " + self.title)["results"]
        assert_equal(len(docs), 0)

    def test_public_parent_title(self):
        self.project.set_title("hello & world", self.consolidate_auth)
        self.project.save()
        docs = query("category:component AND " + self.title)["results"]
        assert_equal(len(docs), 1)
        assert_equal(docs[0]["parent_title"], "hello & world")
        assert_true(docs[0]["parent_url"])

    def test_make_parent_private(self):
        """Make parent of component, public, then private, and verify that the
        component still appears but doesn't link to the parent in search.
        """
        self.project.set_privacy("private")
        docs = query("category:component AND " + self.title)["results"]
        assert_equal(len(docs), 1)
        assert_equal(docs[0]["parent_title"], "-- private project --")
        assert_false(docs[0]["parent_url"])

    def test_delete_project(self):
        """

        """
        self.component.remove_node(self.consolidate_auth)
        docs = query("category:component AND " + self.title)["results"]
        assert_equal(len(docs), 0)

        self.project.remove_node(self.consolidate_auth)
        docs = query("category:project AND " + self.title)["results"]
        assert_equal(len(docs), 0)

    def test_change_title(self):
        """

        """
        title_original = self.project.title
        self.project.set_title("Blue Ordinary", self.consolidate_auth, save=True)

        docs = query("category:project AND " + title_original)["results"]
        assert_equal(len(docs), 0)

        docs = query("category:project AND " + self.project.title)["results"]
        assert_equal(len(docs), 1)

    def test_add_tags(self):

        tags = ["stonecoldcrazy", "just a poor boy", "from-a-poor-family"]

        for tag in tags:
            docs = query('tags:"{}"'.format(tag))["results"]
            assert_equal(len(docs), 0)
            self.project.add_tag(tag, self.consolidate_auth, save=True)

        for tag in tags:
            docs = query('tags:"{}"'.format(tag))["results"]
            assert_equal(len(docs), 1)

    def test_remove_tag(self):

        tags = ["stonecoldcrazy", "just a poor boy", "from-a-poor-family"]

        for tag in tags:
            self.project.add_tag(tag, self.consolidate_auth, save=True)
            self.project.remove_tag(tag, self.consolidate_auth, save=True)
            docs = query('tags:"{}"'.format(tag))["results"]
            assert_equal(len(docs), 0)

    def test_update_wiki(self):
        """Add text to a wiki page, then verify that project is found when
        searching for wiki text.

        """
        wiki_content = {"home": "Hammer to fall", "swag": "#YOLO"}
        for key, value in wiki_content.items():
            docs = query(value)["results"]
            assert_equal(len(docs), 0)
#.........这里部分代码省略.........
开发者ID:erinmayhood,项目名称:osf.io,代码行数:103,代码来源:test_elastic.py


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