|
1
|
|
|
# coding: utf8 |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
This software is licensed under the Apache 2 license, quoted below. |
|
5
|
|
|
|
|
6
|
|
|
Copyright 2014 Crystalnix Limited |
|
7
|
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
9
|
|
|
use this file except in compliance with the License. You may obtain a copy of |
|
10
|
|
|
the License at |
|
11
|
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
16
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
17
|
|
|
License for the specific language governing permissions and limitations under |
|
18
|
|
|
the License. |
|
19
|
|
|
""" |
|
20
|
|
|
|
|
21
|
|
|
import os |
|
22
|
|
|
|
|
23
|
|
|
from django import test |
|
24
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
|
25
|
|
|
|
|
26
|
|
|
from crash.models import Crash, CrashDescription, Symbols, symbols_upload_to |
|
27
|
|
|
from crash.factories import CrashFactory |
|
28
|
|
|
from omaha.tests.utils import temporary_media_root |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
BASE_DIR = os.path.dirname(__file__) |
|
32
|
|
|
TEST_DATA_DIR = os.path.join(BASE_DIR, 'testdata') |
|
33
|
|
|
SYM_FILE = os.path.join(TEST_DATA_DIR, 'BreakpadTestApp.sym') |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
class CrashModelTest(test.TestCase): |
|
37
|
|
|
@temporary_media_root( |
|
38
|
|
|
CELERY_ALWAYS_EAGER=False, |
|
39
|
|
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=False, |
|
40
|
|
|
) |
|
41
|
|
|
def test_model(self): |
|
42
|
|
|
meta = dict( |
|
43
|
|
|
lang='en', |
|
44
|
|
|
version='1.0.0.1', |
|
45
|
|
|
) |
|
46
|
|
|
app_id = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}' |
|
47
|
|
|
user_id = '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}' |
|
48
|
|
|
obj = Crash.objects.create( |
|
49
|
|
|
appid=app_id, |
|
50
|
|
|
userid=user_id, |
|
51
|
|
|
upload_file_minidump=SimpleUploadedFile('./dump.dat', b''), |
|
52
|
|
|
meta=meta, |
|
53
|
|
|
) |
|
54
|
|
|
|
|
55
|
|
|
self.assertTrue(obj) |
|
56
|
|
|
self.assertDictEqual(obj.meta, meta) |
|
57
|
|
|
self.assertEqual(obj.appid, app_id) |
|
58
|
|
|
self.assertEqual(obj.userid, user_id) |
|
59
|
|
|
|
|
60
|
|
|
@temporary_media_root( |
|
61
|
|
|
CELERY_ALWAYS_EAGER=False, |
|
62
|
|
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=False, |
|
63
|
|
|
) |
|
64
|
|
|
def test_propertiy(self): |
|
65
|
|
|
app_id = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}' |
|
66
|
|
|
user_id = '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}' |
|
67
|
|
|
obj = Crash.objects.create( |
|
68
|
|
|
appid=app_id, |
|
69
|
|
|
userid=user_id, |
|
70
|
|
|
upload_file_minidump=SimpleUploadedFile('./dump.tar', b' '), |
|
71
|
|
|
minidump_size=123, |
|
72
|
|
|
archive_size=1234, |
|
73
|
|
|
) |
|
74
|
|
|
self.assertEqual(obj.size, 123+1234) |
|
75
|
|
|
|
|
76
|
|
|
class CrashDescriptionModelTest(test.TestCase): |
|
77
|
|
|
def test_model(self): |
|
78
|
|
|
crash = CrashFactory() |
|
79
|
|
|
summary = "Test summary" |
|
80
|
|
|
description = "Test description" |
|
81
|
|
|
|
|
82
|
|
|
obj = CrashDescription.objects.create( |
|
83
|
|
|
crash=crash, |
|
84
|
|
|
summary=summary, |
|
85
|
|
|
description=description |
|
86
|
|
|
) |
|
87
|
|
|
|
|
88
|
|
|
self.assertTrue(obj) |
|
89
|
|
|
self.assertEqual(obj.crash, crash) |
|
90
|
|
|
self.assertEqual(obj.summary, summary) |
|
91
|
|
|
self.assertEqual(obj.description, description) |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
class SymbolsModelTest(test.TestCase): |
|
95
|
|
|
@temporary_media_root() |
|
96
|
|
|
def test_model(self): |
|
97
|
|
|
with open(SYM_FILE, 'rb') as f: |
|
98
|
|
|
obj = Symbols.objects.create( |
|
99
|
|
|
debug_file='BreakpadTestApp.pdb', |
|
100
|
|
|
debug_id='C1C0FA629EAA4B4D9DD2ADE270A231CC1', |
|
101
|
|
|
file=SimpleUploadedFile(f.name, f.read()), |
|
102
|
|
|
) |
|
103
|
|
|
self.assertTrue(obj) |
|
104
|
|
|
|
|
105
|
|
|
@temporary_media_root() |
|
106
|
|
|
def test_propertiy(self): |
|
107
|
|
|
with open(SYM_FILE, 'rb') as f: |
|
108
|
|
|
obj = Symbols.objects.create( |
|
109
|
|
|
debug_file='BreakpadTestApp.pdb', |
|
110
|
|
|
debug_id='C1C0FA629EAA4B4D9DD2ADE270A231CC1', |
|
111
|
|
|
file=SimpleUploadedFile(f.name, f.read()), |
|
112
|
|
|
file_size=123 |
|
113
|
|
|
) |
|
114
|
|
|
self.assertEqual(obj.size, 123) |
|
115
|
|
|
|
|
116
|
|
|
@temporary_media_root() |
|
117
|
|
|
def test_symbols_upload_to(self): |
|
118
|
|
|
with open(SYM_FILE, 'rb') as f: |
|
119
|
|
|
obj = Symbols.objects.create( |
|
120
|
|
|
debug_file='BreakpadTestApp.pdb', |
|
121
|
|
|
debug_id='C1C0FA629EAA4B4D9DD2ADE270A231CC1', |
|
122
|
|
|
file=SimpleUploadedFile(f.name, f.read()), |
|
123
|
|
|
) |
|
124
|
|
|
self.assertIn('symbols/BreakpadTestApp.pdb/C1C0FA629EAA4B4D9DD2ADE270A231CC1/BreakpadTestApp.sym', |
|
125
|
|
|
obj.file.url) |
|
126
|
|
|
|
|
127
|
|
|
self.assertEqual(symbols_upload_to(obj, 'BreakpadTestApp.pdb'), |
|
128
|
|
|
'symbols/BreakpadTestApp.pdb/C1C0FA629EAA4B4D9DD2ADE270A231CC1/BreakpadTestApp.sym') |
|
129
|
|
|
|