Commit 540f0e95 authored by Daniel Schreiber's avatar Daniel Schreiber

Python3 fix

Test dazu
parent c53537ec
Pipeline #27489 passed with stage
in 21 seconds
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
import requests_mock
from django.test import TestCase
from rest_framework.test import APITestCase
from api.models import Attribute, QueueJob, QueueJobStatus, QueueJobType, Resource, ServiceProvider, TokenAuthUser, UserType
from api.utils import queue_utils
import json
import six
class ResourceQueueSyncTest(APITestCase):
def test_remote_answers_with_400(self):
with requests_mock.Mocker() as m:
pass
class DispatchRessourceSyncTest(TestCase):
def test_resource(self):
self.assertEqual(QueueJob.objects.count(), 0)
remote_realm = 'foo.bar'
remote_user = TokenAuthUser(user_type=UserType.TYPE_SYNC, username='foobar', realm=remote_realm, api_url='https://remote.example.org/api')
remote_user.set_unusable_password()
remote_user.full_clean()
remote_user.save()
sp = ServiceProvider(realm=remote_realm, name="foo2", expiry_date='2099-01-01')
sp.full_clean()
sp.save()
r = Resource(sp=sp, eppn='user@foo.bar', expiry_date='2016-01-01 00:00:00', deletion_date='2017-01-01 00:00:00', setup_token='1234')
r.full_clean()
r.save()
att = Attribute(resource=r, name="foo", value="1234")
att.full_clean()
att.save()
att2 = Attribute(resource=r, name="bar", value="5678")
att2.full_clean()
att2.save()
queue_utils.dispatch_resource_sync(r)
self.assertEqual(QueueJob.objects.count(), 1)
qj = QueueJob.objects.first()
self.assertEqual(qj.status, QueueJobStatus.STATUS_READY)
self.assertEqual(qj.type, QueueJobType.TYPE_RES)
object_data = json.loads(qj.obj)
self.assertEqual(object_data['uuid'], six.text_type(r.pk))
self.assertEqual(object_data['realm_idp'], r.realm_idp)
self.assertEqual(object_data['eppn'], r.eppn)
self.assertEqual(object_data['sp'], six.text_type(r.sp.pk))
self.assertEqual(len(object_data['attributes']), 2)
for a in (att, att2):
self.assertTrue({'default_value': '', 'name': a.name, 'value': a.value, 'vec_idp': a.vec_idp, 'vec_sp': a.vec_sp} in object_data['attributes'])
print(object_data)
......@@ -22,7 +22,7 @@ class SyncException(Exception):
def dispatch_resource_sync(resource):
json = JSONRenderer().render(ResourceSerializer(resource).data)
json = JSONRenderer().render(ResourceSerializer(resource).data).decode("utf-8")
# Remote URL can be inferred by the resource's ePPN FQDN-part minus any sub-domains
dest_realm = extract_idp(resource.eppn)
......
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