def test_events(self, post_event):
        setup_trove_categories()

        # Create event
        cfg = {"trovecategories.enableediting": "true"}
        with h.push_config(config, **cfg):
            r = self.app.post("/categories/create/", params=dict(categoryname="test"))

        category_id = post_event.call_args[0][1]
        assert_true(isinstance(category_id, int))
        assert_equals(post_event.call_args[0][0], "trove_category_created")
        category = M.TroveCategory.query.get(trove_cat_id=category_id)

        # Update event
        category.fullname = "test2"
        session(M.TroveCategory).flush()
        edited_category_id = post_event.call_args[0][1]
        assert_true(isinstance(edited_category_id, int))
        assert_equals(edited_category_id, category_id)
        assert_equals(post_event.call_args[0][0], "trove_category_updated")

        # Delete event
        M.TroveCategory.delete(category)
        session(M.TroveCategory).flush()
        deleted_category_id = post_event.call_args[0][1]
        assert_true(isinstance(deleted_category_id, int))
        assert_equals(deleted_category_id, category_id)
        assert_equals(post_event.call_args[0][0], "trove_category_deleted")
    def test_events(self, post_event):
        setup_trove_categories()

        # Create event
        cfg = {'trovecategories.enableediting': 'true'}
        with h.push_config(config, **cfg):
            r = self.app.post('/categories/create/',
                              params=dict(categoryname='test'))

        category_id = post_event.call_args[0][1]
        assert_true(isinstance(category_id, int))
        assert_equals(post_event.call_args[0][0], 'trove_category_created')
        category = M.TroveCategory.query.get(trove_cat_id=category_id)

        # Update event
        category.fullname = 'test2'
        session(M.TroveCategory).flush()
        edited_category_id = post_event.call_args[0][1]
        assert_true(isinstance(edited_category_id, int))
        assert_equals(edited_category_id, category_id)
        assert_equals(post_event.call_args[0][0], 'trove_category_updated')

        # Delete event
        M.TroveCategory.delete(category)
        session(M.TroveCategory).flush()
        deleted_category_id = post_event.call_args[0][1]
        assert_true(isinstance(deleted_category_id, int))
        assert_equals(deleted_category_id, category_id)
        assert_equals(post_event.call_args[0][0], 'trove_category_deleted')
Exemple #3
0
    def test_commit_stats(self):
        setup_trove_categories()

        p = Project.query.get(shortname='u/test-user-2')
        topic = TroveCategory.query.get(shortname='scientific')
        commit_time = datetime.utcnow() + timedelta(-1)

        with mock.patch('allura.lib.plugin.session'):
            self.user.set_password('testpassword')
        self.user.claim_address('*****@*****.**')

        addr = M.EmailAddress.get(email='*****@*****.**')
        addr.confirmed = True

        repo_dir = pkg_resources.resource_filename(
            'forgeuserstats', 'tests/data')

        c.app.repo.fs_path = repo_dir
        c.app.repo.name = 'testgit.git'
        repo = c.app.repo
        repo.refresh()
        commit = repo.commit('HEAD')

        init_commits = self.user.stats.getCommits()
        assert init_commits['number'] == 4
        init_lmcommits = self.user.stats.getLastMonthCommits()
        assert init_lmcommits['number'] == 4

        p.trove_topic = [topic._id]
        self.user.stats.addCommit(commit, datetime.utcnow(), p)
        commits = self.user.stats.getCommits()
        assert commits['number'] == init_commits['number'] + 1
        assert commits['lines'] == init_commits['lines'] + 1
        lmcommits = self.user.stats.getLastMonthCommits()
        assert lmcommits['number'] == init_lmcommits['number'] + 1
        assert lmcommits['lines'] == init_lmcommits['lines'] + 1
        by_cat = self.user.stats.getCommitsByCategory()
        assert by_cat[topic]['number'] == 1
        assert by_cat[topic]['lines'] == 1
        lm_by_cat = self.user.stats.getLastMonthCommitsByCategory()
        assert lm_by_cat[topic]['number'] == 1
        assert lm_by_cat[topic]['lines'] == 1

        self.user.stats.addCommit(
            commit, datetime.utcnow() + timedelta(-40), p)
        commits = self.user.stats.getCommits()
        assert commits['number'] == init_commits['number'] + 2
        assert commits['lines'] == init_commits['lines'] + 2
        lmcommits = self.user.stats.getLastMonthCommits()
        assert lmcommits['number'] == init_lmcommits['number'] + 1
        assert lmcommits['lines'] == init_lmcommits['lines'] + 1
        by_cat = self.user.stats.getCommitsByCategory()
        assert by_cat[topic]['number'] == 2
        assert by_cat[topic]['lines'] == 2
        lm_by_cat = self.user.stats.getLastMonthCommitsByCategory()
        assert lm_by_cat[topic]['number'] == 1
        assert lm_by_cat[topic]['lines'] == 1
