def icon_or_default(self): if self.icon_image: return uri_to_url(self.icon_image) which = self.id % 10 return uri_to_url('/static/defaults/avatar_{}.jpg'.format( which, ))
def setUp(self): settings.KEPI['LOCAL_OBJECT_HOSTNAME'] = 'testserver' self.alice = create_local_person('alice') self.client = Client() self.alice_url = uri_to_url(settings.KEPI['USER_LINK'] % { 'username': '******', })
def url(self): if self.remote_url is not None: return self.remote_url return uri_to_url(settings.KEPI['STATUS_LINK'] % { 'username': self.account.username, 'id': self.id, })
def activity_url(self): if self.remote_url is not None: raise ValueError( "Activity URL is not stored for remote statuses", ) return uri_to_url(settings.KEPI['STATUS_ACTIVITY_LINK'] % { 'username': self.account.username, 'id': self.id, })
def test_get_single_status(self): self._alice = create_local_person(name='alice') self._status = create_local_status( content='Hello world.', posted_by=self._alice, ) content = self.get( path='/api/v1/statuses/' + str(self._alice.id), as_user=self._alice, ) for field, expected in STATUS_EXPECTED.items(): self.assertIn(field, content) self.assertEqual(content[field], expected, msg="field '{}'".format(field)) self.assertIn('account', content) account = content['account'] account_expected = ACCOUNT_EXPECTED.copy() account_expected['statuses_count'] = 1 for field, expected in account_expected.items(): if field.startswith('status['): # this doesn't give us the status dict continue self.assertIn(field, account) self.assertEqual(account[field], expected, msg="account field '{}'".format(field)) self.assertIn('id', content) self.assertIn('url', content) self.assertEqual( content['url'], uri_to_url(settings.KEPI['STATUS_LINK'] % { 'username': '******', 'id': content['id'], }))
def _do_something_with(self, the_person, request): try: if the_person.auto_follow: offer = None else: number = random.randint(0, 0xffffffff) offer = uri_to_url(settings.KEPI['FOLLOW_REQUEST_LINK'] % { 'username': request.user.username, 'number': number, }) follow = trilby_models.Follow( follower=request.user.localperson, following=the_person, offer=offer, ) with transaction.atomic(): follow.save(send_signal=True, ) logger.info(' -- follow: %s', follow) logger.debug(' -- offer ID: %s', offer) if the_person.auto_follow: follow_back = trilby_models.Follow( follower=the_person, following=request.user.localperson, offer=None, ) with transaction.atomic(): follow_back.save(send_signal=True, ) logger.info(' -- follow back: %s', follow_back) return the_person except IntegrityError: logger.info(' -- not creating a follow; it already exists')
def followers_url(self): return uri_to_url(settings.KEPI['USER_FOLLOWERS_LINK'] % { 'username': self.local_user.username, })
def featured_url(self): return uri_to_url(settings.KEPI['USER_FEATURED_LINK'] % { 'username': self.local_user.username, })
def outbox_url(self): return uri_to_url(settings.KEPI['USER_OUTBOX_LINK'] % { 'username': self.local_user.username, })
def header_or_default(self): if self.header_image: return uri_to_url(self.header_image) return uri_to_url('/static/defaults/header.jpg')
def to_representation(self, instance): return { 'sharedInbox': uri_to_url(settings.KEPI['SHARED_INBOX_LINK'], ), }