FeedbackModelTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 49
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B test_model() 0 31 1
A test_property() 0 16 1
1
# coding: utf8
2
3
"""
4
This software is licensed under the Apache 2 license, quoted below.
5
6
Copyright 2015 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 import test
24
from django.core.files.uploadedfile import SimpleUploadedFile
25
26
from feedback.models import Feedback
27
from omaha.tests.utils import temporary_media_root
28
29
30
BASE_DIR = os.path.dirname(__file__)
31
TEST_DATA_DIR = os.path.join(BASE_DIR, 'testdata')
32
SCREENSHOT_FILE = os.path.join(TEST_DATA_DIR, 'screenshot.png')
33
34
35
class FeedbackModelTest(test.TestCase):
36
    @temporary_media_root()
37
    def test_model(self):
38
        description = 'Test description'
39
        email = '[email protected]'
40
        page_url = 'http://google.com/'
41
        feedback_data = {
42
            'web_data': {
43
                'url': page_url
44
            },
45
            'common_data': {
46
                'description': description,
47
                'user_email': email,
48
          }
49
        }
50
51
        obj = Feedback.objects.create(
52
            description=description,
53
            email=email,
54
            page_url=page_url,
55
            screenshot=SimpleUploadedFile('./screenshot.png', b''),
56
            blackbox=SimpleUploadedFile('./blackbox.tar', b''),
57
            system_logs=SimpleUploadedFile('./sys_logs.zip', b''),
58
            attached_file=SimpleUploadedFile('./attach.zip', b''),
59
            feedback_data=feedback_data,
60
        )
61
62
        self.assertTrue(obj)
63
        self.assertEqual(obj.description, description)
64
        self.assertEqual(obj.email, email)
65
        self.assertEqual(obj.page_url, page_url)
66
        self.assertDictEqual(obj.feedback_data, feedback_data)
67
68
    def test_property(self):
69
        description = 'Test description'
70
71
        obj = Feedback.objects.create(
72
            description=description,
73
            screenshot=SimpleUploadedFile('./screenshot.png', b''),
74
            screenshot_size=111,
75
            blackbox=SimpleUploadedFile('./blackbox.tar', b''),
76
            blackbox_size=222,
77
            system_logs=SimpleUploadedFile('./sys_logs.zip', b''),
78
            system_logs_size=333,
79
            attached_file=SimpleUploadedFile('./attach.zip', b''),
80
            attached_file_size=444,
81
        )
82
83
        self.assertEqual(obj.size, 111+222+333+444)
84