Exemple #4
0
    def test_commit_stats(self):
        setup_trove_categories()

        p = Project.query.get(shortname='u/test-user-2')
        topic = TroveCategory.query.get(shortname='scientific')
        commit_time = datetime.utcnow() + timedelta(-1)

        with mock.patch('allura.lib.plugin.session'):
            self.user.set_password('testpassword')
        self.user.claim_address('*****@*****.**')

        addr = M.EmailAddress.get(email='*****@*****.**')
        addr.confirmed = True

        repo_dir = pkg_resources.resource_filename(
            'forgeuserstats', 'tests/data')

        c.app.repo.fs_path = repo_dir
        c.app.repo.name = 'testgit.git'
        repo = c.app.repo
        repo.refresh()
        commit = repo.commit('HEAD')

        init_commits = self.user.stats.getCommits()
        assert init_commits['number'] == 4
        init_lmcommits = self.user.stats.getLastMonthCommits()
        assert init_lmcommits['number'] == 4

        p.trove_topic = [topic._id]
        self.user.stats.addCommit(commit, datetime.utcnow(), p)
        commits = self.user.stats.getCommits()
        assert commits['number'] == init_commits['number'] + 1
        assert commits['lines'] == init_commits['lines'] + 1
        lmcommits = self.user.stats.getLastMonthCommits()
        assert lmcommits['number'] == init_lmcommits['number'] + 1
        assert lmcommits['lines'] == init_lmcommits['lines'] + 1
        by_cat = self.user.stats.getCommitsByCategory()
        assert by_cat[topic]['number'] == 1
        assert by_cat[topic]['lines'] == 1
        lm_by_cat = self.user.stats.getLastMonthCommitsByCategory()
        assert lm_by_cat[topic]['number'] == 1
        assert lm_by_cat[topic]['lines'] == 1

        self.user.stats.addCommit(
            commit, datetime.utcnow() + timedelta(-40), p)
        commits = self.user.stats.getCommits()
        assert commits['number'] == init_commits['number'] + 2
        assert commits['lines'] == init_commits['lines'] + 2
        lmcommits = self.user.stats.getLastMonthCommits()
        assert lmcommits['number'] == init_lmcommits['number'] + 1
        assert lmcommits['lines'] == init_lmcommits['lines'] + 1
        by_cat = self.user.stats.getCommitsByCategory()
        assert by_cat[topic]['number'] == 2
        assert by_cat[topic]['lines'] == 2
        lm_by_cat = self.user.stats.getLastMonthCommitsByCategory()
        assert lm_by_cat[topic]['number'] == 1
        assert lm_by_cat[topic]['lines'] == 1
Exemple #5
0
    def test_skills(self):
        setup_trove_categories()
        # Add a skill
        skill_cat = M.TroveCategory.query.get(show_as_skill=True)
        level = 'low'
        comment = 'test comment'
        result = self.app.get('/auth/user_info/skills/')
        r = self.app.post('/auth/user_info/skills/save_skill',
                          params=dict(
                              level=level,
                              comment=comment,
                              selected_skill=str(skill_cat.trove_cat_id)))
        user = M.User.query.get(username='******')
        skilldict = dict(category_id=skill_cat._id,
                         comment=comment, level=level)
        assert len(user.skills) == 1 and skilldict in user.skills

        # Add again the same skill
        level = 'medium'
        comment = 'test comment 2'
        result = self.app.get('/auth/user_info/skills/')
        r = self.app.post('/auth/user_info/skills/save_skill',
                          params=dict(
                              level=level,
                              comment=comment,
                              selected_skill=str(skill_cat.trove_cat_id)))
        user = M.User.query.get(username='******')
        skilldict = dict(category_id=skill_cat._id,
                         comment=comment, level=level)
        assert len(user.skills) == 1 and skilldict in user.skills

        # Add an invalid skill
        level2 = 'not a level'
        comment2 = 'test comment 2'
        r = self.app.post('/auth/user_info/skills/save_skill',
                          params=dict(
                              level=level2,
                              comment=comment2,
                              selected_skill=str(skill_cat.trove_cat_id)))
        user = M.User.query.get(username='******')
        # Check that everything is as it was before
        assert len(user.skills) == 1 and skilldict in user.skills

        # Remove a skill
        self.app.get('/auth/user_info/skills/')
        self.app.post('/auth/user_info/skills/remove_skill',
                      params=dict(
                          categoryid=str(skill_cat.trove_cat_id)))
        user = M.User.query.get(username='******')
        assert len(user.skills) == 0
