Skip to content

Commit

Permalink
Disable Location post_save signal when testing
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Sep 10, 2024
1 parent 77a8add commit 87bbdca
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 45 deletions.
8 changes: 0 additions & 8 deletions open_prices/api/locations/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from django.db.models import signals
from django.test import TestCase
from django.urls import reverse

from open_prices.locations.factories import LocationFactory
from open_prices.locations.models import (
Location,
location_post_create_fetch_data_from_openstreetmap,
)

LOCATION_NODE_652825274 = {
"osm_id": 652825274,
Expand Down Expand Up @@ -134,9 +129,6 @@ def test_location_detail_by_osm(self):
class LocationCreateApiTest(TestCase):
@classmethod
def setUpTestData(cls):
signals.post_save.disconnect(
location_post_create_fetch_data_from_openstreetmap, sender=Location
)
cls.url = reverse("api:locations-list")

def test_location_create(self):
Expand Down
9 changes: 1 addition & 8 deletions open_prices/api/prices/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from django.db.models import signals
from django.test import TestCase
from django.urls import reverse

from open_prices.locations.models import (
Location,
location_post_create_fetch_data_from_openstreetmap,
)
from open_prices.locations.models import Location
from open_prices.prices import constants as price_constants
from open_prices.prices.factories import PriceFactory
from open_prices.prices.models import Price
Expand Down Expand Up @@ -263,9 +259,6 @@ def test_price_detail(self):
class PriceCreateApiTest(TestCase):
@classmethod
def setUpTestData(cls):
signals.post_save.disconnect(
location_post_create_fetch_data_from_openstreetmap, sender=Location
)
cls.url = reverse("api:prices-list")
cls.user_session = SessionFactory()
cls.user_proof = ProofFactory(
Expand Down
8 changes: 0 additions & 8 deletions open_prices/api/proofs/tests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from io import BytesIO

from django.db.models import signals
from django.test import TestCase
from django.urls import reverse
from PIL import Image

from open_prices.locations import constants as location_constants
from open_prices.locations.models import (
Location,
location_post_create_fetch_data_from_openstreetmap,
)
from open_prices.proofs import constants as proof_constants
from open_prices.proofs.factories import ProofFactory
from open_prices.proofs.models import Proof
Expand Down Expand Up @@ -150,9 +145,6 @@ def test_proof_detail(self):
class ProofCreateApiTest(TestCase):
@classmethod
def setUpTestData(cls):
signals.post_save.disconnect(
location_post_create_fetch_data_from_openstreetmap, sender=Location
)
cls.url = reverse("api:proofs-upload")
cls.user_session = SessionFactory()
cls.data = {
Expand Down
12 changes: 7 additions & 5 deletions open_prices/locations/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.core.validators import ValidationError
from django.db import models
from django.db.models import Count, signals
Expand Down Expand Up @@ -101,8 +102,9 @@ def save(self, *args, **kwargs):
def location_post_create_fetch_data_from_openstreetmap(
sender, instance, created, **kwargs
):
if created:
async_task(
"open_prices.locations.tasks.fetch_and_save_data_from_openstreetmap",
instance,
)
if not settings.TESTING:
if created:
async_task(
"open_prices.locations.tasks.fetch_and_save_data_from_openstreetmap",
instance,
)
10 changes: 2 additions & 8 deletions open_prices/prices/tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from django.core.exceptions import ValidationError
from django.db.models import signals
from django.test import TestCase

from open_prices.locations import constants as location_constants
from open_prices.locations.factories import LocationFactory
from open_prices.locations.models import (
Location,
location_post_create_fetch_data_from_openstreetmap,
)
from open_prices.locations.models import Location
from open_prices.prices import constants as price_constants
from open_prices.prices.factories import PriceFactory
from open_prices.products.factories import ProductFactory
Expand All @@ -22,9 +18,7 @@
class PriceModelSaveTest(TestCase):
@classmethod
def setUpTestData(cls):
signals.post_save.disconnect(
location_post_create_fetch_data_from_openstreetmap, sender=Location
)
pass

def test_price_product_validation(self):
for PRODUCT_CODE_OK in ["8001505005707", 5]:
Expand Down
9 changes: 1 addition & 8 deletions open_prices/proofs/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from django.core.exceptions import ValidationError
from django.db.models import signals
from django.test import TestCase

from open_prices.locations import constants as location_constants
from open_prices.locations.models import (
Location,
location_post_create_fetch_data_from_openstreetmap,
)
from open_prices.prices.factories import PriceFactory
from open_prices.proofs.factories import ProofFactory
from open_prices.proofs.models import Proof
Expand All @@ -15,9 +10,7 @@
class ProofModelSaveTest(TestCase):
@classmethod
def setUpTestData(cls):
signals.post_save.disconnect(
location_post_create_fetch_data_from_openstreetmap, sender=Location
)
pass

def test_proof_date_validation(self):
for DATE_OK in [None, "2024-01-01"]:
Expand Down

0 comments on commit 87bbdca

Please sign in to comment.