def post(self, request, credential_id): credential = get_object_or_404(AerobridgeCredential, pk=credential_id) serializer = AerobridgeCredentialSerializer(credential, data=request.data) if not serializer.is_valid(): return Response({'serializer': serializer, 'credential': credential}) serializer.save() return redirect('credentials-list')
def test_pki_framework_aerobridge_credentials_data_serializer(self): data = self._get_data_for_model('AerobridgeCredential') aerobridge_credentials_serializer = AerobridgeCredentialSerializer(data=data) required_keys = {'name', 'association', 'manufacturer', 'is_active', 'aircraft', 'operator'} self.assertTrue(aerobridge_credentials_serializer.is_valid()) self.assertEqual(set(aerobridge_credentials_serializer.validated_data.keys()), required_keys) self.assertEqual(aerobridge_credentials_serializer.errors, dict())
def test_pki_framework_aerobridge_credentials_serializer(self): data = self._get_data_for_model('AerobridgeCredential') aerobridge_credentials_serializer = AerobridgeCredentialSerializer( data=data) self.assertTrue(aerobridge_credentials_serializer.is_valid()) self.assertNotEqual(aerobridge_credentials_serializer.validated_data, dict) self.assertEqual(aerobridge_credentials_serializer.errors, dict())
def post(self, request, *args, **kwargs): form = CutsomTokenCreateForm(request.POST) if form.is_valid(): serializer = AerobridgeCredentialSerializer(data=form.data) if serializer.is_valid(): secret_key = settings.CRYPTOGRAPHY_SALT.encode('utf-8') f = encrpytion_util.EncrpytionHelper(secret_key= secret_key) enc_token = f.encrypt(message = form.data['token'].encode('utf-8')) serializer.save(name = form.data['name'],token=enc_token, association = form.data['association'],token_type = form.data['token_type'] ) print("saved") return redirect('credentials-list')
def test_pki_framework_aerobridge_credentials_instance_serializer(self): aerobridge_credentials_serializer = AerobridgeCredentialSerializer( instance=AerobridgeCredential.objects.first()) required_keys = { 'id', 'name', 'token_type', 'token', 'extension', 'association', 'manufacturer', 'is_active', 'aircraft', 'operator' } self.assertEqual(set(aerobridge_credentials_serializer.data.keys()), required_keys)
def get(self, request, credential_id): credential = get_object_or_404(AerobridgeCredential, pk=credential_id) serializer = AerobridgeCredentialSerializer(credential) return Response({'serializer': serializer, 'credential': credential})