|
| 1 | +import secrets |
| 2 | +from collections.abc import Callable |
| 3 | + |
1 | 4 | import pytest |
2 | 5 | from allauth.socialaccount.models import SocialAccount |
3 | 6 | from django.contrib.auth.models import AbstractBaseUser |
|
19 | 22 | ProvenanceFlags, |
20 | 23 | ) |
21 | 24 | from shared.models.nix_evaluation import ( |
| 25 | + MAJOR_CHANNELS, |
22 | 26 | NixChannel, |
23 | 27 | NixDerivation, |
24 | 28 | NixDerivationMeta, |
@@ -49,51 +53,75 @@ def cve(db: None) -> Container: |
49 | 53 |
|
50 | 54 |
|
51 | 55 | @pytest.fixture |
52 | | -def evaluation(db: None) -> NixEvaluation: |
53 | | - channel = NixChannel.objects.create( |
54 | | - staging_branch="release-24.05", |
55 | | - channel_branch="release-24.05", |
| 56 | +def channel(db: None) -> NixChannel: |
| 57 | + # FIXME(@fricklerhandwerk): This will fall apart when we obtain the channel structure dynamically [ref:channel-structure] |
| 58 | + release = MAJOR_CHANNELS[1] |
| 59 | + return NixChannel.objects.create( |
| 60 | + staging_branch=f"nixos-{release}", |
| 61 | + channel_branch=f"nixos-{release}", |
56 | 62 | head_sha1_commit="deadbeef", |
57 | 63 | state=NixChannel.ChannelState.STABLE, |
58 | | - release_version="24.05", |
| 64 | + release_version=release, |
59 | 65 | repository="https://github.com/NixOS/nixpkgs", |
60 | 66 | ) |
61 | 67 |
|
62 | | - evaluation = NixEvaluation.objects.create( |
63 | | - channel=channel, |
64 | | - commit_sha1="deadbeef", |
65 | | - state="completed", |
66 | | - ) |
67 | | - return evaluation |
| 68 | + |
| 69 | +@pytest.fixture |
| 70 | +def make_evaluation(channel: NixChannel) -> Callable[[], NixEvaluation]: |
| 71 | + def wrapped() -> NixEvaluation: |
| 72 | + return NixEvaluation.objects.create( |
| 73 | + channel=channel, |
| 74 | + commit_sha1=secrets.token_hex(16), |
| 75 | + state="completed", |
| 76 | + ) |
| 77 | + |
| 78 | + return wrapped |
| 79 | + |
| 80 | + |
| 81 | +@pytest.fixture |
| 82 | +def evaluation(make_evaluation: Callable[[], NixEvaluation]) -> NixEvaluation: |
| 83 | + return make_evaluation() |
68 | 84 |
|
69 | 85 |
|
70 | 86 | @pytest.fixture |
71 | | -def drv(db: None, evaluation: NixEvaluation) -> NixDerivation: |
72 | | - maintainer = NixMaintainer.objects.create( |
| 87 | +def maintainer(db: None) -> NixMaintainer: |
| 88 | + return NixMaintainer.objects.create( |
73 | 89 | github_id=123, github="testuser", name="Test User", email="test@example.com" |
74 | 90 | ) |
75 | 91 |
|
76 | | - meta = NixDerivationMeta.objects.create( |
77 | | - description="First dummy derivation", |
78 | | - insecure=False, |
79 | | - available=True, |
80 | | - broken=False, |
81 | | - unfree=False, |
82 | | - unsupported=False, |
83 | | - ) |
84 | 92 |
|
85 | | - meta.maintainers.add(maintainer) |
| 93 | +@pytest.fixture |
| 94 | +def make_drv(maintainer: NixMaintainer) -> Callable[[NixEvaluation], NixDerivation]: |
| 95 | + def wrapped(evaluation: NixEvaluation) -> NixDerivation: |
| 96 | + meta = NixDerivationMeta.objects.create( |
| 97 | + description="Dummy derivation", |
| 98 | + insecure=False, |
| 99 | + available=True, |
| 100 | + broken=False, |
| 101 | + unfree=False, |
| 102 | + unsupported=False, |
| 103 | + ) |
| 104 | + meta.maintainers.add(maintainer) |
| 105 | + |
| 106 | + return NixDerivation.objects.create( |
| 107 | + attribute="foo", |
| 108 | + derivation_path="/nix/store/<hash>-foo.drv", |
| 109 | + name="foo-1.0", |
| 110 | + metadata=meta, |
| 111 | + system="x86_64-linux", |
| 112 | + parent_evaluation=evaluation, |
| 113 | + ) |
| 114 | + |
| 115 | + return wrapped |
86 | 116 |
|
87 | | - drv = NixDerivation.objects.create( |
88 | | - attribute="foo", |
89 | | - derivation_path="/nix/store/<hash>-foo.drv", |
90 | | - name="foo-1.0", |
91 | | - metadata=meta, |
92 | | - system="x86_64-linux", |
93 | | - parent_evaluation=evaluation, |
94 | | - ) |
95 | 117 |
|
96 | | - return drv |
| 118 | +@pytest.fixture |
| 119 | +def drv( |
| 120 | + db: None, |
| 121 | + make_drv: Callable[[NixEvaluation], NixDerivation], |
| 122 | + evaluation: NixEvaluation, |
| 123 | +) -> NixDerivation: |
| 124 | + return make_drv(evaluation) |
97 | 125 |
|
98 | 126 |
|
99 | 127 | @pytest.fixture |
|
0 commit comments