Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
028fa21398
@ -1,3 +1,65 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.http import QueryDict
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from django.utils.translation import activate
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
# Create your tests here.
|
from override_storage import override_storage
|
||||||
|
|
||||||
|
from .models import File
|
||||||
|
|
||||||
|
|
||||||
|
@override_storage()
|
||||||
|
class FileTests(TestCase):
|
||||||
|
|
||||||
|
test_user = 'testuser1'
|
||||||
|
test_pass = '12345'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
test_user1 = User.objects.create_user(username=self.test_user, password=self.test_pass)
|
||||||
|
test_user1.save()
|
||||||
|
|
||||||
|
activate('en-gb')
|
||||||
|
|
||||||
|
self.file = File.objects.create(user=test_user1)
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
return self.client.login(username=self.test_user, password=self.test_pass)
|
||||||
|
|
||||||
|
def test_post_not_logged_in(self):
|
||||||
|
url = reverse('files:upload')
|
||||||
|
|
||||||
|
next_url = QueryDict.fromkeys(['next',], url)
|
||||||
|
login_url = reverse('auth_login') + '?' + next_url.urlencode()
|
||||||
|
|
||||||
|
response = self.client.post(url, follow=True)
|
||||||
|
self.assertRedirects(response, login_url)
|
||||||
|
|
||||||
|
def test_delete_not_logged_in(self):
|
||||||
|
url = reverse('files:delete', kwargs={'pk': self.file.pk})
|
||||||
|
|
||||||
|
next_url = QueryDict.fromkeys(['next',], url)
|
||||||
|
login_url = reverse('auth_login') + '?' + next_url.urlencode()
|
||||||
|
|
||||||
|
response = self.client.post(url, follow=True)
|
||||||
|
self.assertRedirects(response, login_url)
|
||||||
|
|
||||||
|
def test_post_and_delete(self):
|
||||||
|
login = self.login()
|
||||||
|
|
||||||
|
with open('apps/map/static/map/ojuso-logo-white.png', 'rb') as fp:
|
||||||
|
response = self.client.post(reverse('files:upload'), {
|
||||||
|
'file': fp
|
||||||
|
})
|
||||||
|
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
self.assertEqual(data['is_valid'], True)
|
||||||
|
|
||||||
|
response = self.client.post(reverse('files:delete', kwargs={
|
||||||
|
'pk': data['id']
|
||||||
|
}))
|
||||||
|
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
self.assertEqual(data['success'], True)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from .models import CaseStudy
|
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.http import QueryDict
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.utils.translation import activate
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from .models import CaseStudyDraft
|
|
||||||
|
from .models import CaseStudy, CaseStudyDraft
|
||||||
|
|
||||||
|
|
||||||
class CaseStudyDraftAPITests(TestCase):
|
class CaseStudyDraftAPITests(TestCase):
|
||||||
@ -16,20 +16,26 @@ class CaseStudyDraftAPITests(TestCase):
|
|||||||
test_user1 = User.objects.create_user(username=self.test_user, password=self.test_pass)
|
test_user1 = User.objects.create_user(username=self.test_user, password=self.test_pass)
|
||||||
test_user1.save()
|
test_user1.save()
|
||||||
|
|
||||||
|
activate('en-gb')
|
||||||
|
|
||||||
|
next_url = QueryDict.fromkeys(['next',], reverse('drafts'))
|
||||||
|
|
||||||
|
self.login_url = reverse('auth_login') + '?' + next_url.urlencode()
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
return self.client.login(username=self.test_user, password=self.test_pass)
|
return self.client.login(username=self.test_user, password=self.test_pass)
|
||||||
|
|
||||||
def test_get_not_logged_in(self):
|
def test_get_not_logged_in(self):
|
||||||
response = self.client.get(reverse('drafts'))
|
response = self.client.get(reverse('drafts'), follow=True)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertRedirects(response, self.login_url)
|
||||||
|
|
||||||
def test_put_not_logged_in(self):
|
def test_put_not_logged_in(self):
|
||||||
response = self.client.put(reverse('drafts'))
|
response = self.client.put(reverse('drafts'), follow=True)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertRedirects(response, self.login_url)
|
||||||
|
|
||||||
def test_delete_not_logged_in(self):
|
def test_delete_not_logged_in(self):
|
||||||
response = self.client.delete(reverse('drafts'))
|
response = self.client.delete(reverse('drafts'), follow=True)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertRedirects(response, self.login_url)
|
||||||
|
|
||||||
def test_get_and_put(self):
|
def test_get_and_put(self):
|
||||||
login = self.login()
|
login = self.login()
|
||||||
@ -90,33 +96,25 @@ class CaseStudyTests(TestCase):
|
|||||||
def test_get_renewable_generation_detail_with_wind(self):
|
def test_get_renewable_generation_detail_with_wind(self):
|
||||||
"""get_renewable_generation_detail() should return the description prefixed with 'wind power'"""
|
"""get_renewable_generation_detail() should return the description prefixed with 'wind power'"""
|
||||||
case_study = CaseStudy(generation_technology='SSWE')
|
case_study = CaseStudy(generation_technology='SSWE')
|
||||||
self.assertEqual(case_study.get_renewable_generation_detail(), "Wind energy – Small-scale (less than 500kW)")
|
self.assertEqual(case_study.get_renewable_generation_detail(), "Wind energy – Small-scale (less than 500 kW)")
|
||||||
|
|
||||||
def test_get_renewable_generation_detail_with_other(self):
|
def test_get_renewable_generation_detail_with_other(self):
|
||||||
"""get_renewable_generation_detail() should return the detail provided in .generation_technology_other"""
|
"""get_renewable_generation_detail() should return the detail provided in .generation_technology_other"""
|
||||||
case_study = CaseStudy(generation_technology='OTHR', generation_technology_other='Warp drive')
|
case_study = CaseStudy(generation_technology='OTHR', generation_technology_other='Warp drive')
|
||||||
self.assertEqual(case_study.get_renewable_generation_detail(), "Warp drive")
|
self.assertEqual(case_study.get_renewable_generation_detail(), "Warp drive")
|
||||||
|
|
||||||
# These tests are commented out because they are not working, but the code
|
def test_get_negative_case_reasons_no_other_1(self):
|
||||||
# in production is. When running as a test, get_negative_case_reasons_no_other()
|
"""Test with case having no 'other' entry"""
|
||||||
# is returning a list of coded options, like
|
case_study = CaseStudy(negative_case_reasons=['VOLR','ALAB'])
|
||||||
# ['V', 'O', 'L', 'R', ',', 'A', 'L', 'A', 'B']
|
self.assertEqual(case_study.get_negative_case_reasons_no_other(),
|
||||||
# instead of a list of text like
|
[ 'Violation of land rights'
|
||||||
# ['Violation of land rights', 'Abusive labour practices']
|
, 'Abusive labour practices'
|
||||||
# I am too much of a Django newbie to know why. – Anna
|
])
|
||||||
|
|
||||||
# def test_get_negative_case_reasons_no_other_1(self):
|
def test_get_negative_case_reasons_no_other_2(self):
|
||||||
# """Test with case having no 'other' entry"""
|
"""Test with case having an 'other' entry"""
|
||||||
# case_study = CaseStudy(negative_case_reasons='VOLR,ALAB')
|
case_study = CaseStudy(negative_case_reasons=['VOLR','ALAB','OTHR'])
|
||||||
# self.assertEqual(case_study.get_negative_case_reasons_no_other(),
|
self.assertEqual(case_study.get_negative_case_reasons_no_other(),
|
||||||
# [ 'Violation of land rights'
|
[ 'Violation of land rights'
|
||||||
# , 'Abusive labour practices'
|
, 'Abusive labour practices'
|
||||||
# ])
|
])
|
||||||
#
|
|
||||||
# def test_get_negative_case_reasons_no_other_2(self):
|
|
||||||
# """Test with case having an 'other' entry"""
|
|
||||||
# case_study = CaseStudy(negative_case_reasons='VOLR,ALAB,OTHR')
|
|
||||||
# self.assertEqual(case_study.get_negative_case_reasons_no_other(),
|
|
||||||
# [ 'Violation of land rights'
|
|
||||||
# , 'Abusive labour practices'
|
|
||||||
# ])
|
|
||||||
|
Loading…
Reference in New Issue
Block a user