def test_basic(self):
        serializer = UserProfileBasketSyncSerializer(self.user)
        assert serializer.data == {
            'deleted': False,
            'display_name': None,
            'fxa_id': self.user.fxa_id,
            'homepage': '',
            'id': self.user.pk,
            'last_login': self.user.last_login.replace(microsecond=0).isoformat() + 'Z',
            'location': '',
        }

        self.user.update(display_name='Dîsplay Mé!')
        serializer = UserProfileBasketSyncSerializer(self.user)
        assert serializer.data['display_name'] == 'Dîsplay Mé!'
class AddonBasketSyncSerializer(AddonSerializerWithUnlistedData):
    # We want to send all authors to basket, not just listed ones, and have
    # the full basket-specific serialization.
    authors = UserProfileBasketSyncSerializer(many=True)
    current_version = VersionBasketSerializer()
    is_recommended = serializers.SerializerMethodField()
    latest_unlisted_version = VersionBasketSerializer()
    name = serializers.SerializerMethodField()

    class Meta:
        model = Addon
        fields = ('authors', 'average_daily_users', 'categories',
                  'current_version', 'default_locale', 'guid', 'id',
                  'is_disabled', 'is_recommended', 'last_updated',
                  'latest_unlisted_version', 'name', 'ratings', 'slug',
                  'status', 'type')
        read_only_fields = fields

    def get_name(self, obj):
        # Basket doesn't want translations, we run the serialization task under
        # the add-on default locale so we can just return the name as string.
        return str(obj.name)

    def get_is_recommended(self, obj):
        # Borrow the logic from is_featured so we don't have to define it twice
        return self.get_is_featured(obj)
 def test_deleted(self):
     self.user.delete()
     serializer = UserProfileBasketSyncSerializer(self.user)
     assert serializer.data == {
         'deleted': True,
         'display_name': '',
         'fxa_id': self.user.fxa_id,
         'homepage': '',
         'id': self.user.pk,
         'last_login': self.user.last_login.replace(microsecond=0).isoformat() + 'Z',
         'location': '',
     }
 def test_userprofile(self):
     responses.add(responses.POST,
                   'https://basket.allizom.org/amo-sync/userprofile/',
                   json=True)
     user = user_factory()
     sync_object_to_basket('userprofile', user.pk)
     assert len(responses.calls) == 1
     request = responses.calls[0].request
     assert request.headers['x-api-key'] == settings.BASKET_API_KEY
     body = request.body
     data = json.loads(body)
     expected_data = UserProfileBasketSyncSerializer(user).data
     assert expected_data
     assert data == expected_data