Exemple #6
0
    def test_neighborhood_home(self):
        setup_trove_categories()
        # Install home app
        nb = M.Neighborhood.query.get(name='Adobe')
        p = nb.neighborhood_project
        with push_config(c, user=M.User.query.get(username='******')):
            p.install_app('home', 'home', 'Home', ordinal=0)

        response = self.app.get('/adobe/')
        projects = response.html.findAll('div', {'class': 'list card proj_icon'})
        assert_equal(len(projects), 2)
        cat_links = response.html.find('div', {'id': 'sidebar'}).findAll('ul')[1].findAll('li')
        assert len(cat_links) == 3, cat_links
        assert cat_links[0].find('a').get('href') == '/adobe/browse/clustering'
        assert cat_links[0].find('a').find('span').string == 'Clustering'
Exemple #7
0
    def test_neighborhood_home(self):
        setup_trove_categories()
        # Install home app
        nb = M.Neighborhood.query.get(name='Adobe')
        p = nb.neighborhood_project
        with push_config(c, user=M.User.query.get(username='******')):
            p.install_app('home', 'home', 'Home', ordinal=0)

        response = self.app.get('/adobe/')
        projects = response.html.findAll('div', {'class': 'list card proj_icon'})
        assert_equal(len(projects), 2)
        cat_links = response.html.find('div', {'id': 'sidebar'}).findAll('ul')[1].findAll('li')
        assert len(cat_links) == 3, cat_links
        assert cat_links[0].find('a').get('href') == '/adobe/browse/clustering'
        assert cat_links[0].find('a').find('span').string == 'Clustering'
Exemple #8
0
def test_filtering():
    # set up for test
    from random import choice
    setup_trove_categories()
    random_trove = choice(M.TroveCategory.query.find().all())
    test_project = M.Project.query.get(shortname='test')
    test_project_troves = getattr(test_project, 'trove_' + random_trove.type)
    test_project_troves.append(random_trove._id)
    ThreadLocalORMSession.flush_all()

    p_nbhd = M.Neighborhood.query.get(name='Projects')
    with h.push_config(c,
                       project=p_nbhd.neighborhood_project,
                       user=M.User.by_username('test-admin')):
        r = g.markdown_wiki.convert('[[projects category="%s"]]' %
                                    random_trove.fullpath)
        project_names = get_project_names(r)
        assert_equal([test_project.name], project_names)
Exemple #9
0
def test_filtering():
    # set up for test
    from random import choice
    setup_trove_categories()
    random_trove = choice(M.TroveCategory.query.find().all())
    test_project = M.Project.query.get(shortname='test')
    test_project_troves = getattr(test_project, 'trove_' + random_trove.type)
    test_project_troves.append(random_trove._id)
    ThreadLocalORMSession.flush_all()

    p_nbhd = M.Neighborhood.query.get(name='Projects')
    with h.push_config(c,
                       project=p_nbhd.neighborhood_project,
                       user=M.User.by_username('test-admin')):
        r = g.markdown_wiki.convert(
            '[[projects category="%s"]]' % random_trove.fullpath)
        project_names = get_project_names(r)
        assert_equal([test_project.name], project_names)
