Skip to content

Commit

Permalink
[tests] Added test for duplicate file bug on file creation #817
Browse files Browse the repository at this point in the history
Fixes #817
  • Loading branch information
pandafy committed Jan 8, 2024
1 parent cb6f91e commit a0faef7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
31 changes: 23 additions & 8 deletions openwisp_controller/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,19 +652,34 @@ def test_remove_duplicate_files(self):
]
},
)
config = self._create_config(organization=self._get_org())
config.templates.add(template1)
config.templates.add(template2)
config.refresh_from_db()
try:
org = self._get_org()
with self.subTest('Test template applied on creating config'):
config = self._create_config(
organization=org,
templates=[template1, template2],
)
config.full_clean()
config.save()
result = config.get_backend_instance(
template_instances=[template1, template2]
).render()
except ValidationError:
self.fail('ValidationError raised!')
else:
self.assertIn('# path: /etc/vpnserver1', result)

config.delete()
with self.subTest('Test template applied after creating config object'):
config = self._create_config(organization=org)
config.templates.add(template1)
config.templates.add(template2)
config.refresh_from_db()
try:
result = config.get_backend_instance(
template_instances=[template1, template2]
).render()
except ValidationError:
self.fail('ValidationError raised!')
else:
self.assertIn('# path: /etc/vpnserver1', result)

def test_duplicated_files_in_config(self):
try:
self._create_config(
Expand Down
3 changes: 3 additions & 0 deletions openwisp_controller/config/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def _create_config(self, **kwargs):
options['device'] = self._create_device(
organization=self._get_org(), name='test-device'
)
templates = options.pop('templates', [])
c = Config(**options)
if templates:
c.templates.set(templates)
c.full_clean()
c.save()
return c
Expand Down

0 comments on commit a0faef7

Please sign in to comment.