Completed
Push — master ( d73fd0...3a2f21 )
by
unknown
01:31
created

SymbolsTest.setUp()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
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, storage_with_spaces_instance
36
37
38
39
BASE_DIR = os.path.dirname(__file__)
40
TEST_DATA_DIR = os.path.join(BASE_DIR, 'testdata')
41
SYM_FILE = os.path.join(TEST_DATA_DIR, 'BreakpadTestApp.sym')
42
43
44
class SymbolsTest(BaseTest, APITestCase):
45
    url = 'symbols-list'
46
    url_detail = 'symbols-detail'
47
    factory = SymbolsFactory
48
    serializer = SymbolsSerializer
49
50
    @is_private()
51
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
52
    def setUp(self):
53
        storage_with_spaces_instance._setup()
54
        super(SymbolsTest, self).setUp()
55
56
    @is_private()
57
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
58
    def test_detail(self):
59 View Code Duplication
        super(SymbolsTest, self).test_detail()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
60
61
    @is_private()
62
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
63
    def test_list(self):
64
        super(SymbolsTest, self).test_list()
65
66
    @is_private()
67
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
68
    def test_create(self):
69
        with open(SYM_FILE, 'rb') as f:
70
            data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read()))
71
        response = self.client.post(reverse(self.url), data)
72
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
73
        symbols = Symbols.objects.get(id=response.data['id'])
74
        self.assertEqual(response.data, self.serializer(symbols).data)
75
        self.assertEqual(symbols.debug_id, 'C1C0FA629EAA4B4D9DD2ADE270A231CC1')
76
        self.assertEqual(symbols.debug_file, 'BreakpadTestApp.pdb')
77
78
    @is_private()
79 View Code Duplication
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
80
    def test_create_without_file(self):
81
        data = dict()
82
        response = self.client.post(reverse(self.url), data)
83
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
84
        self.assertEqual(response.data, {'file': [u'No file was submitted.']})
85
86
    @is_private()
87
    def test_duplicate(self):
88
        with open(SYM_FILE, 'rb') as f:
89
            data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read()))
90
        response = self.client.post(reverse(self.url), data)
91
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
92
        with open(SYM_FILE, 'rb') as f:
93
            data = dict(file=SimpleUploadedFile('./BreakpadTestApp.sym', f.read()))
94
        response = self.client.post(reverse(self.url), data)
95
        self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
96
        self.assertEqual(response.data['message'], 'Duplicate symbol')
97
98
class CrashTest(BaseTest, APITestCase):
99
    url = 'crash-list'
100
    url_detail = 'crash-detail'
101
    factory = CrashFactory
102
    serializer = CrashSerializer
103
104
    @is_private()
105
    def test_list(self):
106
        response = self.client.get(reverse(self.url), format='json')
107
        self.assertEqual(response.status_code, status.HTTP_200_OK)
108
        self.assertEqual(response.data['count'], 10)
109
        self.assertEqual(self.serializer(self.objects, many=True).data, response.data['results'][::-1])
110
111
    @is_private()
112
    def test_create(self):
113
        response = self.client.post(reverse(self.url), {})
114
        self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
115