def test_typo(self):
     tsr = TimestampRange()
     assert tsr.min is None
     assert tsr.get("min") is None
     assert {} == json.loads(json.dumps(tsr))
     tsr["max"] = 4
     assert {"max": 4} == json.loads(json.dumps(tsr))
     tsr.mun = 4
     assert {"max": 4} == json.loads(json.dumps(tsr))
 def test_timestamprange(self):
     tsr = TimestampRange(min=1, max=2)
     assert 1 == tsr.min
     assert 2 == tsr.max
     assert 1 == tsr["min"]
     assert 2 == tsr["max"]
     tsr.max = 3
     assert 3 == tsr["max"]
     tsr["max"] = 4
     assert 4 == tsr["max"]
     assert {"max": 4, "min": 1} == json.loads(json.dumps(tsr))
Beispiel #3
0
 def _load(cls, resource: Union[Dict, str], cognite_client=None):
     instance = super(UnstructuredSearchFileFilter,
                      cls)._load(resource, cognite_client)
     if isinstance(resource, Dict):
         if instance.asset_ids is not None:
             instance.asset_ids = AssetIdsFilter(**instance.asset_ids)
         if instance.created_time is not None:
             instance.created_time = TimestampRange(**instance.created_time)
         if instance.last_updated_time is not None:
             instance.last_updated_time = TimestampRange(
                 **instance.last_updated_time)
         if instance.uploaded_time is not None:
             instance.uploaded_time = TimestampRange(
                 **instance.uploaded_time)
         if instance.source_created_time is not None:
             instance.source_created_time = TimestampRange(
                 **instance.source_created_time)
         if instance.source_modified_time is not None:
             instance.source_modified_time = TimestampRange(
                 **instance.source_modified_time)
     return instance
 def test_list_with_timestamp_range(self, mock_ds_response):
     DS_API.list(created_time=TimestampRange(min=20))
     assert 20 == jsgz_load(mock_ds_response.calls[0].request.body)["filter"]["createdTime"]["min"]
     assert "max" not in jsgz_load(mock_ds_response.calls[0].request.body)["filter"]["createdTime"]
 def test_list_with_timestamp_range(self, mock_events_response):
     EVENTS_API.list(start_time=TimestampRange(min=20))
     assert 20 == jsgz_load(mock_events_response.calls[0].request.body
                            )["filter"]["startTime"]["min"]
     assert "max" not in jsgz_load(
         mock_events_response.calls[0].request.body)["filter"]["startTime"]
 def test_one_missing(self):
     tsr = TimestampRange(min=1)
     assert {"min": 1} == json.loads(json.dumps(tsr))