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
|
|
|
import string |
23
|
|
|
import random |
24
|
|
|
|
25
|
|
|
from django.test import TestCase |
26
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
27
|
|
|
|
28
|
|
|
from crash.forms import SymbolsAdminForm, CrashFrom |
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
|
|
|
TAR_FILE = os.path.join(TEST_DATA_DIR, 'foo.tar') |
35
|
|
|
TAR_GZ_FILE = os.path.join(TEST_DATA_DIR, 'foo.tar.gz') |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
def string_generator(size, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits): |
39
|
|
|
return ''.join(random.choice(chars) for _ in range(size)) |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class SymbolsAdminFormTest(TestCase): |
43
|
|
|
def test_form(self): |
44
|
|
|
form_data = {} |
45
|
|
|
|
46
|
|
|
with open(SYM_FILE, 'rb') as f: |
47
|
|
|
form_file_data = {'file': SimpleUploadedFile('BreakpadTestApp.sym', f.read())} |
48
|
|
|
|
49
|
|
|
form = SymbolsAdminForm(form_data, form_file_data) |
50
|
|
|
|
51
|
|
|
self.assertTrue(form.is_valid()) |
52
|
|
|
self.assertEqual(form.cleaned_data['debug_id'], 'C1C0FA629EAA4B4D9DD2ADE270A231CC1') |
53
|
|
|
self.assertEqual(form.cleaned_data['debug_file'], 'BreakpadTestApp.pdb') |
54
|
|
|
self.assertEqual(form.cleaned_data['file_size'], 68149) |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
class CrashFormTest(TestCase): |
58
|
|
View Code Duplication |
def test_form(self): |
|
|
|
|
59
|
|
|
form_file_data = dict(upload_file_minidump=SimpleUploadedFile( |
60
|
|
|
"7b05e196-7e23-416b-bd13-99287924e214.dmp", b"content")) |
61
|
|
|
form_data = dict( |
62
|
|
|
appid='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', |
63
|
|
|
userid='{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}', |
64
|
|
|
) |
65
|
|
|
|
66
|
|
|
form = CrashFrom(form_data, form_file_data) |
67
|
|
|
|
68
|
|
|
self.assertTrue(form.is_valid()) |
69
|
|
|
self.assertEqual(form.cleaned_data['upload_file_minidump'].name, '7b05e196-7e23-416b-bd13-99287924e214.dmp') |
70
|
|
|
self.assertEqual(form.cleaned_data['archive_size'], 0) |
71
|
|
|
self.assertEqual(form.cleaned_data['minidump_size'], 7) |
72
|
|
|
|
73
|
|
View Code Duplication |
def test_form_tar_file(self): |
|
|
|
|
74
|
|
|
with open(TAR_FILE, 'rb') as f: |
75
|
|
|
form_file_data = dict(upload_file_minidump=SimpleUploadedFile( |
76
|
|
|
"foo.tar", f.read())) |
77
|
|
|
form_data = dict( |
78
|
|
|
appid='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', |
79
|
|
|
userid='{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}', |
80
|
|
|
) |
81
|
|
|
|
82
|
|
|
form = CrashFrom(form_data, form_file_data) |
83
|
|
|
|
84
|
|
|
self.assertTrue(form.is_valid()) |
85
|
|
|
self.assertEqual(form.cleaned_data['upload_file_minidump'].name, '7b05e196-7e23-416b-bd13-99287924e214.dmp') |
86
|
|
|
self.assertEqual(form.cleaned_data['archive'].name, 'foo.tar') |
87
|
|
|
self.assertEqual(form.cleaned_data['archive_size'], 85504) |
88
|
|
|
self.assertEqual(form.cleaned_data['minidump_size'], 14606) |
89
|
|
|
|
90
|
|
View Code Duplication |
def test_form_tar_gz_file(self): |
|
|
|
|
91
|
|
|
with open(TAR_GZ_FILE, 'rb') as f: |
92
|
|
|
form_file_data = dict(upload_file_minidump=SimpleUploadedFile( |
93
|
|
|
"foo.tar.gz", f.read())) |
94
|
|
|
form_data = dict( |
95
|
|
|
appid='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', |
96
|
|
|
userid='{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}', |
97
|
|
|
) |
98
|
|
|
|
99
|
|
|
form = CrashFrom(form_data, form_file_data) |
100
|
|
|
|
101
|
|
|
self.assertTrue(form.is_valid()) |
102
|
|
|
self.assertEqual(form.cleaned_data['upload_file_minidump'].name, '7b05e196-7e23-416b-bd13-99287924e214.dmp') |
103
|
|
|
self.assertEqual(form.cleaned_data['archive'].name, 'foo.tar.gz') |
104
|
|
|
self.assertEqual(form.cleaned_data['archive_size'], 18791) |
105
|
|
|
self.assertEqual(form.cleaned_data['minidump_size'], 14606) |
106
|
|
|
|
107
|
|
|
def test_invalid_data(self): |
108
|
|
|
with open(TAR_FILE, 'rb') as f: |
109
|
|
|
form_file_data = dict(upload_file_minidump=SimpleUploadedFile( |
110
|
|
|
"foo.tar", f.read(100))) |
111
|
|
|
form_data = dict( |
112
|
|
|
appid=string_generator(40), |
113
|
|
|
userid=string_generator(40), |
114
|
|
|
meta=string_generator(40), |
115
|
|
|
stacktrace=string_generator(40), |
116
|
|
|
stacktrace_json=string_generator(40), |
117
|
|
|
signature=string_generator(256), |
118
|
|
|
ip=string_generator(40), |
119
|
|
|
groupid=string_generator(40), |
120
|
|
|
eventid=string_generator(40), |
121
|
|
|
) |
122
|
|
|
|
123
|
|
|
form = CrashFrom(form_data, form_file_data) |
124
|
|
|
self.assertFalse(form.is_valid()) |
125
|
|
|
self.assertIn('upload_file_minidump', form.errors) |
126
|
|
|
self.assertIn('appid', form.errors) |
127
|
|
|
self.assertIn('userid', form.errors) |
128
|
|
|
self.assertIn('meta', form.errors) |
129
|
|
|
self.assertNotIn('stacktrace', form.errors) |
130
|
|
|
self.assertIn('stacktrace_json', form.errors) |
131
|
|
|
self.assertIn('signature', form.errors) |
132
|
|
|
self.assertIn('ip', form.errors) |
133
|
|
|
self.assertIn('groupid', form.errors) |
134
|
|
|
self.assertIn('eventid', form.errors) |
135
|
|
|
|