Suppress print() output from migrations during testing

This commit is contained in:
Jeremy Stretch 2018-11-01 14:54:36 -04:00
parent 7ffb5f16dd
commit 62da0778ee
2 changed files with 22 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import sys
from django.db import migrations, models
import django.db.models.deletion
@ -18,6 +20,7 @@ def circuit_terminations_to_cables(apps, schema_editor):
interface_type = ContentType.objects.get_for_model(Interface)
# Create a new Cable instance from each console connection
if 'test' not in sys.argv:
print("\n Adding circuit terminations... ", end='', flush=True)
for circuittermination in CircuitTermination.objects.filter(interface__isnull=False):
@ -44,6 +47,7 @@ def circuit_terminations_to_cables(apps, schema_editor):
)
cable_count = Cable.objects.filter(termination_a_type=circuittermination_type).count()
if 'test' not in sys.argv:
print("{} cables created".format(cable_count))
@ -71,7 +75,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='circuittermination',
name='cable',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='dcim.Cable'),
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='dcim.Cable'),
),
# Copy CircuitTermination connections to Interfaces as Cables

View File

@ -1,5 +1,8 @@
import sys
from django.db import migrations, models
import django.db.models.deletion
import utilities.fields
@ -17,6 +20,7 @@ def console_connections_to_cables(apps, schema_editor):
consoleserverport_type = ContentType.objects.get_for_model(ConsoleServerPort)
# Create a new Cable instance from each console connection
if 'test' not in sys.argv:
print("\n Adding console connections... ", end='', flush=True)
for consoleport in ConsolePort.objects.filter(connected_endpoint__isnull=False):
@ -34,6 +38,7 @@ def console_connections_to_cables(apps, schema_editor):
ConsoleServerPort.objects.filter(pk=consoleport.connected_endpoint_id).update(cable=cable)
cable_count = Cable.objects.filter(termination_a_type=consoleport_type).count()
if 'test' not in sys.argv:
print("{} cables created".format(cable_count))
@ -51,6 +56,7 @@ def power_connections_to_cables(apps, schema_editor):
poweroutlet_type = ContentType.objects.get_for_model(PowerOutlet)
# Create a new Cable instance from each power connection
if 'test' not in sys.argv:
print(" Adding power connections... ", end='', flush=True)
for powerport in PowerPort.objects.filter(connected_endpoint__isnull=False):
@ -68,6 +74,7 @@ def power_connections_to_cables(apps, schema_editor):
PowerOutlet.objects.filter(pk=powerport.connected_endpoint_id).update(cable=cable)
cable_count = Cable.objects.filter(termination_a_type=powerport_type).count()
if 'test' not in sys.argv:
print("{} cables created".format(cable_count))
@ -84,6 +91,7 @@ def interface_connections_to_cables(apps, schema_editor):
interface_type = ContentType.objects.get_for_model(Interface)
# Create a new Cable instance from each InterfaceConnection
if 'test' not in sys.argv:
print(" Adding interface connections... ", end='', flush=True)
for conn in InterfaceConnection.objects.all():
@ -109,6 +117,7 @@ def interface_connections_to_cables(apps, schema_editor):
)
cable_count = Cable.objects.filter(termination_a_type=interface_type).count()
if 'test' not in sys.argv:
print("{} cables created".format(cable_count))