Exemple #10
0
    def test_create_artifact_stats(self):
        setup_trove_categories()

        p = Project.query.get(shortname='u/test-user-2')
        topic = TroveCategory.query.get(shortname='scientific')

        init_lm_art = self.user.stats.getLastMonthArtifacts()
        init_art = self.user.stats.getArtifacts()
        init_art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        init_art_by_type = self.user.stats.getArtifactsByType()
        init_lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()
        init_art_sci = self.user.stats.getArtifacts(category=topic._id)

        self.user.stats.addNewArtifact('Wiki', datetime.utcnow(), p)
        lm_art = self.user.stats.getLastMonthArtifacts()
        artifacts = self.user.stats.getArtifacts()
        art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        art_by_type = self.user.stats.getArtifactsByType()
        lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()

        assert lm_art['created'] == init_lm_art['created'] + 1
        assert lm_art['modified'] == init_lm_art['modified']
        assert artifacts['created'] == init_art['created'] + 1
        assert artifacts['modified'] == init_art['modified']
        assert art_wiki['created'] == init_art_wiki['created'] + 1
        assert art_wiki['modified'] == init_art_wiki['modified']
        assert art_by_type['Wiki'][
            'created'] == init_art_by_type['Wiki']['created'] + 1
        assert art_by_type['Wiki'][
            'modified'] == init_art_by_type['Wiki']['modified']
        assert lm_art_by_type['Wiki'][
            'created'] == init_lm_art_by_type['Wiki']['created'] + 1
        assert lm_art_by_type['Wiki'][
            'modified'] == init_lm_art_by_type['Wiki']['modified']

        # In that case, last month stats should not be changed
        new_date = datetime.utcnow() + timedelta(-32)
        self.user.stats.addNewArtifact('Wiki', new_date, p)
        lm_art = self.user.stats.getLastMonthArtifacts()
        artifacts = self.user.stats.getArtifacts()
        art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        art_by_type = self.user.stats.getArtifactsByType()
        lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()

        assert lm_art['created'] == init_lm_art['created'] + 1
        assert lm_art['modified'] == init_lm_art['modified']
        assert artifacts['created'] == init_art['created'] + 2
        assert artifacts['modified'] == init_art['modified']
        assert art_wiki['created'] == init_art_wiki['created'] + 2
        assert art_wiki['modified'] == init_art_wiki['modified']
        assert art_by_type['Wiki'][
            'created'] == init_art_by_type['Wiki']['created'] + 2
        assert art_by_type['Wiki'][
            'modified'] == init_art_by_type['Wiki']['modified']
        assert lm_art_by_type['Wiki'][
            'created'] == init_lm_art_by_type['Wiki']['created'] + 1
        assert lm_art_by_type['Wiki'][
            'modified'] == init_lm_art_by_type['Wiki']['modified']

        p.trove_topic = [topic._id]

        self.user.stats.addNewArtifact('Wiki', datetime.utcnow(), p)
        lm_art = self.user.stats.getLastMonthArtifacts()
        artifacts = self.user.stats.getArtifacts()
        art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        art_by_type = self.user.stats.getArtifactsByType()
        lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()
        art_sci = self.user.stats.getArtifacts(category=topic._id)
        art_by_cat = self.user.stats.getArtifactsByCategory(detailed=True)

        assert lm_art['created'] == init_lm_art['created'] + 2
        assert lm_art['modified'] == init_lm_art['modified']
        assert artifacts['created'] == init_art['created'] + 3
        assert artifacts['modified'] == init_art['modified']
        assert art_wiki['created'] == init_art_wiki['created'] + 3
        assert art_wiki['modified'] == init_art_wiki['modified']
        assert art_by_type['Wiki'][
            'created'] == init_art_by_type['Wiki']['created'] + 3
        assert art_by_type['Wiki'][
            'modified'] == init_art_by_type['Wiki']['modified']
        assert lm_art_by_type['Wiki'][
            'created'] == init_lm_art_by_type['Wiki']['created'] + 2
        assert lm_art_by_type['Wiki'][
            'modified'] == init_lm_art_by_type['Wiki']['modified']
        assert art_sci['created'] == init_art_sci['created'] + 1
        assert art_sci['modified'] == init_art_sci['modified']
        assert dict(messagetype='Wiki', created=1,
                    modified=0) in art_by_cat[topic]
        art_by_cat = self.user.stats.getArtifactsByCategory(detailed=False)
        assert art_by_cat[topic]['created'] == 1 and art_by_cat[
            topic]['modified'] == 0
