Skip to content

Commit 8306d5e

Browse files
committed
Update tests to work with pydantic v2
1 parent 455af44 commit 8306d5e

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/zocalo/cli/configure_rabbitmq.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _(self, permissions: PermissionSpec):
7878
@functools.singledispatch
7979
def _info_to_spec(incoming, infos: list):
8080
cls = type(incoming)
81-
return [cls(**i.dict()) for i in infos]
81+
return [cls(**i.model_dump()) for i in infos]
8282

8383

8484
@functools.singledispatch

src/zocalo/util/rabbitmq.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ def binding_declare(self, binding: BindingSpec):
772772
endpoint = f"bindings/{binding.vhost}/e/{binding.source}/{binding.destination_type.value}/{binding.destination}"
773773
response = self.post(
774774
endpoint,
775-
json=binding.dict(
775+
json=binding.model_dump(
776776
exclude_defaults=True,
777777
exclude={"vhost", "source", "destination", "destination_type"},
778778
),
@@ -848,7 +848,7 @@ def exchange_declare(self, exchange: ExchangeSpec):
848848
endpoint = f"exchanges/{exchange.vhost}/{exchange.name}/"
849849
response = self.put(
850850
endpoint,
851-
json=exchange.dict(exclude_defaults=True, exclude={"name", "vhost"}),
851+
json=exchange.model_dump(exclude_defaults=True, exclude={"name", "vhost"}),
852852
)
853853
response.raise_for_status()
854854

@@ -873,7 +873,7 @@ def set_policy(self, policy: PolicySpec):
873873
endpoint = f"policies/{policy.vhost}/{policy.name}/"
874874
response = self.put(
875875
endpoint,
876-
json=policy.dict(
876+
json=policy.model_dump(
877877
exclude_defaults=True, exclude={"name", "vhost"}, by_alias=True
878878
),
879879
)
@@ -902,7 +902,8 @@ def queues(
902902
def queue_declare(self, queue: QueueSpec):
903903
endpoint = f"queues/{queue.vhost}/{queue.name}"
904904
response = self.put(
905-
endpoint, json=queue.dict(exclude_defaults=True, exclude={"name", "vhost"})
905+
endpoint,
906+
json=queue.model_dump(exclude_defaults=True, exclude={"name", "vhost"}),
906907
)
907908
response.raise_for_status()
908909

@@ -942,7 +943,9 @@ def permissions(
942943

943944
def set_permissions(self, permission: PermissionSpec):
944945
endpoint = f"permissions/{permission.vhost}/{permission.user}/"
945-
submission = permission.dict(exclude_defaults=True, exclude={"vhost", "user"})
946+
submission = permission.model_dump(
947+
exclude_defaults=True, exclude={"vhost", "user"}
948+
)
946949
response = self.put(endpoint, json=submission)
947950
response.raise_for_status()
948951

@@ -953,7 +956,7 @@ def clear_permissions(self, vhost: str, user: str):
953956

954957
def user_put(self, user: UserSpec):
955958
endpoint = f"users/{user.name}/"
956-
submission = user.dict(exclude_defaults=True, exclude={"name"})
959+
submission = user.model_dump(exclude_defaults=True, exclude={"name"})
957960
submission["tags"] = ",".join(submission["tags"])
958961
response = self.put(endpoint, json=submission)
959962
response.raise_for_status()
@@ -976,7 +979,8 @@ def vhost(self, name: str) -> VHostSpec:
976979
def add_vhost(self, vhost: VHostSpec):
977980
endpoint = f"vhosts/{vhost.name}/"
978981
response = self.put(
979-
endpoint, json=vhost.dict(exclude_defaults=True, exclude={"name", "vhost"})
982+
endpoint,
983+
json=vhost.model_dump(exclude_defaults=True, exclude={"name", "vhost"}),
980984
)
981985
response.raise_for_status()
982986

src/zocalo/util/slurm/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@ def get_job_info(self, job_id: int) -> models.JobInfo:
146146
endpoint = f"slurm/{self.version}/job/{job_id}"
147147
response = self.get(endpoint)
148148
job_info_resp = models.OpenapiJobInfoResp(**response.json())
149-
jobinfo = next(iter(dict(job_info_resp.jobs).get("__root__", [])))
149+
jobinfo = next(iter(dict(job_info_resp.jobs).get("root", [])))
150150
return jobinfo
151151

152152
def submit_job(
153153
self, job_submission: models.JobSubmitReq
154154
) -> models.JobSubmitResponseMsg:
155155
endpoint = f"slurm/{self.version}/job/submit"
156-
response = self.post(endpoint, json=job_submission.dict(exclude_defaults=True))
156+
response = self.post(
157+
endpoint, json=job_submission.model_dump(exclude_defaults=True)
158+
)
157159
return models.JobSubmitResponseMsg(**response.json())

tests/util/test_rabbitmq.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def test_api_binding_declare(requests_mock, rmqapi, binding_spec):
190190
assert history.method == "POST"
191191
assert history.url.endswith("/api/bindings/zocalo/e/foo/q/bar")
192192
assert history.json() == {
193-
"arguments": binding_spec.arguments,
194193
"routing_key": "bar",
195194
}
196195

@@ -313,7 +312,6 @@ def test_api_exchange_declare(name, requests_mock, rmqapi):
313312
"type": "fanout",
314313
"auto_delete": True,
315314
"durable": True,
316-
"arguments": {},
317315
}
318316

319317

@@ -511,9 +509,7 @@ def test_api_add_vhost(requests_mock, rmqapi, vhost_spec):
511509
history = requests_mock.request_history[0]
512510
assert history.method == "PUT"
513511
assert history.url.endswith(f"/api/vhosts/{vhost_spec.name}/")
514-
assert history.json() == {
515-
"tags": [],
516-
}
512+
assert history.json() == {}
517513

518514

519515
def test_api_delete_vhost(requests_mock, rmqapi, vhost_spec):

tests/util/test_slurm.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ def test_get_job_info(requests_mock, slurm_api, jobs_response):
281281
)
282282
assert slurm_api.get_job_info(129) == next(
283283
iter(
284-
dict(slurm.models.OpenapiJobInfoResp(**jobs_response).jobs).get(
285-
"__root__", []
286-
)
284+
dict(slurm.models.OpenapiJobInfoResp(**jobs_response).jobs).get("root", [])
287285
)
288286
)

0 commit comments

Comments
 (0)