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
3e7f3a7b
Commit
3e7f3a7b
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
Fixing test
parent
c5922515
No related branches found
Branches containing commit
No related tags found
1 merge request
!100
Remove register endpoint
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gregui/tests/api/test_invite_guest.py
+28
-9
28 additions, 9 deletions
gregui/tests/api/test_invite_guest.py
gregui/tests/conftest.py
+51
-14
51 additions, 14 deletions
gregui/tests/conftest.py
with
79 additions
and
23 deletions
gregui/tests/api/test_invite_guest.py
+
28
−
9
View file @
3e7f3a7b
import
pytest
import
pytest
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.reverse
import
reverse
from
rest_framework.reverse
import
reverse
from
rest_framework.test
import
APIRequestFactory
,
force_authenticate
from
greg.models
import
Person
from
gregui.api.views.invitation
import
CreateInvitationView
@pytest.mark.django_db
@pytest.mark.django_db
def
test_invite_guest
(
client
):
def
test_invite_guest
(
client
,
user_sponsor
,
unit_foo
,
role_type_foo
):
data
=
{
"
first_name
"
:
"
Foo
"
,
"
last_name
"
:
"
Bar
"
,
"
email
"
:
"
test@example.com
"
,
"
role
"
:
{
data
=
{
'
first_name
'
:
'
Foo
'
,
'
last_name
'
:
'
Bar
'
,
'
email
'
:
'
test@example.com
'
,
'
role
'
:
{
"
start_date
"
:
"
2019-08-06
"
,
'
start_date
'
:
'
2019-08-06
'
,
"
end_date
"
:
"
2019-08-10
"
,
'
end_date
'
:
'
2019-08-10
'
,
"
id
"
:
1
'
orgunit_id
'
:
unit_foo
.
id
,
'
type
'
:
role_type_foo
.
id
}}
}}
url
=
reverse
(
"
gregui-v1:invite-create
"
)
url
=
reverse
(
'
gregui-v1:invite-create
'
)
response
=
client
.
post
(
url
,
data
,
format
=
"
json
"
)
all_persons
=
Person
.
objects
.
all
()
assert
len
(
all_persons
)
==
0
factory
=
APIRequestFactory
()
request
=
factory
.
post
(
url
,
data
,
format
=
'
json
'
)
force_authenticate
(
request
,
user
=
user_sponsor
)
view
=
CreateInvitationView
.
as_view
()
response
=
view
(
request
)
assert
response
.
status_code
==
status
.
HTTP_201_CREATED
assert
response
.
status_code
==
status
.
HTTP_201_CREATED
assert
response
.
json
()
==
{
"
id
"
:
1
,
**
data
}
all_persons
=
Person
.
objects
.
all
()
assert
len
(
all_persons
)
==
1
assert
all_persons
[
0
].
first_name
==
'
Foo
'
assert
all_persons
[
0
].
last_name
==
'
Bar
'
This diff is collapsed.
Click to expand it.
gregui/tests/conftest.py
+
51
−
14
View file @
3e7f3a7b
from
rest_framework.test
import
APIClient
import
logging
# from django.contrib.auth import get_user_model
from
django.contrib.auth
import
get_user_model
from
rest_framework.authtoken.admin
import
User
from
rest_framework.test
import
APIClient
import
pytest
import
pytest
# from greg.models import (
from
greg.models
import
Sponsor
,
OrganizationalUnit
,
RoleType
# Consent,
from
gregui.models
import
GregUserProfile
# Notification,
# Person,
# faker spams the logs with localisation warnings
# Sponsor,
# see https://github.com/joke2k/faker/issues/753
# SponsorOrganizationalUnit,
logging
.
getLogger
(
"
faker
"
).
setLevel
(
logging
.
ERROR
)
# Identity,
# Role,
# RoleType,
# OrganizationalUnit,
# ConsentType,
# )
@pytest.fixture
@pytest.fixture
def
client
()
->
APIClient
:
def
client
()
->
APIClient
:
client
=
APIClient
()
client
=
APIClient
()
return
client
return
client
@pytest.fixture
def
unit_foo
()
->
OrganizationalUnit
:
ou
=
OrganizationalUnit
.
objects
.
create
(
orgreg_id
=
"
12345
"
,
name_en
=
"
foo_unit
"
)
return
OrganizationalUnit
.
objects
.
get
(
id
=
ou
.
id
)
@pytest.fixture
def
role_type_foo
()
->
RoleType
:
rt
=
RoleType
.
objects
.
create
(
identifier
=
"
role_foo
"
,
name_en
=
"
Role Foo
"
)
return
RoleType
.
objects
.
get
(
id
=
rt
.
id
)
@pytest.fixture
def
sponsor_guy
(
unit_foo
:
OrganizationalUnit
)
->
Sponsor
:
sponsor
=
Sponsor
.
objects
.
create
(
feide_id
=
"
guy@example.org
"
,
first_name
=
"
Sponsor
"
,
last_name
=
"
Guy
"
)
sponsor
.
units
.
add
(
unit_foo
,
through_defaults
=
{
"
hierarchical_access
"
:
False
})
return
Sponsor
.
objects
.
get
(
id
=
sponsor
.
id
)
@pytest.fixture
def
user_sponsor
(
sponsor_guy
:
Sponsor
)
->
User
:
user_model
=
get_user_model
()
# Create a user and link him to a sponsor
user
=
user_model
.
objects
.
create
(
username
=
'
test_sponsor
'
,
email
=
'
test@example.org
'
,
first_name
=
"
Test
"
,
last_name
=
"
Sponsor
"
)
GregUserProfile
.
objects
.
create
(
user
=
user
,
sponsor
=
sponsor_guy
)
# This user is a sponsor for unit_foo
return
user
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