Completed
Push — master ( 67eae9...f0f1ec )
by
unknown
01:23
created

GenerateFakeDataTest.tearDown()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 2
rs 10
cc 1
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
    @temporary_media_root()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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
    @temporary_media_root()
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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.assertEqual(10, len(YearEvents('request', year)))
82