Exemple #11
0
    def test_ticket_stats(self):
        setup_trove_categories()

        p = Project.query.get(shortname='u/test-user-2')
        topic = TroveCategory.query.get(shortname='scientific')
        create_time = datetime.utcnow() + timedelta(-5)

        init_lm_tickets_art = self.user.stats.getLastMonthArtifacts(
            art_type='Ticket')
        init_tickets_art = self.user.stats.getArtifacts(art_type='Ticket')
        init_tickets_sci_art = self.user.stats.getArtifacts(category=topic._id)
        init_tickets = self.user.stats.getTickets()
        init_lm_tickets = self.user.stats.getLastMonthTickets()

        self.user.stats.addNewArtifact('Ticket', create_time, p)
        lm_tickets_art = self.user.stats.getLastMonthArtifacts(
            art_type='Ticket')
        tickets_art = self.user.stats.getArtifacts(art_type='Ticket')
        tickets_sci_art = self.user.stats.getArtifacts(category=topic._id)

        assert lm_tickets_art['created'] == init_lm_tickets_art['created'] + 1
        assert lm_tickets_art['modified'] == init_lm_tickets_art['modified']
        assert tickets_art['created'] == init_tickets_art['created'] + 1
        assert tickets_art['modified'] == init_tickets_art['modified']
        assert tickets_sci_art['created'] == tickets_sci_art['created']
        assert tickets_sci_art['modified'] == tickets_sci_art['modified']

        p.trove_topic = [topic._id]

        self.user.stats.addAssignedTicket(create_time, p)
        tickets = self.user.stats.getTickets()
        lm_tickets = self.user.stats.getLastMonthTickets()

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked']
        assert tickets['solved'] == init_tickets['solved']
        assert tickets['averagesolvingtime'] is None
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved']
        assert lm_tickets['averagesolvingtime'] is None

        self.user.stats.addRevokedTicket(create_time + timedelta(-32), p)
        tickets = self.user.stats.getTickets()

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked'] + 1
        assert tickets['solved'] == init_tickets['solved']
        assert tickets['averagesolvingtime'] is None
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved']
        assert lm_tickets['averagesolvingtime'] is None

        self.user.stats.addClosedTicket(
            create_time, create_time + timedelta(1), p)
        tickets = self.user.stats.getTickets()
        lm_tickets = self.user.stats.getLastMonthTickets()

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked'] + 1
        assert tickets['solved'] == init_tickets['solved'] + 1

        solving_time = dict(seconds=0, minutes=0, days=1, hours=0)
        assert tickets['averagesolvingtime'] == solving_time
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved'] + 1
        assert lm_tickets['averagesolvingtime'] == solving_time

        p.trove_topic = []
        self.user.stats.addClosedTicket(
            create_time, create_time + timedelta(3), p)
        tickets = self.user.stats.getTickets()
        lm_tickets = self.user.stats.getLastMonthTickets()

        solving_time = dict(seconds=0, minutes=0, days=2, hours=0)

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked'] + 1
        assert tickets['solved'] == init_tickets['solved'] + 2
        assert tickets['averagesolvingtime'] == solving_time
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved'] + 2
        assert lm_tickets['averagesolvingtime'] == solving_time

        by_cat = self.user.stats.getTicketsByCategory()
        lm_by_cat = self.user.stats.getLastMonthTicketsByCategory()
        solving_time = dict(days=1, hours=0, minutes=0, seconds=0)

        assert by_cat[topic]['assigned'] == 1
        assert by_cat[topic]['revoked'] == 1
        assert by_cat[topic]['solved'] == 1
        assert by_cat[topic]['averagesolvingtime'] == solving_time
        assert lm_by_cat[topic]['assigned'] == 1
        assert lm_by_cat[topic]['revoked'] == 0
        assert lm_by_cat[topic]['solved'] == 1
        assert lm_by_cat[topic]['averagesolvingtime'] == solving_time
