/
test_crash_data.py
158 lines (135 loc) · 5.4 KB
/
test_crash_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import shutil
import tempfile
import unittest
from configman import ConfigurationManager, Namespace
from mock import Mock, patch
from nose.plugins.attrib import attr
from socorro.external import MissingArgumentError, ResourceNotFound, \
ResourceUnavailable
from socorro.external.filesystem import crash_data, crashstorage
@attr(integration='filesystem') # for nosetests
class IntegrationTestCrashData(unittest.TestCase):
def setUp(self):
"""Insert fake data into filesystem. """
self.std_tmp_dir = tempfile.mkdtemp()
self.def_tmp_dir = tempfile.mkdtemp()
self.pro_tmp_dir = tempfile.mkdtemp()
self.config_manager = self._common_config_setup()
with self.config_manager.context() as config:
store = crashstorage.FileSystemCrashStorage(config.filesystem)
fake_dump = 'this is a fake dump'
fake_raw = {'name': 'Peter', 'legacy_processing': 0,
"submitted_timestamp": '2012-05-04 15:10:33'}
fake_processed = {
'name': 'Peter',
'uuid': '114559a5-d8e6-428c-8b88-1c1f22120314'
}
store.save_raw_crash(
fake_raw,
fake_dump,
'114559a5-d8e6-428c-8b88-1c1f22120314'
)
store.save_processed(fake_processed)
fake_dump = 'this is another fake dump'
fake_raw = {'name': 'Adrian', 'legacy_processing': 0,
"submitted_timestamp": '2012-05-04 15:10:33'}
store.save_raw_crash(
fake_raw,
fake_dump,
'58727744-12f5-454a-bcf5-f688af393821'
)
def tearDown(self):
"""Remove all temp files and folders. """
shutil.rmtree(self.std_tmp_dir)
shutil.rmtree(self.def_tmp_dir)
shutil.rmtree(self.pro_tmp_dir)
def _common_config_setup(self):
mock_logging = Mock()
required_config = Namespace()
required_config.namespace('filesystem')
required_config.filesystem = \
crashstorage.FileSystemCrashStorage.get_required_config()
required_config.filesystem.add_option('logger', default=mock_logging)
config_manager = ConfigurationManager(
[required_config],
app_name='testapp',
app_version='1.0',
app_description='app description',
values_source_list=[{'filesystem': {
'logger': mock_logging,
'std_fs_root': self.std_tmp_dir,
'def_fs_root': self.def_tmp_dir,
'pro_fs_root': self.pro_tmp_dir,
}}],
argv_source=[]
)
return config_manager
@patch('socorro.external.postgresql.priorityjobs.Priorityjobs')
def test_get(self, priorityjobs_mock):
with self.config_manager.context() as config:
service = crash_data.CrashData(config=config)
params = {
'datatype': 'raw',
'uuid': '114559a5-d8e6-428c-8b88-1c1f22120314'
}
# Test 1: get a raw dump
res_expected = ('this is a fake dump', 'application/octet-stream')
res = service.get(**params)
self.assertEqual(res, res_expected)
# Test 2: get a raw crash
params['datatype'] = 'meta'
res_expected = {'name': 'Peter', 'legacy_processing': 0,
"submitted_timestamp": '2012-05-04 15:10:33'}
res = service.get(**params)
self.assertEqual(res, res_expected)
# Test 3: get a processed crash
params['datatype'] = 'processed'
res_expected = {
'name': 'Peter',
'uuid': '114559a5-d8e6-428c-8b88-1c1f22120314'
}
res = service.get(**params)
self.assertEqual(res, res_expected)
# Test 4: missing parameters
self.assertRaises(
MissingArgumentError,
service.get
)
self.assertRaises(
MissingArgumentError,
service.get,
**{'uuid': '114559a5-d8e6-428c-8b88-1c1f22120314'}
)
# Test 5: crash cannot be found
self.assertRaises(
ResourceNotFound,
service.get,
**{
'uuid': 'c44245f4-c93b-49b8-86a2-c15dc3a695cb',
'datatype': 'processed'
}
)
# Test 6: not yet available crash
self.assertRaises(
ResourceUnavailable,
service.get,
**{
'uuid': '58727744-12f5-454a-bcf5-f688af393821',
'datatype': 'processed'
}
)
priorityjobs_mock.return_value.create.assert_called_once_with(
uuid='58727744-12f5-454a-bcf5-f688af393821'
)
# Test 7: raw crash cannot be found
self.assertRaises(
ResourceNotFound,
service.get,
**{
'uuid': 'c44245f4-c93b-49b8-86a2-c15dc3a695cb',
'datatype': 'raw'
}
)