Commit 4c183d47 authored by Benedikt Geißler's avatar Benedikt Geißler 🐸

Split up test method

parent b13e8382
Pipeline #10390 failed with stage
in 18 seconds
......@@ -231,7 +231,7 @@ class Resource(models.Model):
continue
# Check if new value equals the old one
if local_attrib.value == rmt_attrib.get("value"):
if local_attrib.value == str(rmt_attrib.get("value")):
attrib_dict.update({
"status": "unchanged"
})
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from api.models import Attribute, Resource, ServiceProvider, TokenAuthUser, UserType
from django.utils import timezone
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from api.models import Attribute, Resource, ServiceProvider, TokenAuthUser, UserType
class AttributeUpdateTest(APITestCase):
class AttributeTest(APITestCase):
def setUp(self):
TokenAuthUser.objects.create_superuser(username="a_super",
email="test@a.edu",
......@@ -41,40 +40,36 @@ class AttributeUpdateTest(APITestCase):
vec_sp=1,
vec_idp=0)
def test_attribute_update(self):
def test_updated(self):
url = reverse('resource_attributes', args=[self.res.uuid])
user = TokenAuthUser.objects.get(username='a_super')
self.client.force_authenticate(user=user, token=user.token())
data = [
{
"name": "Quota",
"value": 23
},
{
"name": "cpuTime",
"value": 42
}
]
data = [{"name": "Quota", "value": 23}]
response = self.client.put(url, data=data, format='json')
self.assertEqual("updated", response.data[0]["Quota"]["status"])
self.assertEqual(50, self.attrib.value)
self.assertEqual("23", Attribute.objects.get().value)
self.assertEqual(2, Attribute.objects.get().vec_sp)
self.assertEqual(0, Attribute.objects.get().vec_idp)
self.assertEqual("non-existent", response.data[1]["cpuTime"]["status"])
def test_unchanged(self):
url = reverse('resource_attributes', args=[self.res.uuid])
user = TokenAuthUser.objects.get(username='a_super')
self.client.force_authenticate(user=user, token=user.token())
data = [{"name": "Quota", "value": 50}]
response = self.client.put(url, data=data, format='json')
data = [
{
"name": "Quota",
"value": 23
}
]
self.assertEqual("unchanged", response.data[0]["Quota"]["status"])
self.assertEqual("50", Attribute.objects.get().value)
self.assertEqual(1, Attribute.objects.get().vec_sp)
self.assertEqual(0, Attribute.objects.get().vec_idp)
def test_nonExistent(self):
url = reverse('resource_attributes', args=[self.res.uuid])
user = TokenAuthUser.objects.get(username='a_super')
self.client.force_authenticate(user=user, token=user.token())
data = [{"name": "cpuTime", "value": 42}]
response = self.client.put(url, data=data, format='json')
self.assertEqual("updated", response.data[0]["Quota"]["status"])
self.assertEqual(23, int(Attribute.objects.get().value))
self.assertEqual(3, Attribute.objects.get().vec_sp)
self.assertEqual(0, Attribute.objects.get().vec_idp)
self.assertEqual("non-existent", response.data[0]["cpuTime"]["status"])
self.assertFalse(Attribute.objects.filter(name="cpuTime").exists())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment