Skip to content

Commit

Permalink
Fix: Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n-thumann committed Dec 11, 2023
1 parent 86798a7 commit e2dd009
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
13 changes: 10 additions & 3 deletions tests/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ class ExampleModel(Model):
foo: datetime

model = ExampleModel.from_dict({"foo": "1988-10-01T04:00:00.000"})
self.assertEqual(model.foo, datetime(1988, 10, 1, 4))
self.assertEqual(
model.foo, datetime(1988, 10, 1, 4, tzinfo=timezone.utc)
)

model = ExampleModel.from_dict({"foo": "1988-10-01T04:00:00Z"})
self.assertEqual(
Expand All @@ -131,7 +133,10 @@ class ExampleModel(Model):
)

model = ExampleModel.from_dict({"foo": "2021-06-06T11:15:10.213"})
self.assertEqual(model.foo, datetime(2021, 6, 6, 11, 15, 10, 213000))
self.assertEqual(
model.foo,
datetime(2021, 6, 6, 11, 15, 10, 213000, tzinfo=timezone.utc),
)

def test_date(self):
@dataclass
Expand Down Expand Up @@ -190,7 +195,9 @@ class ExampleModel(Model):
)

self.assertEqual(model.foo, "abc")
self.assertEqual(model.bar, datetime(1988, 10, 1, 4))
self.assertEqual(
model.bar, datetime(1988, 10, 1, 4, tzinfo=timezone.utc)
)
self.assertEqual(model.id, 123)
self.assertEqual(model.baz, ["a", "b", "c"])
self.assertIsNotNone(model.ipsum)
Expand Down
10 changes: 7 additions & 3 deletions tests/nvd/cpe/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# pylint: disable=line-too-long, arguments-differ, redefined-builtin
# ruff: noqa: E501

from datetime import datetime
from datetime import datetime, timezone
from itertools import repeat
from typing import Any, Optional
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -132,9 +132,13 @@ async def test_cpe(self):
self.assertEqual(cpe.cpe_name_id, uuid_replace(uuid, 1, 1))
self.assertFalse(cpe.deprecated)
self.assertEqual(
cpe.last_modified, datetime(2022, 12, 9, 18, 15, 16, 973000)
cpe.last_modified,
datetime(2022, 12, 9, 18, 15, 16, 973000, tzinfo=timezone.utc),
)
self.assertEqual(
cpe.created,
datetime(2022, 12, 9, 16, 20, 6, 943000, tzinfo=timezone.utc),
)
self.assertEqual(cpe.created, datetime(2022, 12, 9, 16, 20, 6, 943000))

self.assertEqual(cpe.refs, [])
self.assertEqual(cpe.titles, [])
Expand Down
8 changes: 5 additions & 3 deletions tests/nvd/cve/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# pylint: disable=line-too-long, arguments-differ, redefined-builtin

from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional
from unittest.mock import MagicMock, patch

Expand Down Expand Up @@ -111,10 +111,12 @@ async def test_cve(self):
self.assertEqual(cve.id, "CVE-2022-45536")
self.assertEqual(cve.source_identifier, "[email protected]")
self.assertEqual(
cve.published, datetime(2022, 11, 22, 21, 15, 11, 103000)
cve.published,
datetime(2022, 11, 22, 21, 15, 11, 103000, tzinfo=timezone.utc),
)
self.assertEqual(
cve.last_modified, datetime(2022, 11, 23, 16, 2, 7, 367000)
cve.last_modified,
datetime(2022, 11, 23, 16, 2, 7, 367000, tzinfo=timezone.utc),
)
self.assertEqual(len(cve.descriptions), 1)
self.assertEqual(len(cve.references), 2)
Expand Down
3 changes: 2 additions & 1 deletion tests/nvd/cve_changes/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ async def test_cve_changes(self):
)
self.assertEqual(cve_change.source_identifier, "[email protected]")
self.assertEqual(
cve_change.created, datetime(2022, 3, 18, 20, 13, 8, 123000)
cve_change.created,
datetime(2022, 3, 18, 20, 13, 8, 123000, tzinfo=timezone.utc),
)
self.assertEqual(
cve_change.details,
Expand Down
10 changes: 7 additions & 3 deletions tests/nvd/models/test_cpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# ruff: noqa: E501

import unittest
from datetime import datetime
from datetime import datetime, timezone
from uuid import UUID

from pontos.nvd.models.cpe import CPE, ReferenceType
Expand All @@ -37,9 +37,13 @@ def test_required_only(self):
)
self.assertFalse(cpe.deprecated)
self.assertEqual(
cpe.last_modified, datetime(2022, 12, 9, 18, 15, 16, 973000)
cpe.last_modified,
datetime(2022, 12, 9, 18, 15, 16, 973000, tzinfo=timezone.utc),
)
self.assertEqual(
cpe.created,
datetime(2022, 12, 9, 16, 20, 6, 943000, tzinfo=timezone.utc),
)
self.assertEqual(cpe.created, datetime(2022, 12, 9, 16, 20, 6, 943000))

self.assertEqual(cpe.titles, [])
self.assertEqual(cpe.refs, [])
Expand Down
12 changes: 8 additions & 4 deletions tests/nvd/models/test_cve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# ruff: noqa: E501

import unittest
from datetime import date, datetime
from datetime import date, datetime, timezone

from pontos.nvd.models import cvss_v2, cvss_v3
from pontos.nvd.models.cve import CVE, CVSSType, Operator
Expand All @@ -33,10 +33,12 @@ def test_required_only(self):
self.assertEqual(cve.id, "CVE-2022-45536")
self.assertEqual(cve.source_identifier, "[email protected]")
self.assertEqual(
cve.published, datetime(2022, 11, 22, 21, 15, 11, 103000)
cve.published,
datetime(2022, 11, 22, 21, 15, 11, 103000, tzinfo=timezone.utc),
)
self.assertEqual(
cve.last_modified, datetime(2022, 11, 23, 16, 2, 7, 367000)
cve.last_modified,
datetime(2022, 11, 23, 16, 2, 7, 367000, tzinfo=timezone.utc),
)
self.assertEqual(len(cve.descriptions), 1)
self.assertEqual(len(cve.references), 2)
Expand Down Expand Up @@ -506,7 +508,9 @@ def test_vendor_comments(self):
comment.comment,
"Fixed in Apache HTTP Server 1.3.12:\nhttp://httpd.apache.org/security/vulnerabilities_13.html",
)
self.assertEqual(comment.last_modified, datetime(2008, 7, 2))
self.assertEqual(
comment.last_modified, datetime(2008, 7, 2, tzinfo=timezone.utc)
)

def test_evaluator_comment(self):
cve = CVE.from_dict(
Expand Down
5 changes: 3 additions & 2 deletions tests/nvd/models/test_cve_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# ruff: noqa: E501

import unittest
from datetime import datetime
from datetime import datetime, timezone
from uuid import UUID

from pontos.nvd.models.cve_change import CVEChange, Detail, EventName
Expand All @@ -25,7 +25,8 @@ def test_required_only(self):
)
self.assertEqual(cve_change.source_identifier, "[email protected]")
self.assertEqual(
cve_change.created, datetime(2022, 3, 18, 20, 13, 8, 123000)
cve_change.created,
datetime(2022, 3, 18, 20, 13, 8, 123000, tzinfo=timezone.utc),
)
self.assertEqual(
cve_change.details,
Expand Down

0 comments on commit e2dd009

Please sign in to comment.