@@ -233,10 +233,36 @@ def maintainer(make_maintainer: Callable[..., NixMaintainer]) -> NixMaintainer:
233233 return make_maintainer ()
234234
235235
236+ @pytest .fixture
237+ def make_metadata (maintainer : NixMaintainer ) -> Callable [..., NixDerivationMeta ]:
238+ def wrapped (
239+ maintainer : NixMaintainer = maintainer ,
240+ ) -> NixDerivationMeta :
241+ meta = NixDerivationMeta .objects .create (
242+ homepage = "https://example.com" ,
243+ description = "My package" ,
244+ insecure = False ,
245+ available = True ,
246+ broken = False ,
247+ unfree = False ,
248+ unsupported = False ,
249+ )
250+ meta .maintainers .add (maintainer )
251+ return meta
252+
253+ return wrapped
254+
255+
256+ @pytest .fixture
257+ def metadata (make_metadata : Callable [..., NixDerivationMeta ]) -> NixDerivationMeta :
258+ return make_metadata ()
259+
260+
236261@pytest .fixture
237262def make_drv (
238- maintainer : NixMaintainer ,
239263 evaluation : NixEvaluation ,
264+ maintainer : NixMaintainer ,
265+ make_metadata : Callable [..., NixDerivationMeta ],
240266) -> Callable [..., NixDerivation ]:
241267 def wrapped (
242268 # Like `pname` in `mkDerivation`
@@ -245,22 +271,21 @@ def wrapped(
245271 system : str = "x86_64-linux" ,
246272 attribute : str | None = None ,
247273 evaluation : NixEvaluation = evaluation ,
274+ meta : NixDerivationMeta | None = None ,
248275 maintainer : NixMaintainer = maintainer ,
249276 ) -> NixDerivation :
250- description = "Dummy derivation"
251- homepage = "https://nix.example.com"
252- meta = NixDerivationMeta .objects .create (
253- description = description ,
254- homepage = homepage ,
255- insecure = False ,
256- available = True ,
257- broken = False ,
258- unfree = False ,
259- unsupported = False ,
277+
278+ if meta is None :
279+ meta = make_metadata (maintainer = maintainer )
280+
281+ # get_or_create so callers can safely pass an existing meta that already
282+ # has description/homepage rows (e.g. from make_metadata or a previous call).
283+ NixDerivationDescription .objects .get_or_create (
284+ metadata = meta , defaults = {"text" : meta .description }
285+ )
286+ NixDerivationHomepage .objects .get_or_create (
287+ metadata = meta , defaults = {"url" : meta .homepage }
260288 )
261- NixDerivationDescription .objects .create (metadata = meta , text = description )
262- NixDerivationHomepage .objects .create (metadata = meta , url = homepage )
263- meta .maintainers .add (maintainer )
264289
265290 if attribute is None :
266291 attribute = pname
@@ -459,17 +484,3 @@ def wrapped(
459484 return create_package_subscription_notifications (suggestion )
460485
461486 return wrapped
462-
463-
464- @pytest .fixture
465- def legacy_meta (db : None ) -> NixDerivationMeta :
466- """Create a NixDerivationMeta with only the legacy columns set, no new-table rows."""
467- return NixDerivationMeta .objects .create (
468- homepage = "https://example.com" ,
469- description = "My package" ,
470- insecure = False ,
471- available = True ,
472- broken = False ,
473- unfree = False ,
474- unsupported = False ,
475- )
0 commit comments