incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefanoi...@apache.org
Subject [1/5] organization and organization stats
Date Wed, 03 Apr 2013 22:22:23 GMT
Updated Branches:
  refs/heads/si/5566 [created] aa1a90dbf


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/forgeorganizationstats/tests/test_model.py
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/forgeorganizationstats/tests/test_model.py b/ForgeOrganizationStats/forgeorganizationstats/tests/test_model.py
new file mode 100644
index 0000000..980ef7e
--- /dev/null
+++ b/ForgeOrganizationStats/forgeorganizationstats/tests/test_model.py
@@ -0,0 +1,396 @@
+import pkg_resources
+import unittest
+from datetime import datetime, timedelta
+
+from pylons import tmpl_context as c
+
+from alluratest.controller import setup_basic_test, setup_global_objects
+from allura.tests import decorators as td
+from allura.model import User, Project, TroveCategory
+from allura import model as M
+from forgeorganizationstats.model import OrganizationStats
+from forgeorganization.organization.model import Organization, Membership, ProjectInvolvement
+
+from forgegit.tests import with_git
+
+class TestUserStats(unittest.TestCase):
+
+    def setUp(self):
+        from allura.model import User
+
+        setup_basic_test()
+        setup_global_objects()
+        self.user1 = User.register(dict(username='test-new-user-1',
+            display_name='Test Stats 1'),
+            make_project=False)
+        c.user = self.user1
+        self.organization = Organization.register(
+            'testorg', 'Test Organization', 'For-profit business', self.user1)
+        self.user2 = User.register(dict(username='test-new-user-2',
+            display_name='Test Stats 2'),
+            make_project=False)
+        self.m1 = Membership.insert('Developer', 'active', 
+            self.organization._id, self.user1._id)
+        self.m2 = Membership.insert('Developer', 'active', 
+            self.organization._id, self.user2._id)
+        self.organization.project().add_user(self.user1, ['Admin'])
+        self.organization.project().add_user(self.user2, ['Admin'])
+
+        self.project = M.Project.query.get(shortname='test')
+        self.project.add_user(self.user1, ['Admin'])
+        self.project.add_user(self.user2, ['Admin'])
+        pi = ProjectInvolvement.insert('active', 'cooperation', 
+            self.organization._id, self.project._id)
+        c.user = self.user1
+
+    def test_init_values(self):
+        artifacts = self.organization.stats.getArtifacts()
+        tickets = self.organization.stats.getTickets()
+        commits = self.organization.stats.getCommits()
+        assert artifacts['created'] == 0
+        assert artifacts['modified'] == 0
+        assert tickets['assigned'] == 0
+        assert tickets['solved'] == 0
+        assert tickets['revoked'] == 0
+        assert tickets['averagesolvingtime'] is None
+        assert commits['number'] == 0
+        assert commits['lines'] == 0
+
+        lmartifacts = self.organization.stats.getLastMonthArtifacts()
+        lmtickets = self.organization.stats.getLastMonthTickets()
+        lmcommits = self.organization.stats.getLastMonthCommits()
+        assert lmartifacts['created'] == 0
+        assert lmartifacts['modified'] == 0
+        assert lmtickets['assigned'] == 0
+        assert lmtickets['solved'] == 0
+        assert lmtickets['revoked'] == 0
+        assert lmtickets['averagesolvingtime'] is None
+        assert lmcommits['number'] == 0
+        assert lmcommits['lines'] == 0
+
+    def test_create_artifact_stats(self):
+        p = self.project
+        topic = TroveCategory.query.get(shortname='scientific')
+
+        init_lm_art = self.organization.stats.getLastMonthArtifacts()
+        init_art = self.organization.stats.getArtifacts()
+        init_art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        init_art_by_type = self.organization.stats.getArtifactsByType()
+        init_lm_art_by_type = self.organization.stats.getLastMonthArtifactsByType()
+        init_art_sci = self.organization.stats.getArtifacts(category=topic._id)
+
+        if not init_art_by_type.get('Wiki'):
+            init_art_by_type['Wiki'] = {'created':0, 'modified':0}
+        if not init_lm_art_by_type.get('Wiki'):
+            init_lm_art_by_type['Wiki'] = {'created':0, 'modified':0}
+        self.organization.stats.addNewArtifact('Wiki', datetime.utcnow(), p)
+        lm_art = self.organization.stats.getLastMonthArtifacts()
+        artifacts = self.organization.stats.getArtifacts()
+        art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        art_by_type = self.organization.stats.getArtifactsByType()
+        lm_art_by_type = self.organization.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.organization.stats.addNewArtifact('Wiki', new_date, p)
+        lm_art = self.organization.stats.getLastMonthArtifacts()
+        artifacts = self.organization.stats.getArtifacts()
+        art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        art_by_type = self.organization.stats.getArtifactsByType()
+        lm_art_by_type = self.organization.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.organization.stats.addNewArtifact('Wiki', datetime.utcnow(), p)
+        lm_art = self.organization.stats.getLastMonthArtifacts()
+        artifacts = self.organization.stats.getArtifacts()
+        art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        art_by_type = self.organization.stats.getArtifactsByType()
+        lm_art_by_type = self.organization.stats.getLastMonthArtifactsByType()
+        art_sci = self.organization.stats.getArtifacts(category=topic._id)
+        art_by_cat = self.organization.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.organization.stats.getArtifactsByCategory(detailed=False)
+        assert art_by_cat[topic]['created'] == 1 and art_by_cat[topic]['modified'] == 0
+
+        lm_per_member = self.organization.stats.getLastMonthArtifactsPerMember()
+        assert lm_per_member['created'] == 1.0
+        assert lm_per_member['modified'] == 0.0
+
+    def test_modify_artifact_stats(self):
+        p = self.project
+        topic = TroveCategory.query.get(shortname='scientific')
+
+        init_lm_art = self.organization.stats.getLastMonthArtifacts()
+        init_art = self.organization.stats.getArtifacts()
+        init_art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        init_art_by_type = self.organization.stats.getArtifactsByType()
+        init_lm_art_by_type = self.organization.stats.getLastMonthArtifactsByType()
+        init_art_sci = self.organization.stats.getArtifacts(category=topic._id)
+        if not init_art_by_type.get('Wiki'):
+            init_art_by_type['Wiki'] = {'created':0, 'modified':0}
+        if not init_lm_art_by_type.get('Wiki'):
+            init_lm_art_by_type['Wiki'] = {'created':0, 'modified':0}
+
+        self.organization.stats.addModifiedArtifact('Wiki', datetime.utcnow(), p)
+        lm_art = self.organization.stats.getLastMonthArtifacts()
+        artifacts = self.organization.stats.getArtifacts()
+        art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        art_by_type = self.organization.stats.getArtifactsByType()
+        lm_art_by_type = self.organization.stats.getLastMonthArtifactsByType()
+
+        assert lm_art['created'] == init_lm_art['created']
+        assert lm_art['modified'] == init_lm_art['modified'] + 1
+        assert artifacts['created'] == init_art['created']
+        assert artifacts['modified'] == init_art['modified'] + 1
+        assert art_wiki['created'] == init_art_wiki['created']
+        assert art_wiki['modified'] == init_art_wiki['modified'] + 1
+        assert art_by_type['Wiki']['created'] == init_art_by_type['Wiki']['created']
+        assert art_by_type['Wiki']['modified'] == init_art_by_type['Wiki']['modified'] +
1
+        assert lm_art_by_type['Wiki']['created'] == init_lm_art_by_type['Wiki']['created']
+        assert lm_art_by_type['Wiki']['modified'] == init_lm_art_by_type['Wiki']['modified']
+ 1
+        
+        #In that case, last month stats should not be changed
+        new_date = datetime.utcnow() + timedelta(-32)
+        self.organization.stats.addModifiedArtifact('Wiki', new_date, p)
+        lm_art = self.organization.stats.getLastMonthArtifacts()
+        artifacts = self.organization.stats.getArtifacts()
+        art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        art_by_type = self.organization.stats.getArtifactsByType()
+        lm_art_by_type = self.organization.stats.getLastMonthArtifactsByType()
+
+        assert lm_art['created'] == init_lm_art['created'] 
+        assert lm_art['modified'] == init_lm_art['modified'] + 1
+        assert artifacts['created'] == init_art['created'] 
+        assert artifacts['modified'] == init_art['modified'] + 2
+        assert art_wiki['created'] == init_art_wiki['created']
+        assert art_wiki['modified'] == init_art_wiki['modified'] + 2
+        assert art_by_type['Wiki']['created'] == init_art_by_type['Wiki']['created']
+        assert art_by_type['Wiki']['modified'] == init_art_by_type['Wiki']['modified'] +
2
+        assert lm_art_by_type['Wiki']['created'] == init_lm_art_by_type['Wiki']['created']
+        assert lm_art_by_type['Wiki']['modified'] == init_lm_art_by_type['Wiki']['modified']
+ 1
+        
+        p.trove_topic = [topic._id]
+
+        self.organization.stats.addModifiedArtifact('Wiki', datetime.utcnow(), p)
+        lm_art = self.organization.stats.getLastMonthArtifacts()
+        artifacts = self.organization.stats.getArtifacts()
+        art_wiki = self.organization.stats.getArtifacts(art_type='Wiki')
+        art_by_type = self.organization.stats.getArtifactsByType()
+        lm_art_by_type = self.organization.stats.getLastMonthArtifactsByType()
+        art_sci = self.organization.stats.getArtifacts(category=topic._id)
+        art_by_cat = self.organization.stats.getArtifactsByCategory(detailed=True)
+
+        assert lm_art['created'] == init_lm_art['created'] 
+        assert lm_art['modified'] == init_lm_art['modified'] + 2
+        assert artifacts['created'] == init_art['created']
+        assert artifacts['modified'] == init_art['modified'] + 3
+        assert art_wiki['created'] == init_art_wiki['created']
+        assert art_wiki['modified'] == init_art_wiki['modified'] + 3
+        assert art_by_type['Wiki']['created'] == init_art_by_type['Wiki']['created'] 
+        assert art_by_type['Wiki']['modified'] == init_art_by_type['Wiki']['modified'] +
3
+        assert lm_art_by_type['Wiki']['created'] == init_lm_art_by_type['Wiki']['created']
+        assert lm_art_by_type['Wiki']['modified'] == init_lm_art_by_type['Wiki']['modified']
+2
+        assert art_sci['created'] == init_art_sci['created']
+        assert art_sci['modified'] == init_art_sci['modified'] + 1
+        assert dict(messagetype='Wiki', created=0, modified=1) in art_by_cat[topic]
+        art_by_cat = self.organization.stats.getArtifactsByCategory(detailed=False)
+        assert art_by_cat[topic]['created'] == 0 and art_by_cat[topic]['modified'] == 1
+
+        lm_per_member = self.organization.stats.getLastMonthArtifactsPerMember()
+        assert lm_per_member['created'] == 0.0
+        assert lm_per_member['modified'] == 1.0
+
+    def test_ticket_stats(self):
+        p = self.project
+        topic = TroveCategory.query.get(shortname='scientific')
+        create_time = datetime.utcnow() + timedelta(-5)
+
+        init_lm_tickets_art = self.organization.stats.getLastMonthArtifacts(art_type='Ticket')
+        init_tickets_art = self.organization.stats.getArtifacts(art_type='Ticket')
+        init_tickets_sci_art = self.organization.stats.getArtifacts(category=topic._id)
+        init_tickets = self.organization.stats.getTickets()
+        init_lm_tickets = self.organization.stats.getLastMonthTickets()
+
+        self.organization.stats.addNewArtifact('Ticket', create_time, p)
+        lm_tickets_art = self.organization.stats.getLastMonthArtifacts(art_type='Ticket')
+        tickets_art = self.organization.stats.getArtifacts(art_type='Ticket')
+        tickets_sci_art = self.organization.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.organization.stats.addAssignedTicket(create_time, p)
+        tickets = self.organization.stats.getTickets()
+        lm_tickets = self.organization.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.organization.stats.addRevokedTicket(create_time + timedelta(-32), p)
+        tickets = self.organization.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.organization.stats.addClosedTicket(create_time, create_time + timedelta(1),
p)
+        tickets = self.organization.stats.getTickets()
+        lm_tickets = self.organization.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.organization.stats.addClosedTicket(create_time, create_time + timedelta(3),
p)
+        tickets = self.organization.stats.getTickets()
+        lm_tickets = self.organization.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.organization.stats.getTicketsByCategory()
+        lm_by_cat = self.organization.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
+
+        lm_per_member = self.organization.stats.getLastMonthTicketsPerMember()
+        assert lm_per_member['assigned'] == 0.5
+        assert lm_per_member['solved'] == 1.0
+        assert lm_per_member['revoked'] == 0.0
+
+    @with_git
+    def test_commit_stats(self):
+        p = self.project
+        topic = TroveCategory.query.get(shortname='scientific')
+        commit_time = datetime.utcnow() + timedelta(-1)
+
+        self.user1.set_password('testpassword')
+        addr = M.EmailAddress.upsert('rcopeland@geek.net')
+        self.user1.claim_address('rcopeland@geek.net')
+        
+        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 = M.repo.Commit.query.get(_id=repo.heads[0]['object_id'])
+        commit.repo = repo
+
+        init_commits = self.organization.stats.getCommits()
+        assert init_commits['number'] == 4
+        init_lmcommits = self.organization.stats.getLastMonthCommits()
+        assert init_lmcommits['number'] == 4
+ 
+        lm_per_member = self.organization.stats.getLastMonthCommitsPerMember()
+        assert lm_per_member['number'] == 2.0
+
+        p.trove_topic = [topic._id]
+        self.organization.stats.addCommit(commit, datetime.utcnow(), p)
+        commits = self.organization.stats.getCommits()
+        assert commits['number'] == init_commits['number'] + 1
+        assert commits['lines'] == init_commits['lines'] + 1
+        lmcommits = self.organization.stats.getLastMonthCommits()
+        assert lmcommits['number'] == init_lmcommits['number'] + 1
+        assert lmcommits['lines'] == init_lmcommits['lines'] + 1
+        by_cat = self.organization.stats.getCommitsByCategory()
+        assert by_cat[topic]['number'] == 1
+        assert by_cat[topic]['lines'] == 1
+        lm_by_cat = self.organization.stats.getLastMonthCommitsByCategory()
+        assert lm_by_cat[topic]['number'] == 1
+        assert lm_by_cat[topic]['lines'] == 1
+
+        self.organization.stats.addCommit(commit, datetime.utcnow() + timedelta(-40), p)
+        commits = self.organization.stats.getCommits()
+        assert commits['number'] == init_commits['number'] + 2
+        assert commits['lines'] == init_commits['lines'] + 2
+        lmcommits = self.organization.stats.getLastMonthCommits()
+        assert lmcommits['number'] == init_lmcommits['number'] + 1
+        assert lmcommits['lines'] == init_lmcommits['lines'] + 1
+        by_cat = self.organization.stats.getCommitsByCategory()
+        assert by_cat[topic]['number'] == 2
+        assert by_cat[topic]['lines'] == 2
+        lm_by_cat = self.organization.stats.getLastMonthCommitsByCategory()
+        assert lm_by_cat[topic]['number'] == 1
+        assert lm_by_cat[topic]['lines'] == 1
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/forgeorganizationstats/tests/test_stats.py
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/forgeorganizationstats/tests/test_stats.py b/ForgeOrganizationStats/forgeorganizationstats/tests/test_stats.py
new file mode 100644
index 0000000..a6c10f5
--- /dev/null
+++ b/ForgeOrganizationStats/forgeorganizationstats/tests/test_stats.py
@@ -0,0 +1,283 @@
+import pkg_resources
+import unittest
+
+from pylons import app_globals as g
+from pylons import tmpl_context as c
+
+from alluratest.controller import TestController, setup_basic_test, setup_global_objects
+from allura.tests import decorators as td
+from allura.lib import helpers as h
+from allura import model as M
+
+from forgegit.tests import with_git
+from forgewiki import model as WM
+from forgetracker import model as TM
+from forgeorganization.organization.model import Organization, Membership, ProjectInvolvement
+
+from ming.orm.ormsession import ThreadLocalORMSession
+
+class TestStats(TestController):
+
+    def setUp(self):
+        super(TestStats, self).setUp()
+        self.user1 = M.User.by_username('test-user')
+        self.user2 = M.User.by_username('test-admin')
+        self.user3 = M.User.by_username('test-user-1')
+        self.organization = Organization.register(
+            'testorg', 'Test Organization', 'For-profit business', self.user1)
+        self.organization.project().add_user(self.user1, ['Admin'])
+        self.organization.project().add_user(self.user2, ['Admin'])
+
+        self.m1 = Membership.insert('Developer', 'closed', 
+            self.organization._id, self.user1._id)
+        self.m2 = Membership.insert('Developer', 'active', 
+            self.organization._id, self.user2._id)
+        self.m3 = Membership.insert('Developer', 'active', 
+            self.organization._id, self.user3._id)
+
+        self.project = M.Project.query.get(shortname='test')
+        self.project.add_user(self.user1, ['Admin'])
+        self.project.add_user(self.user2, ['Admin'])
+        self.project.add_user(self.user3, ['Admin'])
+        pi = ProjectInvolvement.insert('active', 'cooperation', 
+            self.organization._id, self.project._id)
+
+    @td.with_tool('test', 'wiki', mount_point='wiki', mount_label='wiki', username='test-admin')
+    def test_wiki_stats(self):
+
+        initial_artifacts = self.organization.stats.getArtifacts()
+        initial_wiki = self.organization.stats.getArtifacts(art_type="Wiki")
+
+        #Try to create a new page as a user enrolled in the organization which
+        #is developing the project
+        self.app.post('/wiki/newtestpage/update', 
+            params=dict(title='newtestpage', text='footext'),
+            extra_environ=dict(username=str(self.user2.username)))
+
+        artifacts = self.organization.stats.getArtifacts()
+        wiki = self.organization.stats.getArtifacts(art_type="Wiki")
+
+        assert artifacts['created'] == 1 + initial_artifacts['created']
+        assert artifacts['modified'] == initial_artifacts['modified']
+        assert wiki['created'] == 1 + initial_wiki['created']
+        assert wiki['modified'] == initial_wiki['modified']
+
+        #Try to create a new page as another user enrolled in the organization
+        #which is developing the project
+        self.app.post('/wiki/newtestpage2/update', 
+            params=dict(title='newtestpage2', text='footext2'),
+            extra_environ=dict(username=str(self.user3.username)))
+
+        artifacts = self.organization.stats.getArtifacts()
+        wiki = self.organization.stats.getArtifacts(art_type="Wiki")
+
+        assert artifacts['created'] == 2 + initial_artifacts['created']
+        assert artifacts['modified'] == initial_artifacts['modified']
+        assert wiki['created'] == 2 + initial_wiki['created']
+        assert wiki['modified'] == initial_wiki['modified']
+
+        #Try to edit a page as a user enrolled in the organization which
+        #is developing the project
+        self.app.post('/wiki/newtestpage2/update', 
+            params=dict(title='newtestpage2', text='newcontent'),
+            extra_environ=dict(username=str(self.user2.username)))
+
+        artifacts = self.organization.stats.getArtifacts()
+        wiki = self.organization.stats.getArtifacts(art_type="Wiki")
+
+        assert artifacts['created'] == 2 + initial_artifacts['created']
+        assert artifacts['modified'] == 1 + initial_artifacts['modified']
+        assert wiki['created'] == 2 + initial_wiki['created']
+        assert wiki['modified'] == 1 + initial_wiki['modified']
+
+        #Try to create a new page as a user whose enrollment within the 
+        #organization has been marked as closed
+        self.app.post('/wiki/newtestpage3/update', 
+            params=dict(title='newtestpage3', text='footext'),
+            extra_environ=dict(username=str(self.user1.username)))
+
+        artifacts = self.organization.stats.getArtifacts()
+        wiki = self.organization.stats.getArtifacts(art_type="Wiki")
+
+        assert artifacts['created'] == 2 + initial_artifacts['created']
+        assert artifacts['modified'] == 1 + initial_artifacts['modified']
+        assert wiki['created'] == 2 + initial_wiki['created']
+        assert wiki['modified'] == 1 + initial_wiki['modified']
+
+        #Try to edit an existing page as a user whose enrollment within the 
+        #organization has been marked as closed
+        self.app.post('/wiki/newtestpage/update', 
+            params=dict(title='newtestpage', text='footext2'),
+            extra_environ=dict(username=str(self.user1.username)))
+
+        artifacts = self.organization.stats.getArtifacts()
+        wiki = self.organization.stats.getArtifacts(art_type="Wiki")
+
+        assert artifacts['created'] == 2 + initial_artifacts['created']
+        assert artifacts['modified'] == 1 + initial_artifacts['modified']
+        assert wiki['created'] == 2 + initial_wiki['created']
+        assert wiki['modified'] == 1 + initial_wiki['modified']
+
+    @td.with_tool('test', 'tickets', mount_point='tickets', mount_label='tickets', username='test-admin')
+    def test_tracker_stats(self):
+
+        initial_tickets = self.organization.stats.getTickets()
+        initial_tickets_artifacts = self.organization.stats.getArtifacts(art_type="Ticket")
+
+        r = self.app.post('/tickets/save_ticket', 
+            params={'ticket_form.summary':'footext2',
+                    'ticket_form.assigned_to' : str(self.user2.username)},
+            extra_environ=dict(username=str(self.user2.username)))
+
+        tickets = self.organization.stats.getTickets()
+        tickets_artifacts = self.organization.stats.getArtifacts(art_type="Ticket")
+
+        assert tickets['assigned'] == initial_tickets['assigned'] + 1
+        assert tickets['solved'] == initial_tickets['solved']
+        assert tickets['revoked'] == initial_tickets['revoked']
+        assert tickets_artifacts['created'] == initial_tickets_artifacts['created'] + 1
+        assert tickets_artifacts['modified'] == initial_tickets_artifacts['modified']
+
+        r = self.app.post('/tickets/save_ticket', 
+            params={'ticket_form.summary':'footext3',
+                    'ticket_form.assigned_to' : str(self.user1.username)},
+            extra_environ=dict(username=str(self.user2.username)))
+
+        tickets = self.organization.stats.getTickets()
+        tickets_artifacts = self.organization.stats.getArtifacts(art_type="Ticket")
+
+        assert tickets['assigned'] == initial_tickets['assigned'] + 1
+        assert tickets['solved'] == initial_tickets['solved']
+        assert tickets['revoked'] == initial_tickets['revoked']
+        assert tickets_artifacts['created'] == initial_tickets_artifacts['created'] + 2
+        assert tickets_artifacts['modified'] == initial_tickets_artifacts['modified']
+
+        ticket2num = str(TM.Ticket.query.get(summary='footext3').ticket_num)
+        r = self.app.post('/tickets/%s/update_ticket_from_widget' % ticket2num, 
+            params={'ticket_form.ticket_num' : ticket2num,
+                    'ticket_form.summary':'footext3',
+                    'ticket_form.assigned_to' : str(self.user3.username)},
+            extra_environ=dict(username=str(self.user2.username)))
+
+        tickets = self.organization.stats.getTickets()
+        tickets_artifacts = self.organization.stats.getArtifacts(art_type="Ticket")
+
+        assert tickets['assigned'] == initial_tickets['assigned'] + 2
+        assert tickets['solved'] == initial_tickets['solved']
+        assert tickets['revoked'] == initial_tickets['revoked']
+        assert tickets_artifacts['created'] == initial_tickets_artifacts['created'] + 2
+        assert tickets_artifacts['modified'] == initial_tickets_artifacts['modified'] + 1
+ 
+        r = self.app.post('/tickets/%s/update_ticket_from_widget' % ticket2num, 
+            params={'ticket_form.ticket_num' : ticket2num,
+                    'ticket_form.summary':'footext2',
+                    'ticket_form.status':'closed',
+                    'ticket_form.assigned_to' : str(self.user3.username)},
+            extra_environ=dict(username=str(self.user2.username)))
+
+        tickets = self.organization.stats.getTickets()
+        tickets_artifacts = self.organization.stats.getArtifacts(art_type="Ticket")
+
+        assert tickets['assigned'] == initial_tickets['assigned'] + 2
+        assert tickets['solved'] == initial_tickets['solved'] + 1
+        assert tickets['revoked'] == initial_tickets['revoked']
+        assert tickets_artifacts['created'] == initial_tickets_artifacts['created'] + 2
+        assert tickets_artifacts['modified'] == initial_tickets_artifacts['modified'] + 2
+
+        ticket1num = str(TM.Ticket.query.get(summary='footext2').ticket_num)
+        r = self.app.post('/tickets/%s/update_ticket_from_widget' % ticket1num, 
+            params={'ticket_form.ticket_num' : ticket1num,
+                    'ticket_form.summary':'footext2',
+                    'ticket_form.status':'closed',
+                    'ticket_form.assigned_to' : str(self.user1.username)},
+            extra_environ=dict(username=str(self.user2.username)))
+
+        tickets = self.organization.stats.getTickets()
+        tickets_artifacts = self.organization.stats.getArtifacts(art_type="Ticket")
+
+        assert tickets['assigned'] == initial_tickets['assigned'] + 2
+        assert tickets['solved'] == initial_tickets['solved'] + 1
+        assert tickets['revoked'] == initial_tickets['revoked'] + 1
+        assert tickets_artifacts['created'] == initial_tickets_artifacts['created'] + 2
+        assert tickets_artifacts['modified'] == initial_tickets_artifacts['modified'] + 3
+
+class TestGitCommitActiveMember(unittest.TestCase, TestController):
+
+    def setUp(self):
+        setup_basic_test()
+        self.user = M.User.by_username('test-admin')
+        self.organization = Organization.register(
+            'testorg', 'Test Organization', 'For-profit business', self.user)
+        self.organization.project().add_user(self.user, ['Admin'])
+
+        self.m = Membership.insert('Developer', 'active', 
+            self.organization._id, self.user._id)
+        
+        self.project = M.Project.query.get(shortname='test')
+        self.project.add_user(self.user, ['Admin'])
+        pi = ProjectInvolvement.insert('active', 'cooperation', 
+            self.organization._id, self.project._id)
+        addr = M.EmailAddress.upsert('rcopeland@geek.net')
+        self.user.claim_address('rcopeland@geek.net')
+        self.setup_with_tools()
+
+    @with_git
+    @td.with_wiki
+    def setup_with_tools(self):
+        setup_global_objects()
+        h.set_context('test', 'src-git', neighborhood='Projects')
+        repo_dir = pkg_resources.resource_filename(
+            'forgeuserstats', 'tests/data')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.name = 'testgit.git'
+        self.repo = c.app.repo
+        self.repo.refresh()
+        self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
+        self.rev.repo = self.repo
+
+    @td.with_user_project('test-admin')
+    def test_commit_member(self):
+        commits = self.organization.stats.getCommits()
+        assert commits['number'] == 4
+        lmcommits = self.organization.stats.getLastMonthCommits()
+        assert lmcommits['number'] == 4
+
+class TestGitCommitPastMember(unittest.TestCase, TestController):
+
+    def setUp(self):
+        setup_basic_test()
+        self.user = M.User.by_username('test-admin')
+        self.organization = Organization.register(
+            'testorg', 'Test Organization', 'For-profit business', self.user)
+        self.organization.project().add_user(self.user, ['Admin'])
+        self.m = Membership.insert('Developer', 'closed', 
+            self.organization._id, self.user._id)
+        
+        self.project = M.Project.query.get(shortname='test')
+        self.project.add_user(self.user, ['Admin'])
+        pi = ProjectInvolvement.insert('active', 'cooperation', 
+            self.organization._id, self.project._id)
+        addr = M.EmailAddress.upsert('rcopeland@geek.net')
+        self.user.claim_address('rcopeland@geek.net')
+        self.setup_with_tools()
+
+    @with_git
+    @td.with_wiki
+    def setup_with_tools(self):
+        setup_global_objects()
+        h.set_context('test', 'src-git', neighborhood='Projects')
+        repo_dir = pkg_resources.resource_filename(
+            'forgeuserstats', 'tests/data')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.name = 'testgit.git'
+        self.repo = c.app.repo
+        self.repo.refresh()
+        self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]['object_id'])
+        self.rev.repo = self.repo
+
+    @td.with_user_project('test-admin')
+    def test_commit_member(self):
+        commits = self.organization.stats.getCommits()
+        assert commits['number'] == 0
+        lmcommits = self.organization.stats.getLastMonthCommits()
+        assert lmcommits['number'] == 0

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/forgeorganizationstats/version.py
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/forgeorganizationstats/version.py b/ForgeOrganizationStats/forgeorganizationstats/version.py
new file mode 100644
index 0000000..6514373
--- /dev/null
+++ b/ForgeOrganizationStats/forgeorganizationstats/version.py
@@ -0,0 +1,2 @@
+__version_info__ = (0, 0)
+__version__ = '.'.join(map(str, __version_info__))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/forgeorganizationstats/widgets/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/forgeorganizationstats/widgets/__init__.py b/ForgeOrganizationStats/forgeorganizationstats/widgets/__init__.py
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/forgeorganizationstats/widgets/forms.py
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/forgeorganizationstats/widgets/forms.py b/ForgeOrganizationStats/forgeorganizationstats/widgets/forms.py
new file mode 100644
index 0000000..e6c3ae1
--- /dev/null
+++ b/ForgeOrganizationStats/forgeorganizationstats/widgets/forms.py
@@ -0,0 +1,22 @@
+from allura.lib import validators as V
+from allura.lib.widgets.forms import ForgeForm
+
+from formencode import validators as fev
+
+import ew as ew_core
+import ew.jinja2_ew as ew
+
+class StatsPreferencesForm(ForgeForm):
+    defaults=dict(ForgeForm.defaults)
+
+    class fields(ew_core.NameList):
+        visible = ew.Checkbox(
+            label='Make my personal statistics visible to other users.')
+            
+    def display(self, **kw):
+        if kw.get('organization').stats.visible:
+            self.fields['visible'].attrs = {'checked':'true'}      
+        else:
+            self.fields['visible'].attrs = {}    
+        return super(ForgeForm, self).display(**kw)
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/setup.py
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/setup.py b/ForgeOrganizationStats/setup.py
new file mode 100644
index 0000000..0d1ea08
--- /dev/null
+++ b/ForgeOrganizationStats/setup.py
@@ -0,0 +1,32 @@
+from setuptools import setup, find_packages
+import sys, os
+
+from forgeorganizationstats.version import __version__
+
+setup(name='ForgeOrganizationStats',
+      version=__version__,
+      description="",
+      long_description="""\
+""",
+      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      keywords='',
+      author='',
+      author_email='',
+      url='',
+      license='',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          # -*- Extra requirements: -*-
+          'allura',
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      [allura]
+      organizationstats=forgeorganizationstats.main:ForgeOrganizationStatsApp
+
+      [allura.stats]
+      organizationstats=forgeorganizationstats.main:OrganizationStatsListener
+      """,
+      )

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/787ef235/ForgeOrganizationStats/test.ini
----------------------------------------------------------------------
diff --git a/ForgeOrganizationStats/test.ini b/ForgeOrganizationStats/test.ini
new file mode 100644
index 0000000..9234e46
--- /dev/null
+++ b/ForgeOrganizationStats/test.ini
@@ -0,0 +1,56 @@
+#
+# allura - TurboGears 2 testing environment configuration
+#
+# The %(here)s variable will be replaced with the parent directory of this file
+#
+[DEFAULT]
+debug = true
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 5000
+
+[app:main]
+use = config:../Allura/test.ini
+
+[app:main_without_authn]
+use = config:../Allura/test.ini#main_without_authn
+
+[app:main_with_amqp]
+use = config:../Allura/test.ini#main_with_amqp
+
+[loggers]
+keys = root, allura, tool
+
+[handlers]
+keys = test
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = test
+
+[logger_allura]
+level = DEBUG
+handlers =
+qualname = allura
+
+[logger_tool]
+level = DEBUG
+handlers =
+qualname = forgeorganization
+
+[handler_test]
+class = FileHandler
+args = ('test.log',)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
+datefmt = %H:%M:%S
+
+


Mime
View raw message