示例#1
0
    def test_get_avatar_url_no_picture_setting(self):
        extra_data = '''
{
  "profilePicture": {
    "displayImage": "urn:li:digitalmediaAsset:12345abcdefgh-12abcd"
  },
  "id": "1234567",
  "lastName": {
    "preferredLocale": {
      "language": "en",
      "country": "US"
    },
    "localized": {
      "en_US": "Penners"
    }
  },
  "firstName": {
    "preferredLocale": {
      "language": "en",
      "country": "US"
    },
    "localized": {
      "en_US": "Raymond"
    }
  }
}
'''
        acc = SocialAccount(
            extra_data=loads(extra_data),
            provider='linkedin_oauth2',
        )
        self.assertIsNone(acc.get_avatar_url())
示例#2
0
def on_social_account_added(sender, instance: SocialAccount, created, **kwargs):
    """Fetch social account name and avatar, and add them to the Profile."""
    if not created:
        return
    name = instance.extra_data.get('name')
    if name:
        log.debug('Updating name via socialaccount for user %i' % instance.user.id)
        instance.user.profile.name = name
        instance.user.profile.save()

    # Look for Social Account avatar and update the avatar
    url_avatar = instance.get_avatar_url()
    if url_avatar:
        log.debug('Updating avatar via socialaccount for user %i' % instance.user.id)
        image_content = ContentFile(requests.get(url_avatar).content)
        instance.user.profile.avatar.save("profile.jpg", image_content)
示例#3
0
    def test_get_avatar_url_float_vs_int(self):
        extra_data = '''
{
  "profilePicture": {
    "displayImage": "urn:li:digitalmediaAsset:12345abcdefgh-12abcd"
  },
  "id": "1234567",
  "lastName": {
    "preferredLocale": {
      "language": "en",
      "country": "US"
    },
    "localized": {
      "en_US": "Penners"
    }
  },
  "firstName": {
    "preferredLocale": {
      "language": "en",
      "country": "US"
    },
    "localized": {
      "en_US": "Raymond"
    }
  },
  "profilePicture": {
    "displayImage~": {
      "elements": [
        {
          "authorizationMethod": "PUBLIC",
          "data": {
            "com.linkedin.digitalmedia.mediaartifact.StillImage": {
              "storageSize": {
                "height": 100,
                "width": 100
              },
              "storageAspectRatio": {
                "heightAspect": 1.0,
                "formatted": "1.00:1.00",
                "widthAspect": 1.0
              },
              "displaySize": {
                "height": 100.0,
                "width": 100.0,
                "uom": "PX"
              },
              "rawCodecSpec": {
                "name": "jpeg",
                "type": "image"
              },
              "displayAspectRatio": {
                "heightAspect": 1.0,
                "formatted": "1.00:1.00",
                "widthAspect": 1.0
              },
              "mediaType": "image/jpeg"
            }
          },
          "artifact": "urn:li:digitalmediaMediaArtifact:avatar",
          "identifiers": [
            {
              "identifierExpiresInSeconds": 4,
              "file": "urn:li:digitalmediaFile:this-is-the-link",
              "index": 0,
              "identifier": "this-is-the-link",
              "mediaType": "image/jpeg",
              "identifierType": "EXTERNAL_URL"
            }
          ]
        }
      ]
    }
  }
}
'''
        acc = SocialAccount(
            extra_data=loads(extra_data),
            provider='linkedin_oauth2',
        )
        self.assertEqual('this-is-the-link', acc.get_avatar_url())