Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik van Velzen committed Apr 9, 2024
1 parent fe92f7d commit 61ab452
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 49 deletions.
1 change: 0 additions & 1 deletion .devcontainer/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SECRET_KEY=django-insecure-vzl9-zm-@ds!frap*7)zy0ppb5b1zh+#7%aq94jj@yh(@jtf&!
ALLOWED_HOSTS=localhost

#Anylogic
AL_API_KEY=al_api_key
RETURN_SCENARIO=True # setting that is used in the HOLON view to determine whether to send back the used scenario (through the serializer) or not

#DATABASE
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/django-code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
DB_HOST: localhost # default host value for the database
DB_NAME: djtesting
DB_PORT: 5432
AL_API_KEY: test-api-key
services:
postgres_main:
image: postgres:13.9
Expand Down
25 changes: 24 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.1"

services:
# Setup to run a reverse proxy in front of the app
# to run them from a single domain.
Expand Down Expand Up @@ -75,6 +75,29 @@ services:
DJANGO_SETTINGS_MODULE: pipit.settings.prod
env_file: ./docker/config/python.env

python-test:
build:
context: ./src
dockerfile: Dockerfile
entrypoint: "python manage.py"
command: "test"
volumes:
- "./src:/app"
depends_on:
- db
environment:
ALLOWED_HOSTS: "*"
DB_HOST: db
DB_USER: postgres
DB_NAME: djangotest
DB_PASSWORD: postgres
RETURN_SCENARIO: false
SECRET_KEY: 5746384
DOMAIN_HOST: http://localhost:8000
N_WORKERS: 2
DJANGO_SETTINGS_MODULE: pipit.settings.test
env_file: ./docker/config/python.env

db:
image: postgres:13.9
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker/config/python.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ SENTRY_ENVIRONMENT=development
SECRET_KEY=asdfasdf
ALLOWED_HOSTS=*
DOMAIN_HOST="https://pizzaoven.holontool.nl"
# Set to enable remote debugging with PyCharm
# Set to enable remote debugging with PyCharm or IntelliJ
PYCHARM_IP=172.17.0.1
PYCHARM_PORT=9222
10 changes: 5 additions & 5 deletions src/holon/fixtures/archive/scenario-config-fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"scenario": 1,
"module": "upscaling",
"name": "National upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 2203642
}
},
Expand All @@ -65,7 +65,7 @@
"scenario": 1,
"module": "cost",
"name": "Cost module",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 2175158
}
},
Expand All @@ -76,7 +76,7 @@
"scenario": 1,
"module": "upscaling",
"name": "Regional upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 2203666
}
},
Expand All @@ -87,7 +87,7 @@
"scenario": 1,
"module": "costbenefit",
"name": "",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 987511684
}
},
Expand Down Expand Up @@ -312,4 +312,4 @@
"wildcard_JSON": null
}
}
]
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@
"scenario": 1,
"module": "upscaling",
"name": "National upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 2203642
}
},
Expand All @@ -2306,7 +2306,7 @@
"scenario": 1,
"module": "cost",
"name": "Cost module",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 2175158
}
},
Expand All @@ -2317,7 +2317,7 @@
"scenario": 1,
"module": "upscaling",
"name": "Regional upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 2203666
}
},
Expand All @@ -2328,7 +2328,7 @@
"scenario": 1,
"module": "costbenefit",
"name": "",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 987511684
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/holon/fixtures/jorrit/ref/tvw-CLEANSMALL.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/holon/fixtures/jorrit/ref/tvw-POSTCLEANUP.json
Original file line number Diff line number Diff line change
Expand Up @@ -90043,7 +90043,7 @@
"scenario": 1,
"module": "upscaling",
"name": "National upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand All @@ -90054,7 +90054,7 @@
"scenario": 1,
"module": "cost",
"name": "Gebiedskosten",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand All @@ -90065,7 +90065,7 @@
"scenario": 1,
"module": "costbenefit",
"name": "National upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand All @@ -90076,7 +90076,7 @@
"scenario": 1,
"module": "costbenefit",
"name": "Cost module",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand Down Expand Up @@ -90461,4 +90461,4 @@
"wildcard_JSON": null
}
}
]
]
2 changes: 1 addition & 1 deletion src/holon/fixtures/jorrit/ref/tvw-POSTSCALEUP.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/holon/fixtures/jorrit/ref/tvw-PRESCALEUP.json
Original file line number Diff line number Diff line change
Expand Up @@ -5362,7 +5362,7 @@
"scenario": 1,
"module": "upscaling",
"name": "National upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand All @@ -5373,7 +5373,7 @@
"scenario": 1,
"module": "cost",
"name": "Gebiedskosten",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand All @@ -5384,7 +5384,7 @@
"scenario": 1,
"module": "costbenefit",
"name": "National upscaling",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand All @@ -5395,7 +5395,7 @@
"scenario": 1,
"module": "costbenefit",
"name": "Cost module",
"api_url": "https://beta-engine.energytransitionmodel.com/api/v3/scenarios/",
"api_url": "https://engine.energytransitionmodel.com/api/v3/scenarios/",
"etm_scenario_id": 123456
}
},
Expand Down Expand Up @@ -5785,4 +5785,4 @@
"wildcard_JSON": null
}
}
]
]
2 changes: 1 addition & 1 deletion src/holon/fixtures/pizza.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ class Migration(migrations.Migration):
(
"api_url",
models.URLField(
default="https://beta-engine.energytransitionmodel.com/api/v3/scenarios/"
default="https://engine.energytransitionmodel.com/api/v3/scenarios/"
),
),
("etm_scenario_id", models.IntegerField()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='queryandconvertconfig',
name='api_url',
field=models.URLField(db_comment='This is currently not used and should be removed', default='https://beta-engine.energytransitionmodel.com/api/v3/scenarios/'),
field=models.URLField(db_comment='This is currently not used and should be removed', default='https://engine.energytransitionmodel.com/api/v3/scenarios/'),
),
]
20 changes: 20 additions & 0 deletions src/holon/migrations/0062_alter_queryandconvertconfig_api_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.6 on 2024-04-09 07:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("holon", "0061_alter_queryandconvertconfig_api_url"),
]

