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

View File

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