Skip to content

Commit

Permalink
test: Remove use of pytest-factoryboy
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Nov 7, 2024
1 parent 023da47 commit 1ff9408
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 32 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
'factory-boy==3.3.1',
'pytest==8.3.3',
'pytest-django==4.9.0',
'pytest-factoryboy==2.7.0',
'pytest-mock==3.14.0',
],
},
Expand Down
32 changes: 1 addition & 31 deletions uvdat/core/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
from django.contrib.auth.models import User
from django.contrib.gis.geos import Point
import pytest
from pytest_factoryboy import register
from rest_framework.test import APIClient

from uvdat.core.models import Project

from .factories import (
DatasetFactory,
NetworkEdgeFactory,
NetworkFactory,
NetworkNodeFactory,
ProjectFactory,
RasterMapLayerFactory,
SuperUserFactory,
UserFactory,
VectorMapLayerFactory,
)

register(UserFactory)
register(SuperUserFactory, 'superuser')
register(ProjectFactory)
register(DatasetFactory)
register(NetworkFactory)
register(NetworkNodeFactory)
register(NetworkEdgeFactory)
register(RasterMapLayerFactory)
register(VectorMapLayerFactory)


# Override the existing `project` pytest fixture, to ensure that
# when a project is created, it always has an owner
@pytest.fixture
def project(user_factory, project_factory) -> Project:
project = project_factory()
project.set_owner(user_factory())
return project
from .factory_fixtures import * # noqa: F403


@pytest.fixture
Expand Down
116 changes: 116 additions & 0 deletions uvdat/core/tests/factory_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import pytest

from uvdat.core.models import Project

from .factories import (
DatasetFactory,
NetworkEdgeFactory,
NetworkFactory,
NetworkNodeFactory,
ProjectFactory,
RasterMapLayerFactory,
SuperUserFactory,
UserFactory,
VectorMapLayerFactory,
)


# User
@pytest.fixture
def user_factory():
return UserFactory


@pytest.fixture
def user(user_factory):
return user_factory()


@pytest.fixture
def superuser_factory():
return SuperUserFactory


@pytest.fixture
def superuser(superuser_factory):
return superuser_factory()


# Project
@pytest.fixture
def project_factory():
return ProjectFactory


# Ensure that when a project is created, it always has an owner
@pytest.fixture
def project(user_factory, project_factory) -> Project:
project = project_factory()
project.set_owner(user_factory())
return project


# Dataset
@pytest.fixture
def dataset_factory():
return DatasetFactory


@pytest.fixture
def dataset(dataset_factory):
return dataset_factory()


# Network
@pytest.fixture
def network_factory():
return NetworkFactory


@pytest.fixture
def network(network_factory):
return network_factory()


# Network Node
@pytest.fixture
def network_node_factory():
return NetworkNodeFactory


@pytest.fixture
def network_node(network_node_factory):
return network_node_factory()


# Network Edge
@pytest.fixture
def network_edge_factory():
return NetworkEdgeFactory


@pytest.fixture
def network_edge(network_edge_factory):
return network_edge_factory()


# Raster Map Layer
@pytest.fixture
def raster_map_layer_factory():
return RasterMapLayerFactory


@pytest.fixture
def raster_map_layer(raster_map_layer_factory):
return raster_map_layer_factory()


# Vector Map Layer
@pytest.fixture
def vector_map_layer_factory():
return VectorMapLayerFactory


@pytest.fixture
def vector_map_layer(vector_map_layer_factory):
return vector_map_layer_factory()

0 comments on commit 1ff9408

Please sign in to comment.