operations = [
migrations.AlterField(
model_name="queryandconvertconfig",
name="api_url",
field=models.URLField(
default="https://engine.energytransitionmodel.com/api/v3/scenarios/"
),
),
]
2 changes: 1 addition & 1 deletion src/holon/models/config/query_and_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class QueryAndConvertConfig(ClusterableModel):
name = models.CharField(max_length=255, null=False, blank=True)

api_url = models.URLField(
# or https://beta-engine.energytransitionmodel.com/api/v3/scenarios/
# or https://engine.energytransitionmodel.com/api/v3/scenarios/
default="https://engine.energytransitionmodel.com/api/v3/scenarios/",
)
etm_scenario_id = models.IntegerField()
Expand Down
11 changes: 8 additions & 3 deletions src/holon/rule_engine/repositories/repository_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from polymorphic import utils
from typing import Type
from typing import Type, Iterator
from django.db.models import Model
from polymorphic.models import PolymorphicModel
from modelcluster.models import ClusterableModel
Expand Down Expand Up @@ -227,14 +227,19 @@ def add(self, new_object: Model) -> Model:

# copy object and set new id
cloned_new_object = deepcopy(new_object)
cloned_new_object.pk = cloned_new_object.id = next(self.id_counter)

new_id = next(self.id_counter)
while new_id <= new_object.id:
new_id = next(self.id_counter)

cloned_new_object.pk = cloned_new_object.id = new_id

# add new object to list and return new object
self.objects.append(cloned_new_object)

return cloned_new_object

def id_counter_generator(self, objects: list[Model]) -> list[int]:
def id_counter_generator(self, objects: list[Model]) -> Iterator[int]:
"""Generator to keep track of new ids"""

max_id = max([object.id for object in objects], default=0)
Expand Down
23 changes: 12 additions & 11 deletions src/holon/tests/aggregate/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self) -> None:
insulation_label=InsulationLabel.A,
heating_type=HeatingType.GASBURNER,
type=BuildingType.LOGISTICS,
id=0,
# id=0,
)
self.gridconnection_1: BuildingGridConnection = BuildingGridConnection.objects.create(
owner_actor=self.actor1,
Expand All @@ -33,7 +33,7 @@ def setUp(self) -> None:
insulation_label=InsulationLabel.A,
heating_type=HeatingType.GASBURNER,
type=BuildingType.LOGISTICS,
id=1,
# id=1,
)
self.gridconnection_2: BuildingGridConnection = BuildingGridConnection.objects.create(
owner_actor=self.actor2,
Expand All @@ -42,7 +42,7 @@ def setUp(self) -> None:
insulation_label=InsulationLabel.A,
heating_type=HeatingType.GASBURNER,
type=BuildingType.LOGISTICS,
id=2,
# id=2,
)
self.asset1 = ElectricHeatConversionAsset.objects.create(
gridconnection=self.gridconnection_0,
Expand All @@ -51,7 +51,7 @@ def setUp(self) -> None:
eta_r=0.95,
deliveryTemp_degC=70.0,
capacityElectricity_kW=30.0,
id=1,
# id=1,
)
self.asset2 = ElectricHeatConversionAsset.objects.create(
gridconnection=self.gridconnection_0,
Expand All @@ -60,7 +60,7 @@ def setUp(self) -> None:
eta_r=0.95,
deliveryTemp_degC=70.0,
capacityElectricity_kW=30.0,
id=2,
# id=2,
)
self.asset3 = ElectricHeatConversionAsset.objects.create(
gridconnection=self.gridconnection_1,
Expand All @@ -69,7 +69,7 @@ def setUp(self) -> None:
eta_r=0.95,
deliveryTemp_degC=70.0,
capacityElectricity_kW=30.0,
id=3,
# id=3,
)
self.asset4 = ElectricHeatConversionAsset.objects.create(
gridconnection=self.gridconnection_2,
Expand All @@ -78,7 +78,7 @@ def setUp(self) -> None:
eta_r=0.95,
deliveryTemp_degC=70.0,
capacityElectricity_kW=30.0,
id=4,
# id=4,
)

self.scenario_aggregate = ScenarioAggregate(self.scenario)
Expand All @@ -100,12 +100,13 @@ def test_add_asset(self):
)
new_object = self.scenario_aggregate.add_object(asset5)

self.scenario_aggregate.repositories[ModelType.ENERGYASSET.value].get(
new_object.id
) == new_object
self.assertEqual(
self.scenario_aggregate.repositories[ModelType.ENERGYASSET.value].get(new_object.id),
new_object,
)

assert self.scenario_aggregate.repositories[ModelType.ENERGYASSET.value].len() == 5
assert new_object != asset5
self.assertNotEqual(new_object, asset5)

def test_add_empty_repo_type(self):
gridnode = GridNode(id=22)
Expand Down
Loading

0 comments on commit 61ab452

Please sign in to comment.