lostplaces-backend/django_lostplaces/lostplaces/tests/models/test_link_model.py

102 lines
3.0 KiB
Python
Raw Permalink Normal View History

2020-09-18 22:39:18 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
from unittest import mock
from django.test import TestCase
from django.db import models
from django.core.files import File
from django.conf import settings
from django.contrib.auth.models import User
from django.utils import timezone
from lostplaces.models import ExternalLink, PhotoAlbum, Place
from lostplaces.tests.models import ModelTestCase
class ExternalLinkTestCase(ModelTestCase):
model = ExternalLink
def setup(self):
self.albumlink = ExternalLink.objects.get(id=1)
def test_label(self):
self.assertField('label', models.CharField)
def test_url(self):
self.assertField('url', models.URLField)
class PhotoAlbumTestCase(ModelTestCase):
model = PhotoAlbum
2020-09-18 22:39:18 +02:00
@classmethod
def setUpTestData(cls):
user = User.objects.create_user(
username='testpeter',
password='Develop123'
)
place = Place.objects.create(
name='Im a place',
submitted_when=timezone.now(),
submitted_by=User.objects.get(username='testpeter').explorer,
location='Testtown',
latitude=50.5,
longitude=7.0,
description='This is just a test, do not worry'
)
place.tags.add('I am a tag', 'testlocation')
2020-09-18 22:39:18 +02:00
place.save()
PhotoAlbum.objects.create(
url='https://lostplaces.example.com/album/',
label='TestLink',
submitted_by=user.explorer,
place=place,
submitted_when=timezone.now()
)
def setUp(self):
self.albumlink = PhotoAlbum.objects.get(id=1)
self.place = Place.objects.get(id=1)
2020-09-18 22:39:18 +02:00
2020-09-18 23:02:59 +02:00
def test_place(self):
field = self.assertField('place', models.ForeignKey)
self.assertEqual(field.remote_field.on_delete, models.CASCADE,
msg='Expecting the deletion of %s to be cascading' % (
str(field)
)
)
Squashed commit of the following: commit 0d62e72d72922a84e41c9f2cc21977b794784d1c Merge: 79fee63 85f2a81 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:55:18 2020 +0200 Merge branch 'develop' into refactor/models commit 79fee631d7ac28509067ecdd74078f1a2f6e0be2 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:54:32 2020 +0200 Updating references for related name commit 8e07e79df2de2601f2e2eadfdd37eb7c719c51b0 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:53:31 2020 +0200 Generating of related names fix commit 5fd804f37a805ae4707e13c3d941bdde3660afea Merge: 8cc1d3e 3b526c9 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 21:01:48 2020 +0200 Merge branch 'develop' into refactor/models commit 8cc1d3e690211dba6451e86569f00078b23e0621 Author: reverend <reverend@reverend2048.de> Date: Tue Sep 22 20:21:08 2020 +0200 Tests commit 7c0591e5397f892b1f6fb80725a693c21f90468a Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 23:53:39 2020 +0200 Testing PlaceAsset commit 2e7b49ad1a15173565c81e7eb8bb3f35b9f622a6 Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 22:25:08 2020 +0200 Restructuring models commit eb7d03b08b326f9115e70d0fd9ed5d0fc229a362 Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 22:01:54 2020 +0200 Abstract class Expireable commit 2b51e741bb5734c5a578beeadef7819fe58b2223 Author: reverend <reverend@reverend2048.de> Date: Fri Sep 18 21:54:07 2020 +0200 Abstract Model for PlaceAsset (i.e. Photoalbums)
2020-09-22 21:56:51 +02:00
expected_related_name = 'photoalbums'
2020-09-18 23:02:59 +02:00
self.assertEqual(field.remote_field.related_name, expected_related_name,
msg='Expecting the related name of %s to be %s' % (
str(field),
expected_related_name
)
)
def test_label(self):
albumlink = self.albumlink
self.assertTrue('TestLink' in albumlink.label,
msg='Expecting albumlink.label to contain \'TestLink\' string'
)
def test_url(self):
albumlink = self.albumlink
self.assertTrue('lostplaces.example.com' in albumlink.url,
msg='Expecting albumlink.url to contain \'lostplaces.example.com\' string'
)
2020-09-22 20:48:56 +02:00
def test_linked_place(self):
albumlink = self.albumlink
place = self.place
self.assertTrue(str(albumlink.place) in str(place.name),
msg='Expecting %s.__str__ to contain the name' % (
self.model.__name__
)
)