Skip to content

DBC22-1890: Unit tests for current weather model #335

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/backend/apps/shared/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

from apps.cms.models import Ferry
from apps.event.models import Event
from apps.shared.views import FeedbackView
from apps.weather.models import RegionalWeather
from apps.webcam.models import Webcam
from django.core.cache import cache
from django.test import TestCase
from httpx import HTTPStatusError

from rest_framework.test import APIRequestFactory

from apps.shared.views import FeedbackView

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -52,4 +50,3 @@ def tearDown(self):
Event.objects.all().delete()
Ferry.objects.all().delete()
RegionalWeather.objects.all().delete()

2 changes: 1 addition & 1 deletion src/backend/apps/weather/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ def __str__(self):
return f"Current weather for {self.pk}"

def save(self, *args, **kwargs):
self.location = Point(self.location_latitude, self.location_longitude)
self.location = Point((self.location_latitude, self.location_longitude))
super().save(*args, **kwargs)
23 changes: 23 additions & 0 deletions src/backend/apps/weather/tests/test_current_weather_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from unittest.mock import patch

from apps.shared.tests import BaseTest
from apps.weather.models import BaseModel, CurrentWeather
from apps.weather.serializers import CurrentWeatherSerializer


def mocked_method(self):
# Method to block the base model save function
return True

class TestCurrentWeatherModel(BaseTest):

@patch.object(BaseModel, 'save', mocked_method)
def test_model_save(self):
current_weather_test = CurrentWeather(
weather_station_name="Vancouver",
location_latitude=58.66,
location_longitude=-124.64,
)
current_weather_test.save();

assert(current_weather_test.location == "SRID=4326;POINT (58.66 -124.64)")
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import json
from pathlib import Path
from unittest import skip
from unittest import mock, skip
from unittest.mock import patch

from apps.feed.client import FeedClient
from apps.shared.tests import BaseTest, MockResponse
from apps.weather.models import RegionalWeather
from apps.weather.tasks import (
populate_all_regional_weather_data,
populate_regional_weather_from_data,
populate_all_regional_weather_data,
)
from apps.weather.tests.test_data.regional_weather_parsed_feed import json_feed
from apps.feed.client import FeedClient
from unittest import mock

class TestRegionalWeatherModel(BaseTest):
def setUp(self):
Expand Down Expand Up @@ -82,4 +81,4 @@ def test_populate_all_regional_weather_data(self):
]

populate_all_regional_weather_data()
assert len(RegionalWeather.objects.all()) == 1
assert len(RegionalWeather.objects.all()) == 1