Exemple #12
0
    def test_create_artifact_stats(self):
        setup_trove_categories()

        p = Project.query.get(shortname='u/test-user-2')
        topic = TroveCategory.query.get(shortname='scientific')

        init_lm_art = self.user.stats.getLastMonthArtifacts()
        init_art = self.user.stats.getArtifacts()
        init_art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        init_art_by_type = self.user.stats.getArtifactsByType()
        init_lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()
        init_art_sci = self.user.stats.getArtifacts(category=topic._id)

        self.user.stats.addNewArtifact('Wiki', datetime.utcnow(), p)
        lm_art = self.user.stats.getLastMonthArtifacts()
        artifacts = self.user.stats.getArtifacts()
        art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        art_by_type = self.user.stats.getArtifactsByType()
        lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()

        assert lm_art['created'] == init_lm_art['created'] + 1
        assert lm_art['modified'] == init_lm_art['modified']
        assert artifacts['created'] == init_art['created'] + 1
        assert artifacts['modified'] == init_art['modified']
        assert art_wiki['created'] == init_art_wiki['created'] + 1
        assert art_wiki['modified'] == init_art_wiki['modified']
        assert art_by_type['Wiki'][
            'created'] == init_art_by_type['Wiki']['created'] + 1
        assert art_by_type['Wiki'][
            'modified'] == init_art_by_type['Wiki']['modified']
        assert lm_art_by_type['Wiki'][
            'created'] == init_lm_art_by_type['Wiki']['created'] + 1
        assert lm_art_by_type['Wiki'][
            'modified'] == init_lm_art_by_type['Wiki']['modified']

        # In that case, last month stats should not be changed
        new_date = datetime.utcnow() + timedelta(-32)
        self.user.stats.addNewArtifact('Wiki', new_date, p)
        lm_art = self.user.stats.getLastMonthArtifacts()
        artifacts = self.user.stats.getArtifacts()
        art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        art_by_type = self.user.stats.getArtifactsByType()
        lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()

        assert lm_art['created'] == init_lm_art['created'] + 1
        assert lm_art['modified'] == init_lm_art['modified']
        assert artifacts['created'] == init_art['created'] + 2
        assert artifacts['modified'] == init_art['modified']
        assert art_wiki['created'] == init_art_wiki['created'] + 2
        assert art_wiki['modified'] == init_art_wiki['modified']
        assert art_by_type['Wiki'][
            'created'] == init_art_by_type['Wiki']['created'] + 2
        assert art_by_type['Wiki'][
            'modified'] == init_art_by_type['Wiki']['modified']
        assert lm_art_by_type['Wiki'][
            'created'] == init_lm_art_by_type['Wiki']['created'] + 1
        assert lm_art_by_type['Wiki'][
            'modified'] == init_lm_art_by_type['Wiki']['modified']

        p.trove_topic = [topic._id]

        self.user.stats.addNewArtifact('Wiki', datetime.utcnow(), p)
        lm_art = self.user.stats.getLastMonthArtifacts()
        artifacts = self.user.stats.getArtifacts()
        art_wiki = self.user.stats.getArtifacts(art_type='Wiki')
        art_by_type = self.user.stats.getArtifactsByType()
        lm_art_by_type = self.user.stats.getLastMonthArtifactsByType()
        art_sci = self.user.stats.getArtifacts(category=topic._id)
        art_by_cat = self.user.stats.getArtifactsByCategory(detailed=True)

        assert lm_art['created'] == init_lm_art['created'] + 2
        assert lm_art['modified'] == init_lm_art['modified']
        assert artifacts['created'] == init_art['created'] + 3
        assert artifacts['modified'] == init_art['modified']
        assert art_wiki['created'] == init_art_wiki['created'] + 3
        assert art_wiki['modified'] == init_art_wiki['modified']
        assert art_by_type['Wiki'][
            'created'] == init_art_by_type['Wiki']['created'] + 3
        assert art_by_type['Wiki'][
            'modified'] == init_art_by_type['Wiki']['modified']
        assert lm_art_by_type['Wiki'][
            'created'] == init_lm_art_by_type['Wiki']['created'] + 2
        assert lm_art_by_type['Wiki'][
            'modified'] == init_lm_art_by_type['Wiki']['modified']
        assert art_sci['created'] == init_art_sci['created'] + 1
        assert art_sci['modified'] == init_art_sci['modified']
        assert dict(messagetype='Wiki', created=1,
                    modified=0) in art_by_cat[topic]
        art_by_cat = self.user.stats.getArtifactsByCategory(detailed=False)
        assert art_by_cat[topic]['created'] == 1 and art_by_cat[
            topic]['modified'] == 0
