Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Jan 15, 2024
1 parent 0727ec4 commit a936407
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 406 deletions.
4 changes: 0 additions & 4 deletions validity/compliance/device_config/__init__.py

This file was deleted.

56 changes: 0 additions & 56 deletions validity/compliance/device_config/base.py

This file was deleted.

156 changes: 0 additions & 156 deletions validity/compliance/device_config/routeros.py

This file was deleted.

32 changes: 0 additions & 32 deletions validity/compliance/device_config/ttp.py

This file was deleted.

20 changes: 0 additions & 20 deletions validity/compliance/device_config/yaml.py

This file was deleted.

2 changes: 1 addition & 1 deletion validity/compliance/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def with_config(self, serializable: Serializable):
def _blocked_op(self, *_):
raise AttributeError("State is read only")

__setitem__ = __delitem__ = __ior__ = pop = popitem = update = setdefault = clear = _blocked_op
__setitem__ = __delitem__ = pop = popitem = update = setdefault = clear = _blocked_op

def __getattr__(self, key):
return self[key]
Expand Down
2 changes: 1 addition & 1 deletion validity/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def annotate_datasource_id(self):
from validity.models import VDataSource

return self.annotate(
bound_source=Cast(KeyTextTransform("config_data_source", "tenant__custom_field_data"), BigIntegerField())
bound_source=Cast(KeyTextTransform("data_source", "tenant__custom_field_data"), BigIntegerField())
).annotate(
data_source_id=Case(
When(bound_source__isnull=False, then=F("bound_source")),
Expand Down
4 changes: 2 additions & 2 deletions validity/migrations/0005_datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def setup_datasource_cf(apps, schema_editor):
for cf in datasource_cfs:
cf.content_types.set([ContentType.objects.get_for_model(DataSource)])
tenant_cf = CustomField.objects.using(db).create(
name="config_data_source",
label=_("Config Data Source"),
name="data_source",
label=_("Data Source"),
description=_("Required by Validity"),
type="object",
object_type=ContentType.objects.get_for_model(DataSource),
Expand Down
14 changes: 0 additions & 14 deletions validity/models/polling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contextlib import contextmanager
from functools import cached_property
from typing import Collection

Expand Down Expand Up @@ -102,19 +101,6 @@ def config_command(self) -> Command | None:
def get_backend(self):
return get_poller(self.connection_type, self.credentials, self.commands.all())

def serialize_object(self):
with self.serializable_credentials():
return super().serialize_object()

@contextmanager
def serializable_credentials(self):
private_creds = self.private_credentials
try:
self.private_credentials = self.private_credentials.encrypted
yield
finally:
self.private_credentials = private_creds

@staticmethod
def validate_commands(connection_type: str, commands: Collection[Command]):
# All the commands must be of the matching type
Expand Down
11 changes: 8 additions & 3 deletions validity/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create_custom_fields(db):
required=False,
),
CustomField(
name="config_data_source",
name="data_source",
type="object",
object_type=ContentType.objects.get_for_model(DataSource),
required=False,
Expand All @@ -52,6 +52,11 @@ def create_custom_fields(db):
type="string",
required=False,
),
CustomField(
name="device_command_path",
type="string",
required=False,
),
CustomField(
name="poller",
type="object",
Expand All @@ -68,9 +73,9 @@ def create_custom_fields(db):
]
)
cfs[1].content_types.set([ContentType.objects.get_for_model(Tenant)])
for cf in cfs[2:5]:
for cf in cfs[2:6]:
cf.content_types.set([ContentType.objects.get_for_model(DataSource)])
cfs[5].content_types.set(
cfs[6].content_types.set(
[
ContentType.objects.get_for_model(Device),
ContentType.objects.get_for_model(DeviceType),
Expand Down
Loading

0 comments on commit a936407

Please sign in to comment.