Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/GitHub action #15

Closed
wants to merge 11 commits into from
Closed
7 changes: 6 additions & 1 deletion .github/workflows/backend_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:

- name: Run tests
env:
TESTING_TOKEN: ${{ secrets.TESTING_TOKEN }}
TESTING_TOKEN: ${{ os.environ['TESTING_TOKEN'] }}
run: |
cd backend/

Expand All @@ -129,3 +129,8 @@ jobs:
python manage.py migrate
python manage.py migrate login
python manage.py migrate core

pip install coverage
pip install factory-boy
coverage run manage.py test tests
coverage report
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