def test_get_attributes_with_alias(self): narrowed_fieds = narrower(self.obj, [("title", "bounty_name"), ("bounty_id", "id")]) self.assertEquals(sorted(narrowed_fieds.keys()), ['bounty_name', 'id']) self.assertEquals(narrowed_fieds['bounty_name'], self.obj.title) self.assertEquals(narrowed_fieds['id'], self.obj.bounty_id)
def get_base_bounty_values(bounty): base_fields = narrower(bounty, ['title', 'bounty_id', 'tokenSymbol', 'tokenDecimals']) base_fields['total_value'] = calculate_token_quantity(bounty.fulfillmentAmount, bounty.tokenDecimals) base_fields['usd_price'] = Decimal(bounty.usd_price).quantize(Decimal(10) ** -2) base_fields['deadline'] = bounty.deadline.strftime('%m/%d/%Y') base_fields['token_price'] = 'Unkown Price' if not bounty.token else Decimal(bounty.token.price_usd).quantize(Decimal(10) ** -2) base_fields['token_lock_price'] = 'Unkown Price' if not bounty.tokenLockPrice else Decimal(bounty.tokenLockPrice).quantize(Decimal(10) ** -2) base_fields['link'] = bounty_url_for(bounty.bounty_id, bounty.platform) return base_fields
def test_get_nested_attributes_using_double_underscore(self): narrowed_fieds = narrower( self.fullfillment, [("bounty__title", "title"), "bounty__usd_price"]) self.assertEquals(sorted(narrowed_fieds.keys()), sorted(['title', 'bounty__usd_price'])) self.assertEquals(narrowed_fieds['title'], self.obj.title) self.assertEquals(narrowed_fieds['bounty__usd_price'], self.obj.usd_price)
def deadline_extended(bounty_id, **kwargs): bounty = Bounty.objects.get(bounty_id=bounty_id) previous_deadline = narrower(bounty, [('deadline', 'previous_deadline')]) msg = "{title}, {bounty_id}, {previous_deadline}, {deadline} {link}" mix_previous_deadline = wrapped_partial(merge, source2=previous_deadline) add_link = partial(merge, source2={'link': bounty_url_for(bounty_id)}) apply_and_notify(bounty, event='Deadline Extended', action=bounty_client.extend_deadline, inputs=kwargs, fields=['title', 'bounty_id', 'deadline'], msg=msg, slack_client=sc, before_formatter=[mix_previous_deadline, add_link] )
def test_get_attributes_from_bounty_model(self): narrowed_fieds = narrower(self.obj, ["title", "usd_price"]) self.assertEquals(narrowed_fieds['title'], self.obj.title) self.assertEquals(narrowed_fieds['usd_price'], self.obj.usd_price)