~cr3/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to lib/lp/results/schema/main/tests/test_project.py

  • Committer: Marc Tardif
  • Date: 2010-12-07 01:16:17 UTC
  • Revision ID: marc.tardif@canonical.com-20101207011617-cqcv0240ca3cs5ba
Added TestStat for statistics about test runs and TestRank for ranking of projects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
__metaclass__ = type
 
5
 
 
6
__all__ = []
 
7
 
 
8
from unittest import defaultTestLoader
 
9
 
 
10
from lp.results.models.store import get_store
 
11
 
 
12
from lp.results.testing.cases import TestCaseWithFactory
 
13
from lp.results.testing.layers import DatabaseLayer
 
14
 
 
15
 
 
16
class TestProject(TestCaseWithFactory):
 
17
 
 
18
    layer = DatabaseLayer
 
19
 
 
20
    def setUp(self):
 
21
        super(TestProject, self).setUp()
 
22
 
 
23
        self.store = get_store("main")
 
24
 
 
25
    def assertTestRankCount(self, name, count):
 
26
        test_rank_count = self.store.execute(
 
27
            "SELECT COUNT(*) FROM test_rank tr "
 
28
            "JOIN project p ON p.id = tr.project_i_id "
 
29
            "WHERE p.name = ?",
 
30
            (name,),
 
31
            ).get_one()[0]
 
32
        self.assertEquals(test_rank_count, count)
 
33
 
 
34
    def test_insert(self):
 
35
        # Insert a first project which should still have a count of zero
 
36
        name = self.factory.getUniqueString(u"project1-name")
 
37
        self.store.execute(
 
38
            "INSERT INTO project (name) VALUES (?)",
 
39
            (name,),
 
40
            )
 
41
        self.assertTestRankCount(name, 0)
 
42
 
 
43
        # Insert a second project which should increase the count to one
 
44
        name = self.factory.getUniqueString(u"project2-name")
 
45
        self.store.execute(
 
46
            "INSERT INTO project (name) VALUES (?)",
 
47
            (name,),
 
48
            )
 
49
        self.assertTestRankCount(name, 1)
 
50
 
 
51
 
 
52
def test_suite():
 
53
    return defaultTestLoader.loadTestsFromName(__name__)