|
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.core.urlresolvers import reverse |
|
24
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
|
25
|
|
|
|
|
26
|
|
|
from rest_framework import status |
|
27
|
|
|
from rest_framework.test import APITestCase |
|
28
|
|
|
|
|
29
|
|
|
from crash.serializers import SymbolsSerializer, CrashSerializer |
|
30
|
|
|
from crash.models import Symbols, Crash |
|
31
|
|
|
from crash.factories import SymbolsFactory, CrashFactory |
|
32
|
|
|
|
|
33
|
|
|
from omaha.tests.utils import temporary_media_root |
|
34
|
|
|
from omaha.tests.test_api import BaseTest |
|
35
|
|
|
from omaha_server.utils import is_private |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
BASE_DIR = os.path.dirname(__file__) |
|
39
|
|
|
TEST_DATA_DIR = os.path.join(BASE_DIR, 'testdata') |
|
40
|
|
|
SYM_FILE = os.path.join(TEST_DATA_DIR, 'BreakpadTestApp.sym') |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
class SymbolsTest(BaseTest, APITestCase): |
|
44
|
|
|
url = 'symbols-list' |
|
45
|
|
|
url_detail = 'symbols-detail' |
|
46
|
|
|
factory = SymbolsFactory |
|
47
|
|
|
serializer = SymbolsSerializer |
|
48
|
|
|
|
|
49
|
|
|
@is_private() |
|
50
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
51
|
|
|
def test_detail(self): |
|
52
|
|
|
super(SymbolsTest, self).test_detail() |
|
53
|
|
|
|
|
54
|
|
|
@is_private() |
|
55
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
56
|
|
|
def test_list(self): |
|
57
|
|
|
super(SymbolsTest, self).test_list() |
|
58
|
|
|
|
|
59
|
|
|
@is_private() |
|
60
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
61
|
|
|
def test_create(self): |
|
62
|
|
|
with open(SYM_FILE, 'rb') as f: |
|
63
|
|
|
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read())) |
|
64
|
|
|
response = self.client.post(reverse(self.url), data) |
|
65
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
66
|
|
|
symbols = Symbols.objects.get(id=response.data['id']) |
|
67
|
|
|
self.assertEqual(response.data, self.serializer(symbols).data) |
|
68
|
|
|
self.assertEqual(symbols.debug_id, 'C1C0FA629EAA4B4D9DD2ADE270A231CC1') |
|
69
|
|
|
self.assertEqual(symbols.debug_file, 'BreakpadTestApp.pdb') |
|
70
|
|
|
|
|
71
|
|
|
@is_private() |
|
72
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
73
|
|
|
def test_create_without_file(self): |
|
74
|
|
|
data = dict() |
|
75
|
|
|
response = self.client.post(reverse(self.url), data) |
|
76
|
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) |
|
77
|
|
|
self.assertEqual(response.data, {'file': [u'No file was submitted.']}) |
|
78
|
|
|
|
|
79
|
|
|
@is_private() |
|
80
|
|
|
def test_duplicate(self): |
|
81
|
|
|
with open(SYM_FILE, 'rb') as f: |
|
82
|
|
|
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read())) |
|
83
|
|
|
response = self.client.post(reverse(self.url), data) |
|
84
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
85
|
|
|
with open(SYM_FILE, 'rb') as f: |
|
86
|
|
|
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read())) |
|
87
|
|
|
response = self.client.post(reverse(self.url), data) |
|
88
|
|
|
self.assertEqual(response.status_code, status.HTTP_409_CONFLICT) |
|
89
|
|
|
self.assertEqual(response.data['message'], 'Duplicate symbol') |
|
90
|
|
|
|
|
91
|
|
|
class CrashTest(BaseTest, APITestCase): |
|
92
|
|
|
url = 'crash-list' |
|
93
|
|
|
url_detail = 'crash-detail' |
|
94
|
|
|
factory = CrashFactory |
|
95
|
|
|
serializer = CrashSerializer |
|
96
|
|
|
|
|
97
|
|
|
@is_private() |
|
98
|
|
|
def test_list(self): |
|
99
|
|
|
response = self.client.get(reverse(self.url), format='json') |
|
100
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
101
|
|
|
self.assertEqual(response.data['count'], 10) |
|
102
|
|
|
self.assertEqual(self.serializer(self.objects, many=True).data, response.data['results'][::-1]) |
|
103
|
|
|
|
|
104
|
|
|
@is_private() |
|
105
|
|
|
def test_create(self): |
|
106
|
|
|
response = self.client.post(reverse(self.url), {}) |
|
107
|
|
|
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) |
|
108
|
|
|
|