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
|
# coding: utf8
"""
This software is licensed under the Apache 2 license, quoted below.
Copyright 2014 Crystalnix Limited
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
"""
import os
from django.core.urlresolvers import reverse
from django.core.files.uploadedfile import SimpleUploadedFile
from rest_framework import status
from rest_framework.test import APITestCase
from crash.serializers import SymbolsSerializer, CrashSerializer
from crash.models import Symbols, Crash
from crash.factories import SymbolsFactory, CrashFactory
from omaha.tests.utils import temporary_media_root
from omaha.tests.test_api import BaseTest
from omaha_server.utils import is_private
BASE_DIR = os.path.dirname(__file__)
TEST_DATA_DIR = os.path.join(BASE_DIR, 'testdata')
SYM_FILE = os.path.join(TEST_DATA_DIR, 'BreakpadTestApp.sym')
class SymbolsTest(BaseTest, APITestCase):
url = 'symbols-list'
url_detail = 'symbols-detail'
factory = SymbolsFactory
serializer = SymbolsSerializer
@is_private()
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
def test_detail(self):
super(SymbolsTest, self).test_detail()
@is_private()
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
def test_list(self):
super(SymbolsTest, self).test_list()
@is_private()
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
def test_create(self):
with open(SYM_FILE, 'rb') as f:
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read()))
response = self.client.post(reverse(self.url), data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
symbols = Symbols.objects.get(id=response.data['id'])
self.assertEqual(response.data, self.serializer(symbols).data)
self.assertEqual(symbols.debug_id, 'C1C0FA629EAA4B4D9DD2ADE270A231CC1')
self.assertEqual(symbols.debug_file, 'BreakpadTestApp.pdb')
@is_private()
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
def test_create_without_file(self):
data = dict()
response = self.client.post(reverse(self.url), data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {'file': [u'No file was submitted.']})
@is_private()
def test_duplicate(self):
with open(SYM_FILE, 'rb') as f:
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read()))
response = self.client.post(reverse(self.url), data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
with open(SYM_FILE, 'rb') as f:
data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read()))
response = self.client.post(reverse(self.url), data)
self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
self.assertEqual(response.data['message'], 'Duplicate symbol')
class CrashTest(BaseTest, APITestCase):
url = 'crash-list'
url_detail = 'crash-detail'
factory = CrashFactory
serializer = CrashSerializer
@is_private()
def test_list(self):
response = self.client.get(reverse(self.url), format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 10)
self.assertEqual(self.serializer(self.objects, many=True).data, response.data['results'][::-1])
@is_private()
def test_create(self):
response = self.client.post(reverse(self.url), {})
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
|