Skip to content

Commit

Permalink
Merge pull request #259 from nifedara/test/views
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma authored Aug 6, 2024
2 parents 0dab52e + b0b9441 commit fbb7691
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
pip install coverage
pip install factory-boy
- name: Creating env
- name: Create env
run: |
cd backend/
mv sample_env .env
Expand Down
2 changes: 1 addition & 1 deletion backend/login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get(self, request, format=None):


class callback(APIView):
def get(self, request, format=None):
def get(self, request, format=None): # pragma: no cover
"""Callback method redirected from osm callback method
Args:
Expand Down
6 changes: 6 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ distribution = true
dev = [
"commitizen>=3.27.0",
"ruff>=0.4.9",
"coverage>=7.6.0",
]

[tool.commitizen]
Expand All @@ -54,3 +55,8 @@ tag_format = "\"v$version\""
version_scheme = "semver2"
version = "1.0.1"
update_changelog_on_bump = true

[tool.coverage.run]
omit = [
"/usr/*"
]
137 changes: 137 additions & 0 deletions backend/tests/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import factory
from login.models import OsmUser
from django.contrib.gis.geos import Polygon
from core.models import (
Dataset,
AOI,
Label,
Model,
Training,
Feedback,
FeedbackAOI,
FeedbackLabel,
)


class OsmUserFactory(factory.django.DjangoModelFactory):
class Meta:
model = OsmUser

osm_id = 123456


class DatasetFactory(factory.django.DjangoModelFactory):
class Meta:
model = Dataset

name = "My test dataset"
source_imagery = "https://tiles.openaerialmap.org/5ac4fc6f26964b0010033112/0/5ac4fc6f26964b0010033113/{z}/{x}/{y}"
created_by = factory.SubFactory(OsmUserFactory)


class AoiFactory(factory.django.DjangoModelFactory):
class Meta:
model = AOI

geom = Polygon(
(
(32.588507094820351, 0.348666499011499),
(32.588517512656978, 0.348184682976698),
(32.588869114643053, 0.348171660921362),
(32.588840465592334, 0.348679521066151),
(32.588507094820351, 0.348666499011499),
)
)
dataset = factory.SubFactory(DatasetFactory)


class LabelFactory(factory.django.DjangoModelFactory):
class Meta:
model = Label

aoi = factory.SubFactory(AoiFactory)
geom = Polygon(
(
(32.588507094820351, 0.348666499011499),
(32.588517512656978, 0.348184682976698),
(32.588869114643053, 0.348171660921362),
(32.588840465592334, 0.348679521066151),
(32.588507094820351, 0.348666499011499),
)
)


class ModelFactory(factory.django.DjangoModelFactory):
class Meta:
model = Model

dataset = factory.SubFactory(DatasetFactory)
name = "My test model"
created_by = factory.SubFactory(OsmUserFactory)


class TrainingFactory(factory.django.DjangoModelFactory):
class Meta:
model = Training

model = factory.SubFactory(ModelFactory)
description = "My very first training"
created_by = factory.SubFactory(OsmUserFactory)
epochs = 1
zoom_level = [20, 21]
batch_size = 1


class FeedbackFactory(factory.django.DjangoModelFactory):
class Meta:
model = Feedback

geom = Polygon(
(
(32.588507094820351, 0.348666499011499),
(32.588517512656978, 0.348184682976698),
(32.588869114643053, 0.348171660921362),
(32.588840465592334, 0.348679521066151),
(32.588507094820351, 0.348666499011499),
)
)
training = factory.SubFactory(TrainingFactory)
zoom_level = 19
feedback_type = "TP"
user = factory.SubFactory(OsmUserFactory)
source_imagery = "https://tiles.openaerialmap.org/5ac4fc6f26964b0010033112/0/5ac4fc6f26964b0010033113/{z}/{x}/{y}"


class FeedbackAoiFactory(factory.django.DjangoModelFactory):
class Meta:
model = FeedbackAOI

training = factory.SubFactory(TrainingFactory)
geom = Polygon(
(
(32.588507094820351, 0.348666499011499),
(32.588517512656978, 0.348184682976698),
(32.588869114643053, 0.348171660921362),
(32.588840465592334, 0.348679521066151),
(32.588507094820351, 0.348666499011499),
)
)
label_status = -1
source_imagery = "https://tiles.openaerialmap.org/5ac4fc6f26964b0010033112/0/5ac4fc6f26964b0010033113/{z}/{x}/{y}"
user = factory.SubFactory(OsmUserFactory)


class FeedbackLabelFactory(factory.django.DjangoModelFactory):
class Meta:
model = FeedbackLabel

feedback_aoi = factory.SubFactory(FeedbackAoiFactory)
geom = Polygon(
(
(32.588507094820351, 0.348666499011499),
(32.588517512656978, 0.348184682976698),
(32.588869114643053, 0.348171660921362),
(32.588840465592334, 0.348679521066151),
(32.588507094820351, 0.348666499011499),
)
)
Loading

0 comments on commit fbb7691

Please sign in to comment.