Skip to content

Commit

Permalink
Datapoint: Ignore t1 value when passed.
Browse files Browse the repository at this point in the history
Required for "set value" endpoint.
Fixes broken tests.
  • Loading branch information
xsedla1o committed Sep 4, 2024
1 parent c186b9e commit 2b84577
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions dp3/common/datapoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ipaddress import IPv4Address, IPv6Address
from typing import Annotated, Any, Optional, Union

from pydantic import BaseModel, Field, PlainSerializer
from pydantic import BaseModel, BeforeValidator, Field, PlainSerializer

from dp3.common.types import T2Datetime

Expand All @@ -13,6 +13,11 @@ def to_json_friendly(v):
return v


def ignore_value(_v):
"""Ignore the passed value and return None."""
return None


class DataPointBase(BaseModel, use_enum_values=True):
"""Data-point
Expand Down Expand Up @@ -44,7 +49,7 @@ class DataPointPlainBase(DataPointBase):
the same naming for simplicity.
"""

t1: None = None
t1: Annotated[None, BeforeValidator(ignore_value)] = None
t2: None = None


Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_set_attr_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
class SetEidAttrValue(common.APITest):
def test_invalid_payload(self):
response = self.post_request(TESTED_PATH.format(action="set"), json={})
self.assertEqual(response.status_code, 422)
self.assertEqual(response.status_code, 422, msg=response.json())

def test_valid_payload(self):
payload = EntityEidAttrValue(value="Test string val1")
response = self.post_request(
TESTED_PATH.format(action="set"), data=payload.model_dump_json()
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 200, msg=response.json())

expected = EntityEidAttrValueOrHistory(attr_type=1, current_value="Test string val1")
self.query_expected_value(
Expand Down

0 comments on commit 2b84577

Please sign in to comment.