Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Enzo Yair
/
turismo-api
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Enzo Yair
2024-10-01 08:46:29 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d05f323416dad6758b825e1ad684cae71bf3e025
d05f3234
1 parent
81cc3b0f
finaliza app organismo
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
5 deletions
project/apps/organismo/api.py
project/apps/organismo/tests/factories.py
project/apps/organismo/tests/test_endpoint.py
project/router.py
project/settings/base.py
pytest.ini
requirements/testing.txt
project/apps/organismo/api.py
View file @
d05f323
...
...
@@ -6,15 +6,16 @@ from .serializers import OrganismoSerializer, DependenciaSerializer
class
OrganismoViewSets
(
viewsets
.
ReadOnlyModelViewSet
):
queryset
=
Organismo
.
objects
.
all
()
queryset
=
Organismo
.
objects
.
all
()
.
order_by
(
'id'
)
serializer_class
=
OrganismoSerializer
permission_classes
=
[
IsAuthenticated
,
]
lookup_field
=
'id'
class
DependenciaViewSets
(
viewsets
.
ReadOnlyModelViewSet
):
queryset
=
Dependencia
.
objects
.
all
()
queryset
=
Dependencia
.
objects
.
all
()
.
order_by
(
'id'
)
serializer_class
=
DependenciaSerializer
permission_classes
=
[
IsAuthenticated
,
]
lookup_field
=
'id'
...
...
project/apps/organismo/tests/factories.py
View file @
d05f323
...
...
@@ -2,3 +2,19 @@ import factory
from
factory
import
SubFactory
,
faker
,
django
from
organismo.models
import
Organismo
,
Dependencia
class
OrganimsoFactory
(
django
.
DjangoModelFactory
):
class
Meta
:
model
=
Organismo
short_name
=
faker
.
Faker
(
provider
=
'sentence'
,
nb_words
=
30
)
class
DependenciaFactory
(
django
.
DjangoModelFactory
):
class
Meta
:
model
=
Dependencia
organismo
=
SubFactory
(
factory
=
OrganimsoFactory
)
short_name
=
faker
.
Faker
(
provider
=
'sentence'
,
nb_words
=
30
)
\ No newline at end of file
...
...
project/apps/organismo/tests/test_endpoint.py
0 → 100644
View file @
d05f323
import
pytest
from
rest_framework
import
status
from
django.contrib.auth.models
import
User
from
django.urls
import
reverse
from
rest_framework.test
import
APIClient
from
organismo.tests.factories
import
OrganimsoFactory
,
DependenciaFactory
@pytest.mark.django_db
def
test_organismo_listado
():
cliente
=
APIClient
()
user
=
User
.
objects
.
create_user
(
username
=
'admin'
,
email
=
'admin@example.com'
,
password
=
'password123'
)
cliente
.
force_authenticate
(
user
=
user
)
OrganimsoFactory
.
create_batch
(
size
=
4
)
endpoint
=
reverse
(
'organismo-list'
)
response
=
cliente
.
get
(
path
=
endpoint
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
@pytest.mark.django_db
def
test_dependencia_listado
():
cliente
=
APIClient
()
user
=
User
.
objects
.
create_user
(
username
=
'admin'
,
email
=
'admin@example.com'
,
password
=
'password123'
)
cliente
.
force_authenticate
(
user
=
user
)
DependenciaFactory
.
create_batch
(
size
=
2
)
endpoint
=
reverse
(
'dependencia-list'
)
response
=
cliente
.
get
(
path
=
endpoint
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
\ No newline at end of file
...
...
project/router.py
View file @
d05f323
...
...
@@ -6,4 +6,4 @@ from organismo import api as organismo_api
router
=
routers
.
DefaultRouter
()
router
.
register
(
prefix
=
'organismo'
,
viewset
=
organismo_api
.
OrganismoViewSets
)
router
.
register
(
prefix
=
'dependencia'
,
viewset
=
organismo_api
.
OrganismoViewSets
)
\ No newline at end of file
router
.
register
(
prefix
=
'dependencia'
,
viewset
=
organismo_api
.
DependenciaViewSets
)
\ No newline at end of file
...
...
project/settings/base.py
View file @
d05f323
...
...
@@ -55,6 +55,9 @@ THIRD_PARTY_APPS = (
'rest_framework'
,
'django_filters'
,
'corsheaders'
,
'oauth2_provider'
,
'mozilla_django_oidc'
,
)
PROJECT_APPS
=
(
...
...
pytest.ini
View file @
d05f323
[pytest]
DJANGO_SETTINGS_MODULE
=
PROJECTproject-NAME
.settings.testing
DJANGO_SETTINGS_MODULE
=
project
.settings.testing
norecursedirs
=
requirements deployment
testpaths
=
test
s
testpaths
=
test
addopts
=
--capture=fd --nomigrations
...
...
requirements/testing.txt
View file @
d05f323
...
...
@@ -2,3 +2,4 @@
pytest==6.2.5
pytest-django==4.4.0
factory_boy==3.3.1
...
...
Please
register
or
login
to post a comment