Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
1d6f4f4c
Commit
1d6f4f4c
authored
2 years ago
by
Jonas Braathen
Browse files
Options
Downloads
Patches
Plain Diff
Change Cerebrum sponsor import to replace manual SponsorOrganizationalUnits with an automatic one
parent
64fd0eb4
No related branches found
No related tags found
1 merge request
!366
Change Cerebrum sponsor import to replace manual SponsorOrganizationalUnits with an automatic one
Pipeline
#175788
passed
2 years ago
Stage: venv update
Stage: tests and linting
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
greg/management/commands/import_sponsors_from_cerebrum.py
+20
-7
20 additions, 7 deletions
greg/management/commands/import_sponsors_from_cerebrum.py
greg/tests/management/test_import_sponsors_from_cerebrum.py
+17
-0
17 additions, 0 deletions
greg/tests/management/test_import_sponsors_from_cerebrum.py
with
37 additions
and
7 deletions
greg/management/commands/import_sponsors_from_cerebrum.py
+
20
−
7
View file @
1d6f4f4c
...
...
@@ -40,18 +40,31 @@ class Command(BaseCommand):
def
_upsert_sponsor_unit_link
(
self
,
sponsor
:
Sponsor
,
unit
:
OrganizationalUnit
):
"""
Ensure a link between sponsor and unit.
"""
sunit
,
created
=
SponsorOrganizationalUnit
.
objects
.
get_or_create
(
sponsor
=
sponsor
,
organizational_unit
=
unit
,
source
=
self
.
CEREBRUM_SOURCE
,
automatic
=
True
,
defaults
=
{
"
hierarchical_access
"
:
settings
.
CEREBRUM_HIERARCHICAL_ACCESS
},
)
try
:
sunit
=
SponsorOrganizationalUnit
.
objects
.
get
(
sponsor
=
sponsor
,
organizational_unit
=
unit
,
)
created
=
False
except
SponsorOrganizationalUnit
.
DoesNotExist
:
sunit
=
SponsorOrganizationalUnit
.
objects
.
create
(
sponsor
=
sponsor
,
organizational_unit
=
unit
,
source
=
self
.
CEREBRUM_SOURCE
,
automatic
=
True
,
hierarchical_access
=
settings
.
CEREBRUM_HIERARCHICAL_ACCESS
,
)
created
=
True
if
created
:
logger
.
info
(
"
sponsor_ou_link_create
"
,
sponsor
=
sponsor
.
id
,
sunit
=
sunit
.
id
)
else
:
logger
.
info
(
"
sponsor_ou_link_found
"
,
sponsor
=
sponsor
.
id
,
sunit
=
sunit
.
id
)
sunit
.
source
=
self
.
CEREBRUM_SOURCE
sunit
.
automatic
=
True
sunit
.
hierarchical_access
=
settings
.
CEREBRUM_HIERARCHICAL_ACCESS
changes
=
sunit
.
get_dirty_fields
(
check_relationship
=
True
,
verbose
=
True
)
if
changes
:
logger
.
info
(
"
sponsor_ou_link_changed
"
,
changes
=
changes
)
sunit
.
save
()
return
SponsorOrganizationalUnit
.
objects
.
get
(
id
=
sunit
.
id
)
...
...
This diff is collapsed.
Click to expand it.
greg/tests/management/test_import_sponsors_from_cerebrum.py
+
17
−
0
View file @
1d6f4f4c
...
...
@@ -150,3 +150,20 @@ def test_import_sponsors_from_cerebrum(
# One excluded from unit with stedkode in manual list
assert
Sponsor
.
objects
.
all
().
count
()
==
2
assert
SponsorOrganizationalUnit
.
objects
.
count
()
==
2
# when a SponsorOrganizationalUnit with source != 'cerebrum'
# and automatic = False exists, replace it with an automatic one
sunit_lookup
=
dict
(
organizational_unit__identifiers__name
=
"
legacy_stedkode
"
,
organizational_unit__identifiers__value
=
"
234567
"
,
)
sunit
=
SponsorOrganizationalUnit
.
objects
.
filter
(
**
sunit_lookup
).
first
()
assert
isinstance
(
sunit
,
SponsorOrganizationalUnit
)
sunit
.
source
=
"
manual
"
sunit
.
automatic
=
False
sunit
.
save
()
call_command
(
"
import_sponsors_from_cerebrum
"
)
sunit
=
SponsorOrganizationalUnit
.
objects
.
filter
(
**
sunit_lookup
).
first
()
assert
isinstance
(
sunit
,
SponsorOrganizationalUnit
)
assert
sunit
.
source
==
"
cerebrum
"
assert
sunit
.
automatic
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment