Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
328 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ target/ | |
|
||
# editors | ||
*.komodoproject | ||
.vscode | ||
|
||
# other | ||
*.DS_Store* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
language: python | ||
sudo: false | ||
cache: pip | ||
dist: focal | ||
|
||
python: | ||
- "3.4" | ||
- "2.7" | ||
- "3.8" | ||
|
||
env: | ||
- DJANGO="django>=1.11,<1.12" | ||
- DJANGO="django>=2.0,<2.1" | ||
- DJANGO="django~=3.1" | ||
|
||
matrix: | ||
exclude: | ||
- python: "2.7" | ||
env: DJANGO="django>=2.0,<2.1" | ||
addons: | ||
apt: | ||
packages: | ||
- sqlite3 | ||
- fping | ||
- gdal-bin | ||
- libproj-dev | ||
- libgeos-dev | ||
- libspatialite-dev | ||
- spatialite-bin | ||
- libsqlite3-mod-spatialite | ||
|
||
services: | ||
- redis-server | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
install: | ||
before_install: | ||
- pip install -U "pip==20.2.4" wheel setuptools | ||
- pip install $DJANGO | ||
- python setup.py -q develop | ||
- pip install -r requirements-test.txt | ||
|
||
install: | ||
- pip install -e . | ||
|
||
script: | ||
- openwisp-utils-qa-checks --skip-checkmigrations | ||
- coverage run --source=owm_legacy runtests.py | ||
- ./run-qa-checks | ||
- coverage run -a --source=owm_legacy runtests.py | ||
|
||
after_success: | ||
coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: "3" | ||
|
||
services: | ||
redis: | ||
image: redis:5.0-alpine | ||
ports: | ||
- "6379:6379" | ||
entrypoint: redis-server --appendonly yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from django.conf import settings | ||
|
||
ALLOWED_SUBNETS = getattr(settings, 'OWM_LEGACY_ALLOWED_SUBNETS', ['10.8.0.0/16', | ||
'127.0.0.1/32']) | ||
ALLOWED_SUBNETS = getattr( | ||
settings, 'OWM_LEGACY_ALLOWED_SUBNETS', ['10.8.0.0/16', '127.0.0.1/32'] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,68 @@ | ||
from time import sleep | ||
|
||
from django.urls import reverse | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from django_netjsonconfig.models import Config, Device | ||
from django_netjsonconfig.tests import CreateConfigMixin | ||
from openwisp_controller.config.models import Config, Device | ||
from openwisp_controller.config.tests import CreateConfigMixin | ||
from openwisp_users.tests.utils import TestOrganizationMixin | ||
from owm_legacy.settings import ALLOWED_SUBNETS | ||
|
||
|
||
class TestOwmLegacy(CreateConfigMixin, TestCase): | ||
class TestOwmLegacy(CreateConfigMixin, TestOrganizationMixin, TestCase): | ||
""" | ||
tests for owm_legacy | ||
""" | ||
|
||
config_model = Config | ||
device_model = Device | ||
|
||
def test_get_config_md5(self): | ||
c = self._create_config() | ||
response = self.client.get(reverse('owm:get_config_md5', args=[c.mac_address])) | ||
self.assertEqual(response['Content-Disposition'], 'attachment; filename={0}'.format(self.TEST_MAC_ADDRESS)) | ||
response = self.client.get( | ||
reverse('owm_legacy:get_config_md5', args=[c.mac_address]) | ||
) | ||
self.assertEqual( | ||
response['Content-Disposition'], | ||
'attachment; filename={0}'.format(self.TEST_MAC_ADDRESS), | ||
) | ||
self.assertEqual(len(response.content), 32) | ||
checksum1 = response.content | ||
sleep(1) | ||
response = self.client.get(reverse('owm:get_config_md5', args=[c.mac_address])) | ||
response = self.client.get( | ||
reverse('owm_legacy:get_config_md5', args=[c.mac_address]) | ||
) | ||
checksum2 = response.content | ||
self.assertEqual(checksum1, checksum2) | ||
c.refresh_from_db() | ||
self.assertIsNotNone(c.last_ip) | ||
self.assertIsNotNone(c.device.last_ip) | ||
|
||
def test_get_config(self): | ||
d = self._create_device(name='test') | ||
c = self._create_config(device=d) | ||
response = self.client.get(reverse('owm:get_config', args=[c.mac_address])) | ||
self.assertEqual(response['Content-Disposition'], 'attachment; filename=test.tar.gz') | ||
response = self.client.get( | ||
reverse('owm_legacy:get_config', args=[c.mac_address]) | ||
) | ||
self.assertEqual( | ||
response['Content-Disposition'], 'attachment; filename=test.tar.gz' | ||
) | ||
|
||
def test_last_ip(self): | ||
c = self._create_config() | ||
response = self.client.get(reverse('owm:get_config', args=[c.mac_address])) | ||
self.client.get(reverse('owm_legacy:get_config', args=[c.mac_address])) | ||
c.refresh_from_db() | ||
self.assertIsNotNone(c.last_ip) | ||
self.assertIsNotNone(c.device.last_ip) | ||
|
||
def test_status(self): | ||
c = self._create_config() | ||
response = self.client.get(reverse('owm:get_config', args=[c.mac_address])) | ||
self.client.get(reverse('owm_legacy:get_config', args=[c.mac_address])) | ||
c.refresh_from_db() | ||
self.assertEqual(c.status, 'running') | ||
self.assertEqual(c.status, 'applied') | ||
|
||
def test_forbidden_ip(self): | ||
ALLOWED_SUBNETS.remove('127.0.0.1/32') | ||
response = self.client.get(reverse('owm:get_config', args=['00:11:22:33:44:55'])) | ||
response = self.client.get( | ||
reverse('owm_legacy:get_config', args=['00:11:22:33:44:55']) | ||
) | ||
self.assertEqual(response.status_code, 403) | ||
ALLOWED_SUBNETS.append('127.0.0.1/32') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
coveralls | ||
openwisp-utils[qa]>=0.4.1 | ||
openwisp-utils[qa]~=0.7.0 | ||
django-redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
django-netjsonconfig>=0.8.0,<0.9.0 | ||
openwisp-controller~=0.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
openwisp-qa-check \ | ||
--skip-checkmigrations | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.