Commit 0b04bb1f authored by Gautier D's avatar Gautier D Committed by Gautier Daures
Browse files

fix(test): no more city and campus

parent f3dc7e3b
Pipeline #60292 passed with stages
in 4 minutes and 36 seconds
from os.path import abspath, join
from backend_app.load_data.utils import ASSETS_PATH, csv_2_dict_list
from backend_app.models.campus import Campus
from backend_app.models.city import City
from backend_app.models.country import Country
from backend_app.models.partner import Partner
from backend_app.models.university import University
......@@ -29,9 +27,6 @@ class LoadUniversities(LoadGeneric):
lon = round(float(row["lon"]), 6)
country = Country.objects.get(pk=row["country"])
city = City(name=row["city"], country=country)
city.save()
self.add_info_and_save(city, self.admin)
univ = University.objects.update_or_create(
pk=row["utc_id"], # Not perfect but should do the trick
......@@ -39,21 +34,15 @@ class LoadUniversities(LoadGeneric):
"name": row["university"],
"acronym": row["acronym"],
"website": row["website"],
"city": row["city"],
"country": country,
"main_campus_lat": lat,
"main_campus_lon": lon,
# "logo": row["logo"], # WARNING FIX BETA not ok
},
)[0]
self.add_info_and_save(univ, self.admin)
main_campus = Campus(
is_main_campus=True,
name="Campus - " + univ.name,
city=city,
university=univ,
lat=lat,
lon=lon,
)
self.add_info_and_save(main_campus, self.admin)
Partner.objects.update_or_create(
utc_id=row["utc_id"],
defaults=dict(
......
......@@ -4,8 +4,8 @@ from django.test import override_settings
from backend_app.models.for_testing.moderation import ForTestingModeration
from backend_app.models.pendingModeration import PendingModeration
from backend_app.models.university import University
from backend_app.tests.utils import WithUserTestCase
from backend_app.tests.utils import get_dummy_university
class ModerationTestCase(WithUserTestCase):
......@@ -206,9 +206,7 @@ class ModerationTestCase(WithUserTestCase):
Test to check that when moderation IS activated
no error regarding saving occures with foreing key
"""
c = University(name="Univ de test")
c.save()
data = {"comment": "", "useful_links": [], "universities": [c.pk]}
api_end_point = "/api/universityDri/?universities={}/".format(c.pk)
u = get_dummy_university()
data = {"comment": "", "useful_links": [], "universities": [u.pk]}
api_end_point = "/api/universityDri/?universities={}/".format(u.pk)
self._submit_post_test(self.dri_client, data, api_end_point)
......@@ -3,9 +3,9 @@ from django.test import TestCase
from base_app.models import User
from backend_app.models.userData import UserData
from backend_app.models.university import University
from backend_app.models.universityInfo import UniversityInfo
from backend_app.models.universitySemestersDates import UniversitySemestersDates
from backend_app.tests.utils import get_dummy_university
class AutomaticCreationPostCreateTestCase(TestCase):
......@@ -13,7 +13,7 @@ class AutomaticCreationPostCreateTestCase(TestCase):
def setUpTestData(cls):
cls.user = User.objects.create_user(username="toto")
cls.univ = University.objects.create(name="Univ de test")
cls.univ = get_dummy_university()
def test_user_data_automatically_created(self):
self.assertTrue(UserData.objects.filter(owner=self.user).exists())
......
from backend_app.models.university import University
from backend_app.tests.utils import WithUserTestCase
from backend_app.tests.utils import get_dummy_university
class WriteAccessTestCase(WithUserTestCase):
......@@ -9,7 +9,7 @@ class WriteAccessTestCase(WithUserTestCase):
@classmethod
def setUpMoreTestData(cls):
cls.univ = University.objects.create(name="Univ de test")
cls.univ = get_dummy_university()
cls.api_dri = "/api/universityDri/?universities={}/".format(cls.univ.pk)
cls.post_data = dict(
universities=[cls.univ.pk], title="qsdlkjqsmlkdj", useful_links="[]"
......
......@@ -2,6 +2,9 @@ from django.contrib.auth.models import Group
from django.test import TestCase
from rest_framework.test import APIClient
from backend_app.models.country import Country
from backend_app.models.university import University
from base_app.models import User
......@@ -82,3 +85,23 @@ class WithUserTestCase(TestCase):
@classmethod
def setUpMoreTestData(cls):
pass
def get_dummy_country() -> Country:
return Country.objects.update_or_create(
name="TE",
defaults=dict(iso_alpha2_code="TE", region_name="EU", region_un_code="EU"),
)[0]
def get_dummy_university() -> University:
return University.objects.update_or_create(
name="Université de Technologie de Compiègne",
defaults=dict(
acronym="UTC",
main_campus_lat=0,
main_campus_lon=0,
country=get_dummy_country(),
city="",
),
)[0]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment