1
0
mirror of https://github.com/daniviga/bite.git synced 2024-11-22 21:16:12 +01:00

Complete API renaming into DPS. Add sample local_settings

This commit is contained in:
Daniele Viganò 2023-09-09 11:35:06 +02:00
parent 79f5c516e0
commit e4d6a15614
21 changed files with 44 additions and 24 deletions

View File

@ -0,0 +1,20 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'bite',
'USER': 'bite',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
MQTT_BROKER = {
'HOST': 'localhost',
'PORT': '1883',
}
KAFKA_BROKER = {
'HOST': 'localhost',
'PORT': '29092',
}

View File

@ -61,7 +61,7 @@ INSTALLED_APPS = [
# 'health_check.storage',
'rest_framework',
'bite',
'api',
'dps',
'telemetry',
]

View File

@ -37,13 +37,13 @@ from django.contrib import admin
from django.conf import settings
from django.urls import include, path
from api import urls as api_urls
from dps import urls as dps_urls
from telemetry import urls as telemetry_urls
urlpatterns = [
path('admin/', admin.site.urls),
path('ht/', include('health_check.urls')),
path('api/', include(api_urls)),
path('dps/', include(dps_urls)),
path('telemetry/', include(telemetry_urls)),
]

View File

@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import admin
from api.models import Device, WhiteList
from dps.models import Device, WhiteList
@admin.register(Device)

View File

@ -20,5 +20,5 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'api'
class DPSConfig(AppConfig):
name = 'dps'

View File

@ -1,6 +1,6 @@
# Generated by Django 3.1.3 on 2021-03-19 08:08
import api.models
import dps.models
from django.db import migrations, models
import uuid
@ -16,7 +16,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Device',
fields=[
('serial', models.CharField(max_length=128, unique=True, validators=[api.models.device_validation])),
('serial', models.CharField(max_length=128, unique=True, validators=[dps.models.device_validation])),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('creation_time', models.DateTimeField(auto_now_add=True)),
('updated_time', models.DateTimeField(auto_now=True)),

View File

@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from rest_framework import serializers
from api.models import Device, device_validation
from dps.models import Device, device_validation
class DeviceSerializer(serializers.ModelSerializer):

View File

@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.test import TestCase, Client
from api.models import Device, WhiteList
from dps.models import Device, WhiteList
class DPSTestCase(TestCase):
@ -29,17 +29,17 @@ class DPSTestCase(TestCase):
Device.objects.create(serial='test1234')
def test_no_whitelist(self):
response = self.c.post('/api/device/provision/',
response = self.c.post('/dps/device/provision/',
{'serial': 'test12345'})
self.assertEqual(response.status_code, 400)
def test_provision_post(self):
WhiteList.objects.create(serial='test12345')
response = self.c.post('/api/device/provision/',
response = self.c.post('/dps/device/provision/',
{'serial': 'test12345'})
self.assertEqual(response.status_code, 201)
def test_provision_get(self):
response = self.c.get('/api/device/list/')
response = self.c.get('/dps/device/list/')
self.assertEqual(
response.json()[0]['serial'], 'test1234')

View File

@ -33,7 +33,7 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from api.views import DPS
from dps.views import DPS
urlpatterns = [
path('device/provision/',

View File

@ -19,8 +19,8 @@
from rest_framework.viewsets import ModelViewSet
from api.models import Device
from api.serializers import DeviceSerializer
from dps.models import Device
from dps.serializers import DeviceSerializer
class DPS(ModelViewSet):

View File

@ -31,7 +31,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.exceptions import ObjectDoesNotExist
from api.models import Device
from dps.models import Device
class Command(BaseCommand):

View File

@ -26,7 +26,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.exceptions import ObjectDoesNotExist
from api.models import Device
from dps.models import Device
from telemetry.models import Telemetry

View File

@ -11,7 +11,7 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('api', '0001_initial'),
('dps', '0001_initial'),
]
operations = [
@ -23,7 +23,7 @@ class Migration(migrations.Migration):
('transport', models.CharField(choices=[('http', 'http'), ('mqtt', 'mqtt')], default='http', max_length=4)),
('clock', models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(0)])),
('payload', models.JSONField(validators=[telemetry.models.telemetry_validation])),
('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.device')),
('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dps.device')),
],
options={
'verbose_name_plural': 'Telemetry',

View File

@ -21,7 +21,7 @@ from django.db import models
from django.core.validators import MinValueValidator
from django.core.exceptions import ValidationError
from api.models import Device
from dps.models import Device
def telemetry_validation(value):

View File

@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from rest_framework import serializers
from api.models import Device
from dps.models import Device
from telemetry.models import Telemetry

View File

@ -19,7 +19,7 @@
import json
from django.test import TestCase, Client
from api.models import Device, WhiteList
from dps.models import Device, WhiteList
class ApiTestCase(TestCase):

View File

@ -114,7 +114,7 @@ def main():
)
args = parser.parse_args()
dps = "/api/device/provision/"
dps = "/dps/device/provision/"
telemetry = "/telemetry/"
if args.serial is None: