GenerateFakeDataTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 64.29 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 18
loc 28
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_command() 0 5 1
A tearDown() 0 2 1
A setUp() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# coding: utf8
2
3
import datetime
4
5
from django.test import TestCase
6
from django.core.management import call_command
7
from django.core.files.uploadedfile import SimpleUploadedFile
8
9
from bitmapist import YearEvents
10
11
from omaha.tests.utils import temporary_media_root
12
from omaha.utils import redis
13
from omaha.models import (
14
    Application,
15
    Platform,
16
    Channel,
17
    Version,
18
    Request,
19
    AppRequest
20
)
21
22
23
class GenerateFakeDataTest(TestCase):
24 View Code Duplication
    @temporary_media_root()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
    def setUp(self):
26
        redis.flushdb()
27
        self.app = Application.objects.create(id='{5FAD27D4-6BFA-4daa-A1B3-5A1F821FEE0F}', name='app')
28
        self.channel = Channel.objects.create(name='stable')
29
        self.platform = Platform.objects.create(name='win')
30
        self.version1 = Version.objects.create(
31
            app=self.app,
32
            platform=self.platform,
33
            channel=self.channel,
34
            version='1.0.0.0',
35
            file=SimpleUploadedFile('./chrome_installer.exe', False))
36
        self.version2 = Version.objects.create(
37
            app=self.app,
38
            platform=self.platform,
39
            channel=self.channel,
40
            version='2.0.0.0',
41
            file=SimpleUploadedFile('./chrome_installer.exe', False))
42
43
    def tearDown(self):
44
        redis.flushdb()
45
46
    def test_command(self):
47
        self.assertEqual(0, Request.objects.all().count())
48
        call_command('generate_fake_data', self.app.id, count=10)
49
        self.assertEqual(10, Request.objects.all().count())
50
        self.assertEqual(10, AppRequest.objects.filter(appid=self.app.id).count())
51
52
53
class GenerateFakeStatisticsTest(TestCase):
54 View Code Duplication
    @temporary_media_root()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
55
    def setUp(self):
56
        redis.flushdb()
57
        self.app = Application.objects.create(id='{5FAD27D4-6BFA-4daa-A1B3-5A1F821FEE0F}', name='app')
58
        self.channel = Channel.objects.create(name='stable')
59
        self.platform = Platform.objects.create(name='win')
60
        self.version1 = Version.objects.create(
61
            app=self.app,
62
            platform=self.platform,
63
            channel=self.channel,
64
            version='1.0.0.0',
65
            file=SimpleUploadedFile('./chrome_installer.exe', False))
66
        self.version2 = Version.objects.create(
67
            app=self.app,
68
            platform=self.platform,
69
            channel=self.channel,
70
            version='2.0.0.0',
71
            file=SimpleUploadedFile('./chrome_installer.exe', False))
72
73
    def tearDown(self):
74
        redis.flushdb()
75
76
    def test_command(self):
77
        now = datetime.datetime.now()
78
        year = now.year
79
        self.assertEqual(0, len(YearEvents('request', year)))
80
        call_command('generate_fake_statistics', self.app.id, count=10)
81
        self.assertGreater(len(YearEvents('request', year)), 0)
82