-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 changed file
with
13 additions
and
25 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 |
---|---|---|
@@ -1,73 +1,61 @@ | ||
import random | ||
from datetime import timedelta | ||
|
||
from django.contrib.auth.models import User | ||
from django.contrib.gis.geos import Point | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
from mixer.backend.django import mixer | ||
import random | ||
|
||
from tracking.models import Device, LoggedPoint | ||
|
||
|
||
class ViewTestCase(TestCase): | ||
|
||
def setUp(self): | ||
point = Point(random.uniform(32.0, 34.0), random.uniform(-115.0, -116.0)) | ||
self.device = mixer.blend(Device, seen=timezone.now(), point=point) | ||
# Generate a short tracking history. | ||
mixer.blend(LoggedPoint, device=self.device, seen=self.device.seen, point=point) | ||
point.x = point.x + random.uniform(-0.01, 0.01) | ||
point.y = point.y + random.uniform(-0.01, 0.01) | ||
mixer.blend(LoggedPoint, device=self.device, seen=self.device.seen - timedelta(minutes=3), point=point) | ||
point.x = point.x + random.uniform(-0.01, 0.01) | ||
point.y = point.y + random.uniform(-0.01, 0.01) | ||
mixer.blend(LoggedPoint, device=self.device, seen=self.device.seen - timedelta(minutes=6), point=point) | ||
point.x = point.x + random.uniform(-0.01, 0.01) | ||
point.y = point.y + random.uniform(-0.01, 0.01) | ||
mixer.blend(LoggedPoint, device=self.device, seen=self.device.seen - timedelta(minutes=9), point=point) | ||
|
||
# Generate a short tracking history. | ||
for i in range(1, 5): | ||
point.x = point.x + random.uniform(-0.01, 0.01) | ||
point.y = point.y + random.uniform(-0.01, 0.01) | ||
mixer.blend(LoggedPoint, device=self.device, seen=self.device.seen - timedelta(minutes=i), point=point) | ||
# Login | ||
self.client.force_login(User.objects.create(username="testuser")) | ||
|
||
def test_device_csv_download(self): | ||
"""Test the devices.csv download view | ||
""" | ||
"""Test the devices.csv download view""" | ||
url = reverse("device_csv") | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_device_geojson_download(self): | ||
"""Test the devices.geojson download view | ||
""" | ||
"""Test the devices.geojson download view""" | ||
url = reverse("device_geojson") | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_device_history_geojson_view(self): | ||
"""Test the device history GeoJSON view | ||
""" | ||
"""Test the device history GeoJSON view""" | ||
url = reverse("device_history_geojson", kwargs={"device_id": self.device.pk}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_device_history_csv_view(self): | ||
"""Test the device history CSV view | ||
""" | ||
"""Test the device history CSV view""" | ||
url = reverse("device_history_csv", kwargs={"device_id": self.device.pk}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_device_route_geojson_view(self): | ||
"""Test the device route GeoJSON view | ||
""" | ||
"""Test the device route GeoJSON view""" | ||
url = reverse("device_route_geojson", kwargs={"device_id": self.device.pk}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_resource_map_view(self): | ||
"""Test the resource map view | ||
""" | ||
"""Test the resource map view""" | ||
url = reverse("resource_map") | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) |