Skip to content

Commit d25fcf8

Browse files
authored
Run initializer tests twice (#23)
* Run initializer tests twice The second test will catch errors when the initializers are run a second time against an already initialized database. * Force image pull and DB migrations into test_setup * Fixed bugs caught by the second test run
1 parent 55dcd11 commit d25fcf8

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ jobs:
1212
- id: git-checkout
1313
name: Checkout
1414
uses: actions/checkout@v3
15-
- id: test-script
16-
name: Test the initializers
15+
- id: test-script-1
16+
name: Test the initializers (First run)
17+
env:
18+
KEEP_VOLUMES: "true"
19+
run: |
20+
cd test
21+
./test.sh
22+
- id: test-script-2
23+
name: Test the initializers (Second run)
1724
run: |
1825
cd test
1926
./test.sh

src/netbox_initializers/initializers/interfaces.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def load_data(self):
6565
query = {
6666
r_field: related_value,
6767
"device": interface.device,
68-
"type": related_field,
6968
}
7069
related_obj, rel_obj_created = r_model.objects.get_or_create(**query)
7170

src/netbox_initializers/initializers/object_permissions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def load_data(self):
4444
object_permission.object_types.add(
4545
ContentType.objects.get(app_label=app_label, model=model)
4646
)
47-
48-
print("🔓 Created object permission", object_permission.name)
47+
if created:
48+
print("🔓 Created object permission", object_permission.name)
4949

5050
if permission_details.get("groups", 0):
5151
for groupname in permission_details["groups"]:

test/test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ test_setup() {
2222
done
2323
)
2424
$doco build --no-cache || exit 1
25+
$doco run --rm netbox /opt/netbox/docker-entrypoint.sh ./manage.py check || exit 1
2526
}
2627

2728
test_cleanup() {
2829
gh_echo "::group::Clean test environment"
2930
echo "💣 Cleaning Up"
30-
$doco down -v
31+
if [ "$KEEP_VOLUMES" == "true" ]; then
32+
$doco down
33+
else
34+
$doco down -v
35+
fi
3136

3237
if [ -d "${INITIALIZERS_DIR}" ]; then
3338
rm -rf "${INITIALIZERS_DIR}"

0 commit comments

Comments
 (0)