~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/test/test_process_core.py

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import unittest
2
 
from testtools import TestCase
3
 
from oopsrepository.testing.cassandra import TemporaryOOPSDB
4
 
import schema
5
 
import process_core
6
 
import configuration
7
 
import tempfile
8
 
import os
9
 
import shutil
10
 
import time
11
 
import pycassa
12
 
from pycassa.types import IntegerType, FloatType
13
 
 
14
 
class TestSubmission(TestCase):
15
 
    def setUp(self):
16
 
        super(TestSubmission, self).setUp()
17
 
        # We need to set the configuration before importing.
18
 
        self.keyspace = self.useFixture(TemporaryOOPSDB()).keyspace
19
 
        self.pool = pycassa.ConnectionPool(self.keyspace, ['localhost:9160'])
20
 
        configuration.cassandra_keyspace = self.keyspace
21
 
        configuration.cassandra_host = 'localhost:9160'
22
 
        schema.create()
23
 
        self.temp = tempfile.mkdtemp()
24
 
        config_dir = os.path.join(self.temp, 'config')
25
 
        sandbox_dir = os.path.join(self.temp, 'sandbox')
26
 
        os.makedirs(config_dir)
27
 
        os.makedirs(sandbox_dir)
28
 
        self.retracer = process_core.Retracer(config_dir, sandbox_dir)
29
 
 
30
 
    def tearDown(self):
31
 
        super(TestSubmission, self).tearDown()
32
 
        shutil.rmtree(self.temp)
33
 
 
34
 
    def test_update_retrace_stats(self):
35
 
        retrace_stats_fam = pycassa.ColumnFamily(self.pool, 'RetraceStats')
36
 
        indexes_fam = pycassa.ColumnFamily(self.pool, 'Indexes')
37
 
        release = 'Ubuntu 12.04'
38
 
        day_key = time.strftime('%Y%m%d', time.gmtime())
39
 
 
40
 
        self.retracer.update_retrace_stats(release, day_key, 30.5, True)
41
 
        result = retrace_stats_fam.get(day_key)
42
 
        self.assertEqual(result['Ubuntu 12.04:success'], 1)
43
 
        mean_key = '%s:Ubuntu 12.04' % day_key
44
 
        counter_key = '%s:count' % mean_key
45
 
        indexes_fam.column_validators = {mean_key : FloatType(),
46
 
                                         counter_key : IntegerType()}
47
 
        result = indexes_fam.get('mean_retracing_time')
48
 
        self.assertEqual(result[mean_key], 30.5)
49
 
        self.assertEqual(result[counter_key], 1)
50
 
 
51
 
        self.retracer.update_retrace_stats(release, day_key, 30.5, True)
52
 
        result = indexes_fam.get('mean_retracing_time')
53
 
        self.assertEqual(result[mean_key], 30.5)
54
 
        self.assertEqual(result[counter_key], 2)
55
 
 
56
 
if __name__ == '__main__':
57
 
    unittest.main()