mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
#9047 - Fully resolve test issues. Move model to look more like requested initial model.
This commit is contained in:
parent
9e129b0ebf
commit
22fdd6160c
@ -51,22 +51,22 @@ class Migration(migrations.Migration):
|
||||
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
|
||||
('description', models.CharField(blank=True, max_length=200)),
|
||||
('comments', models.TextField(blank=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('account', models.CharField(blank=True, max_length=30)),
|
||||
('account', models.CharField(max_length=30)),
|
||||
('name', models.CharField(blank=True, max_length=100)),
|
||||
('provider', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='accounts', to='circuits.provider')),
|
||||
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
|
||||
],
|
||||
options={
|
||||
'ordering': ('provider', 'name'),
|
||||
'ordering': ('provider', 'account'),
|
||||
},
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='provideraccount',
|
||||
constraint=models.UniqueConstraint(fields=('provider', 'name'), name='circuits_provideraccount_unique_provider_name'),
|
||||
constraint=models.UniqueConstraint(condition=models.Q(('account', ''), _negated=True), fields=('provider', 'name'), name='circuits_provideraccount_unique_provider_name'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='provideraccount',
|
||||
constraint=models.UniqueConstraint(condition=models.Q(('account', ''), _negated=True), fields=('provider', 'account'), name='circuits_provideraccount_unique_provider_account'),
|
||||
constraint=models.UniqueConstraint(fields=('provider', 'account'), name='circuits_provideraccount_unique_provider_account'),
|
||||
),
|
||||
migrations.RunPython(
|
||||
create_provideraccounts_from_providers, revert_provideraccounts_from_providers
|
@ -52,19 +52,19 @@ class ProviderAccount(PrimaryModel):
|
||||
"""
|
||||
This represents a provider account
|
||||
"""
|
||||
account = models.CharField(
|
||||
max_length=30,
|
||||
verbose_name='Account number'
|
||||
)
|
||||
name = models.CharField(
|
||||
max_length=100
|
||||
max_length=100,
|
||||
blank=True
|
||||
)
|
||||
provider = models.ForeignKey(
|
||||
to='circuits.Provider',
|
||||
on_delete=models.PROTECT,
|
||||
related_name='accounts'
|
||||
)
|
||||
account = models.CharField(
|
||||
max_length=30,
|
||||
blank=True,
|
||||
verbose_name='Account number'
|
||||
)
|
||||
|
||||
# Generic relations
|
||||
contacts = GenericRelation(
|
||||
@ -74,21 +74,22 @@ class ProviderAccount(PrimaryModel):
|
||||
clone_fields = ('provider', )
|
||||
|
||||
class Meta:
|
||||
ordering = ('provider', 'name')
|
||||
ordering = ('provider', 'account')
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('provider', 'name'),
|
||||
name='%(app_label)s_%(class)s_unique_provider_name'
|
||||
fields=('provider', 'account'),
|
||||
name='%(app_label)s_%(class)s_unique_provider_account'
|
||||
),
|
||||
models.UniqueConstraint(
|
||||
fields=('provider', 'account'),
|
||||
name='%(app_label)s_%(class)s_unique_provider_account',
|
||||
fields=('provider', 'name'),
|
||||
name='%(app_label)s_%(class)s_unique_provider_name',
|
||||
condition=~Q(account="")
|
||||
),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
if self.name:
|
||||
return f'{self.account} ({self.name})'
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('circuits:provideraccount', args=[self.pk])
|
||||
|
@ -72,9 +72,9 @@ class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
||||
class Meta(NetBoxTable.Meta):
|
||||
model = ProviderAccount
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'account', 'provider', 'comments', 'contacts', 'tags', 'created', 'last_updated',
|
||||
'pk', 'id', 'account', 'name', 'provider', 'comments', 'contacts', 'tags', 'created', 'last_updated',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'account', 'provider')
|
||||
default_columns = ('pk', 'account', 'name', 'provider')
|
||||
|
||||
|
||||
class ProviderNetworkTable(NetBoxTable):
|
||||
|
@ -210,9 +210,9 @@ class ProviderAccountTest(APIViewTestCases.APIViewTestCase):
|
||||
Provider.objects.bulk_create(providers)
|
||||
|
||||
provider_accounts = (
|
||||
ProviderAccount(name='Provider Account 1', provider=providers[0]),
|
||||
ProviderAccount(name='Provider Account 2', provider=providers[0]),
|
||||
ProviderAccount(name='Provider Account 3', provider=providers[0]),
|
||||
ProviderAccount(name='Provider Account 1', provider=providers[0], account='1234'),
|
||||
ProviderAccount(name='Provider Account 2', provider=providers[0], account='2345'),
|
||||
ProviderAccount(name='Provider Account 3', provider=providers[0], account='3456'),
|
||||
)
|
||||
ProviderAccount.objects.bulk_create(provider_accounts)
|
||||
|
||||
@ -220,14 +220,17 @@ class ProviderAccountTest(APIViewTestCases.APIViewTestCase):
|
||||
{
|
||||
'name': 'Provider Account 4',
|
||||
'provider': providers[0].pk,
|
||||
'account': '4567',
|
||||
},
|
||||
{
|
||||
'name': 'Provider Account 5',
|
||||
'provider': providers[0].pk,
|
||||
'account': '5678',
|
||||
},
|
||||
{
|
||||
'name': 'Provider Account 6',
|
||||
'provider': providers[0].pk,
|
||||
'account': '6789',
|
||||
},
|
||||
]
|
||||
|
||||
|
@ -458,9 +458,9 @@ class ProviderAccountTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
Provider.objects.bulk_create(providers)
|
||||
|
||||
provider_accounts = (
|
||||
ProviderAccount(name='Provider Account 1', provider=providers[0], description='foobar1'),
|
||||
ProviderAccount(name='Provider Account 2', provider=providers[1], description='foobar2'),
|
||||
ProviderAccount(name='Provider Account 3', provider=providers[2]),
|
||||
ProviderAccount(name='Provider Account 1', provider=providers[0], description='foobar1', account='1234'),
|
||||
ProviderAccount(name='Provider Account 2', provider=providers[1], description='foobar2', account='2345'),
|
||||
ProviderAccount(name='Provider Account 3', provider=providers[2], account='3456'),
|
||||
)
|
||||
ProviderAccount.objects.bulk_create(provider_accounts)
|
||||
|
||||
@ -468,6 +468,10 @@ class ProviderAccountTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
params = {'name': ['Provider Account 1', 'Provider Account 2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_account(self):
|
||||
params = {'account': ['1234', '3456']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
||||
def test_description(self):
|
||||
params = {'description': ['foobar1', 'foobar2']}
|
||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||
|
@ -190,9 +190,9 @@ class ProviderAccountTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
Provider.objects.bulk_create(providers)
|
||||
|
||||
provider_accounts = (
|
||||
ProviderAccount(name='Provider Account 1', provider=providers[0]),
|
||||
ProviderAccount(name='Provider Account 2', provider=providers[0]),
|
||||
ProviderAccount(name='Provider Account 3', provider=providers[0]),
|
||||
ProviderAccount(name='Provider Account 1', provider=providers[0], account='1234'),
|
||||
ProviderAccount(name='Provider Account 2', provider=providers[0], account='2345'),
|
||||
ProviderAccount(name='Provider Account 3', provider=providers[0], account='3456'),
|
||||
)
|
||||
|
||||
ProviderAccount.objects.bulk_create(provider_accounts)
|
||||
@ -202,23 +202,24 @@ class ProviderAccountTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||
cls.form_data = {
|
||||
'name': 'Provider Account X',
|
||||
'provider': providers[1].pk,
|
||||
'account': 'XXXX',
|
||||
'description': 'A new provider network',
|
||||
'comments': 'Longer description goes here',
|
||||
'tags': [t.pk for t in tags],
|
||||
}
|
||||
|
||||
cls.csv_data = (
|
||||
"name,provider,description",
|
||||
"Provider Account 4,Provider 1,Foo",
|
||||
"Provider Account 5,Provider 1,Bar",
|
||||
"Provider Account 6,Provider 1,Baz",
|
||||
"name,provider,account,description",
|
||||
"Provider Account 4,Provider 1,4567,Foo",
|
||||
"Provider Account 5,Provider 1,5678,Bar",
|
||||
"Provider Account 6,Provider 1,6789,Baz",
|
||||
)
|
||||
|
||||
cls.csv_update_data = (
|
||||
"id,name,description",
|
||||
f"{provider_accounts[0].pk},Provider Network 7,New description7",
|
||||
f"{provider_accounts[1].pk},Provider Network 8,New description8",
|
||||
f"{provider_accounts[2].pk},Provider Network 9,New description9",
|
||||
"id,name,account,description",
|
||||
f"{provider_accounts[0].pk},Provider Network 7,7890,New description7",
|
||||
f"{provider_accounts[1].pk},Provider Network 8,8901,New description8",
|
||||
f"{provider_accounts[2].pk},Provider Network 9,9012,New description9",
|
||||
)
|
||||
|
||||
cls.bulk_edit_data = {
|
||||
|
@ -31,6 +31,7 @@ class ProviderView(generic.ObjectView):
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
related_models = (
|
||||
(ProviderAccount.objects.restrict(request.user, 'view').filter(provider=instance), 'provider_id'),
|
||||
(Circuit.objects.restrict(request.user, 'view').filter(provider=instance), 'provider_id'),
|
||||
)
|
||||
|
||||
|
@ -52,6 +52,14 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col col-md-12">
|
||||
<div class="card">
|
||||
<h5 class="card-header">Provider Accounts</h5>
|
||||
<div class="card-body htmx-container table-responsive"
|
||||
hx-get="{% url 'circuits:provideraccount_list' %}?provider_id={{ object.pk }}"
|
||||
hx-trigger="load"
|
||||
></div>
|
||||
</div>
|
||||
<div class="col col-md-12">
|
||||
<div class="card">
|
||||
<h5 class="card-header">Circuits</h5>
|
||||
|
Loading…
Reference in New Issue
Block a user