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
|
|
|
from builtins import str |
22
|
|
|
|
23
|
|
|
import os |
24
|
|
|
|
25
|
|
|
from django.test import TestCase |
26
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
27
|
|
|
|
28
|
|
|
from omaha.tests.utils import temporary_media_root |
29
|
|
|
|
30
|
|
|
from crash.models import Symbols, Crash |
31
|
|
|
from crash.serializers import SymbolsSerializer, CrashSerializer |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
BASE_DIR = os.path.dirname(__file__) |
35
|
|
|
TEST_DATA_DIR = os.path.join(BASE_DIR, 'testdata') |
36
|
|
|
SYM_FILE = os.path.join(TEST_DATA_DIR, 'BreakpadTestApp.sym') |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
class SymbolsSerializerTest(TestCase): |
40
|
|
|
def test_serializer(self): |
41
|
|
|
data = dict(file=SimpleUploadedFile('./test.pdb', False), |
42
|
|
|
debug_id='C1C0FA629EAA4B4D9DD2ADE270A231CC1', |
43
|
|
|
debug_file='BreakpadTestApp.pdb') |
44
|
|
|
symbols = Symbols.objects.create(**data) |
45
|
|
|
self.assertDictEqual(SymbolsSerializer(symbols).data, |
46
|
|
|
dict(id=symbols.id, |
47
|
|
|
debug_id='C1C0FA629EAA4B4D9DD2ADE270A231CC1', |
48
|
|
|
debug_file='BreakpadTestApp.pdb', |
49
|
|
|
file=symbols.file.url, |
50
|
|
|
file_size=symbols.file_size, |
51
|
|
|
created=symbols.created.strftime('%Y-%m-%dT%H:%M:%S.%fZ'), |
52
|
|
|
modified=symbols.modified.strftime('%Y-%m-%dT%H:%M:%S.%fZ'), )) |
53
|
|
|
|
54
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
55
|
|
|
def test_auto_fill_file_size(self): |
56
|
|
|
with open(SYM_FILE, 'rb') as f: |
57
|
|
|
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read())) |
58
|
|
|
|
59
|
|
|
symbols = SymbolsSerializer(data=data) |
60
|
|
|
self.assertTrue(symbols.is_valid()) |
61
|
|
|
symbols_instance = symbols.save() |
62
|
|
|
self.assertEqual(symbols_instance.debug_id, 'C1C0FA629EAA4B4D9DD2ADE270A231CC1') |
63
|
|
|
self.assertEqual(symbols_instance.debug_file, 'BreakpadTestApp.pdb') |
64
|
|
|
self.assertEqual(symbols_instance.file_size, 68149) |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
class CrashSerializerTest(TestCase): |
68
|
|
|
maxDiff = None |
69
|
|
|
|
70
|
|
|
@temporary_media_root( |
71
|
|
|
CELERY_ALWAYS_EAGER=False, |
72
|
|
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=False, |
73
|
|
|
) |
74
|
|
|
def test_serializer(self): |
75
|
|
|
meta = dict( |
76
|
|
|
lang='en', |
77
|
|
|
version='1.0.0.1', |
78
|
|
|
) |
79
|
|
|
stacktrace_json = dict( |
80
|
|
|
crashing_thread={}, |
81
|
|
|
) |
82
|
|
|
app_id = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}' |
83
|
|
|
user_id = '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}' |
84
|
|
|
crash = Crash.objects.create( |
85
|
|
|
appid=app_id, |
86
|
|
|
userid=user_id, |
87
|
|
|
upload_file_minidump=SimpleUploadedFile('./dump.dat', b''), |
88
|
|
|
meta=meta, |
89
|
|
|
stacktrace_json=stacktrace_json |
90
|
|
|
) |
91
|
|
|
self.assertDictEqual(CrashSerializer(crash).data, |
92
|
|
|
dict(id=crash.id, |
93
|
|
|
upload_file_minidump=crash.upload_file_minidump.url, |
94
|
|
|
archive=None, |
95
|
|
|
appid=str(crash.appid), |
96
|
|
|
userid=str(crash.userid), |
97
|
|
|
meta=meta, |
98
|
|
|
signature=crash.signature, |
99
|
|
|
stacktrace_json=crash.stacktrace_json, |
100
|
|
|
created=crash.created.strftime('%Y-%m-%dT%H:%M:%S.%fZ'), |
101
|
|
|
modified=crash.modified.strftime('%Y-%m-%dT%H:%M:%S.%fZ'), |
102
|
|
|
os=None, |
103
|
|
|
build_number=None, |
104
|
|
|
channel='')) |
105
|
|
|
|