Beispiel #1
0
    def test_finding_queries_no_data(self):
        user3 = User.objects.get(username='******')
        self.request.user = user3

        product_types = []
        finding_queries = views.finding_querys(product_types, self.request)

        self.assertSequenceEqual(
            finding_queries['all'].values(),
            [],
        )
Beispiel #2
0
    def test_finding_queries(self, mock_timezone):
        mock_datetime = datetime(2020, 12, 9, tzinfo=timezone.utc)
        mock_timezone.return_value = mock_datetime

        # Queries over Finding and Risk_Acceptance
        with self.assertNumQueries(29):
            product_types = []
            finding_queries = views.finding_querys(product_types, self.request)

            self.assertSequenceEqual(list(finding_queries.keys()), [
                'all',
                'closed',
                'accepted',
                'accepted_count',
                'top_ten',
                'monthly_counts',
                'weekly_counts',
                'weeks_between',
                'start_date',
                'end_date',
            ])

            # Assert that we get expected querysets back. This is to be used to
            # support refactoring, in attempt of lowering the query count.
            self.assertSequenceEqual(finding_queries['all'].qs.values(), [])
            self.assertSequenceEqual(finding_queries['closed'].values(), [])
            self.assertSequenceEqual(finding_queries['accepted'].values(), [])
            self.assertSequenceEqual(
                list(finding_queries['accepted_count'].values()),
                [None, None, None, None, None, None])
            self.assertSequenceEqual(finding_queries['top_ten'].values(), [])
            self.assertSequenceEqual(
                list(finding_queries['monthly_counts'].values()),
                [[[
                    'Timestamp', 'Date', 'S0', 'S1', 'S2', 'S3', 'Total',
                    'Closed'
                ],
                  [
                      1604188800000,
                      datetime(2020, 11, 1, 0, 0, tzinfo=timezone.utc), 0, 0,
                      0, 0, 0, 0
                  ],
                  [
                      1606780800000,
                      datetime(2020, 12, 1, 0, 0, tzinfo=timezone.utc), 0, 0,
                      0, 0, 0, 0
                  ]],
                 [[
                     'Timestamp', 'Date', 'S0', 'S1', 'S2', 'S3', 'Total',
                     'Closed'
                 ],
                  [
                      1604188800000,
                      datetime(2020, 11, 1, 0, 0, tzinfo=timezone.utc), 0, 0,
                      0, 0, 0
                  ],
                  [
                      1606780800000,
                      datetime(2020, 12, 1, 0, 0, tzinfo=timezone.utc), 0, 0,
                      0, 0, 0
                  ]],
                 [[
                     'Timestamp', 'Date', 'S0', 'S1', 'S2', 'S3', 'Total',
                     'Closed'
                 ],
                  [
                      1604188800000,
                      datetime(2020, 11, 1, 0, 0, tzinfo=timezone.utc), 0, 0,
                      0, 0, 0
                  ],
                  [
                      1606780800000,
                      datetime(2020, 12, 1, 0, 0, tzinfo=timezone.utc), 0, 0,
                      0, 0, 0
                  ]]])
            self.assertDictEqual(
                finding_queries['weekly_counts'], {
                    'opened_per_period':
                    [[
                        'Timestamp', 'Date', 'S0', 'S1', 'S2', 'S3', 'Total',
                        'Closed'
                    ],
                     [
                         1607299200000,
                         datetime(2020, 12, 7, 0, 0, tzinfo=timezone.utc), 0,
                         0, 0, 0, 0, 0
                     ],
                     [
                         1607904000000,
                         datetime(2020, 12, 14, 0, 0, tzinfo=timezone.utc), 0,
                         0, 0, 0, 0, 0
                     ],
                     [
                         1608508800000,
                         datetime(2020, 12, 21, 0, 0, tzinfo=timezone.utc), 0,
                         0, 0, 0, 0, 0
                     ]],
                    'accepted_per_period': [
                        [
                            'Timestamp', 'Date', 'S0', 'S1', 'S2', 'S3',
                            'Total', 'Closed'
                        ],
                        [
                            1607299200000,
                            datetime(2020, 12, 7, 0, 0, tzinfo=timezone.utc),
                            0, 0, 0, 0, 0
                        ],
                        [
                            1607904000000,
                            datetime(2020, 12, 14, 0, 0, tzinfo=timezone.utc),
                            0, 0, 0, 0, 0
                        ],
                        [
                            1608508800000,
                            datetime(2020, 12, 21, 0, 0, tzinfo=timezone.utc),
                            0, 0, 0, 0, 0
                        ]
                    ],
                    'active_per_period': [
                        [
                            'Timestamp', 'Date', 'S0', 'S1', 'S2', 'S3',
                            'Total', 'Closed'
                        ],
                        [
                            1607299200000,
                            datetime(2020, 12, 7, 0, 0, tzinfo=timezone.utc),
                            0, 0, 0, 0, 0
                        ],
                        [
                            1607904000000,
                            datetime(2020, 12, 14, 0, 0, tzinfo=timezone.utc),
                            0, 0, 0, 0, 0
                        ],
                        [
                            1608508800000,
                            datetime(2020, 12, 21, 0, 0, tzinfo=timezone.utc),
                            0, 0, 0, 0, 0
                        ]
                    ]
                })
            self.assertEqual(finding_queries['weeks_between'], 2)
            self.assertIsInstance(finding_queries['start_date'], datetime)
            self.assertIsInstance(finding_queries['end_date'], datetime)