Exemple #13
0
    def test_ticket_stats(self):
        setup_trove_categories()

        p = Project.query.get(shortname='u/test-user-2')
        topic = TroveCategory.query.get(shortname='scientific')
        create_time = datetime.utcnow() + timedelta(-5)

        init_lm_tickets_art = self.user.stats.getLastMonthArtifacts(
            art_type='Ticket')
        init_tickets_art = self.user.stats.getArtifacts(art_type='Ticket')
        init_tickets_sci_art = self.user.stats.getArtifacts(category=topic._id)
        init_tickets = self.user.stats.getTickets()
        init_lm_tickets = self.user.stats.getLastMonthTickets()

        self.user.stats.addNewArtifact('Ticket', create_time, p)
        lm_tickets_art = self.user.stats.getLastMonthArtifacts(
            art_type='Ticket')
        tickets_art = self.user.stats.getArtifacts(art_type='Ticket')
        tickets_sci_art = self.user.stats.getArtifacts(category=topic._id)

        assert lm_tickets_art['created'] == init_lm_tickets_art['created'] + 1
        assert lm_tickets_art['modified'] == init_lm_tickets_art['modified']
        assert tickets_art['created'] == init_tickets_art['created'] + 1
        assert tickets_art['modified'] == init_tickets_art['modified']
        assert tickets_sci_art['created'] == tickets_sci_art['created']
        assert tickets_sci_art['modified'] == tickets_sci_art['modified']

        p.trove_topic = [topic._id]

        self.user.stats.addAssignedTicket(create_time, p)
        tickets = self.user.stats.getTickets()
        lm_tickets = self.user.stats.getLastMonthTickets()

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked']
        assert tickets['solved'] == init_tickets['solved']
        assert tickets['averagesolvingtime'] is None
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved']
        assert lm_tickets['averagesolvingtime'] is None

        self.user.stats.addRevokedTicket(create_time + timedelta(-32), p)
        tickets = self.user.stats.getTickets()

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked'] + 1
        assert tickets['solved'] == init_tickets['solved']
        assert tickets['averagesolvingtime'] is None
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved']
        assert lm_tickets['averagesolvingtime'] is None

        self.user.stats.addClosedTicket(
            create_time, create_time + timedelta(1), p)
        tickets = self.user.stats.getTickets()
        lm_tickets = self.user.stats.getLastMonthTickets()

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked'] + 1
        assert tickets['solved'] == init_tickets['solved'] + 1

        solving_time = dict(seconds=0, minutes=0, days=1, hours=0)
        assert tickets['averagesolvingtime'] == solving_time
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved'] + 1
        assert lm_tickets['averagesolvingtime'] == solving_time

        p.trove_topic = []
        self.user.stats.addClosedTicket(
            create_time, create_time + timedelta(3), p)
        tickets = self.user.stats.getTickets()
        lm_tickets = self.user.stats.getLastMonthTickets()

        solving_time = dict(seconds=0, minutes=0, days=2, hours=0)

        assert tickets['assigned'] == init_tickets['assigned'] + 1
        assert tickets['revoked'] == init_tickets['revoked'] + 1
        assert tickets['solved'] == init_tickets['solved'] + 2
        assert tickets['averagesolvingtime'] == solving_time
        assert lm_tickets['assigned'] == init_lm_tickets['assigned'] + 1
        assert lm_tickets['revoked'] == init_lm_tickets['revoked']
        assert lm_tickets['solved'] == init_lm_tickets['solved'] + 2
        assert lm_tickets['averagesolvingtime'] == solving_time

        by_cat = self.user.stats.getTicketsByCategory()
        lm_by_cat = self.user.stats.getLastMonthTicketsByCategory()
        solving_time = dict(days=1, hours=0, minutes=0, seconds=0)

        assert by_cat[topic]['assigned'] == 1
        assert by_cat[topic]['revoked'] == 1
        assert by_cat[topic]['solved'] == 1
        assert by_cat[topic]['averagesolvingtime'] == solving_time
        assert lm_by_cat[topic]['assigned'] == 1
        assert lm_by_cat[topic]['revoked'] == 0
        assert lm_by_cat[topic]['solved'] == 1
        assert lm_by_cat[topic]['averagesolvingtime'] == solving_time
 def test_project_template(self):
     setup_trove_categories()
     icon_url = 'file://' + \
         os.path.join(allura.__path__[0], 'nf', 'allura',
                      'images', 'neo-icon-set-454545-256x350.png')
     test_groups = [{
         "name": "Viewer",  # group will be created, all params are valid
         "permissions": ["read"],
         "usernames": ["user01"]
     }, {
         "name": "",  # group won't be created - invalid name
         "permissions": ["read"],
         "usernames": ["user01"]
     }, {
         "name": "TestGroup1",  # group won't be created - invalid perm name
         "permissions": ["foobar"],
         "usernames": ["user01"]
     }, {
         "name": "TestGroup2",  # will be created; 'inspect' perm ignored
         "permissions": ["read", "inspect"],
         "usernames": ["user01", "user02"]
     }, {
         "name": "TestGroup3",  # will be created with no users in group
         "permissions": ["admin"]
     }]
     r = self.app.post('/adobe/_admin/update', params=dict(name='Mozq1',
                                                           css='', homepage='# MozQ1!\n[Root]', project_template="""{
             "private":true,
             "icon":{
                 "url":"%s",
                 "filename":"icon.png"
             },
             "tools":{
                 "wiki":{
                     "label":"Wiki",
                     "mount_point":"wiki",
                     "options":{
                         "show_right_bar":false,
                         "show_left_bar":false,
                         "show_discussion":false,
                         "some_url": "http://foo.com/$shortname/"
                     },
                     "home_text":"My home text!"
                 },
                 "discussion":{"label":"Discussion","mount_point":"discussion"},
                 "blog":{"label":"News","mount_point":"news","options":{
                 "show_discussion":false
                 }},
                 "admin":{"label":"Admin","mount_point":"admin"}
             },
             "tool_order":["wiki","discussion","news","admin"],
             "labels":["mmi"],
             "trove_cats":{
                 "topic":[247],
                 "developmentstatus":[11]
             },
             "groups": %s
             }""" % (icon_url, json.dumps(test_groups))),
         extra_environ=dict(username='******'))
     r = self.app.post(
         '/adobe/register',
         params=dict(
             project_unixname='testtemp',
             project_name='Test Template',
             project_description='',
             neighborhood='Mozq1',
             private_project='off'),
         antispam=True,
         extra_environ=dict(username='******'),
         status=302).follow()
     p = M.Project.query.get(shortname='testtemp')
     # make sure the correct tools got installed in the right order
     top_nav = r.html.find('div', {'id': 'top_nav'})
     assert top_nav.contents[1].contents[1].contents[
         1]['href'] == '/adobe/testtemp/wiki/'
     assert 'Wiki' in top_nav.contents[
         1].contents[1].contents[1].contents[0]
     assert top_nav.contents[1].contents[3].contents[
         1]['href'] == '/adobe/testtemp/discussion/'
     assert 'Discussion' in top_nav.contents[
         1].contents[3].contents[1].contents[0]
     assert top_nav.contents[1].contents[5].contents[
         1]['href'] == '/adobe/testtemp/news/'
     assert 'News' in top_nav.contents[
         1].contents[5].contents[1].contents[0]
     assert top_nav.contents[1].contents[7].contents[
         1]['href'] == '/adobe/testtemp/admin/'
     assert 'Admin' in top_nav.contents[
         1].contents[7].contents[1].contents[0]
     # make sure project is private
     r = self.app.get(
         '/adobe/testtemp/wiki/',
         extra_environ=dict(username='******')).follow(extra_environ=dict(username='******'), status=200)
     r = self.app.get(
         '/adobe/testtemp/wiki/',
         extra_environ=dict(username='******'),
         status=302)
     # check the labels and trove cats
     r = self.app.get('/adobe/testtemp/admin/trove')
     assert 'mmi' in r
     assert 'Topic :: Communications :: Telephony' in r
     assert 'Development Status :: 5 - Production/Stable' in r
     # check the wiki text
     r = self.app.get('/adobe/testtemp/wiki/').follow()
     assert "My home text!" in r
     # check tool options
     opts = p.app_config('wiki').options
     assert_equal(False, opts.show_discussion)
     assert_equal(False, opts.show_left_bar)
     assert_equal(False, opts.show_right_bar)
     assert_equal("http://foo.com/testtemp/", opts.some_url)
     # check that custom groups/perms/users were setup correctly
     roles = p.named_roles
     for group in test_groups:
         name = group.get('name')
         permissions = group.get('permissions', [])
         usernames = group.get('usernames', [])
         if name in ('Viewer', 'TestGroup2', 'TestGroup3'):
             role = M.ProjectRole.by_name(name, project=p)
             # confirm role created in project
             assert role in roles
             for perm in permissions:
                 # confirm valid permissions added to role, and invalid
                 # permissions ignored
                 if perm in p.permissions:
                     assert M.ACE.allow(role._id, perm) in p.acl
                 else:
                     assert M.ACE.allow(role._id, perm) not in p.acl
             # confirm valid users received role
             for username in usernames:
                 user = M.User.by_username(username)
                 if user and user._id:
                     assert role in M.ProjectRole.by_user(
                         user, project=p).roles
         # confirm roles with invalid json data are not created
         if name in ('', 'TestGroup1'):
             assert name not in roles