Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Denomination bracket - DO NOT MERGE #39

Conversation

shivkumarsah
Copy link
Contributor

Please review network denomination bracket which include the below features:

  • There shall be an interface to configure prepaid top up amount with corresponding validity.
  • Top up amount value should define range, say 1-10ps, 10-50 ps. Ranges must be contiguous (no gaps between them), non-overlapping and exhaustive, such that every valid top-up amount can be assigned to exactly one denomination bracket.
  • Validity should be in number of days.
  • Any amount range can be mapped to any number of days.
  • User can delete the already set range mapping with validity and can define the new mapping.
  • User can delete the validity period for specific range and set new range

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Contributor

@kkroo kkroo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small notes! I think we need to add an asynchronous task to vacuum subscriber balances after validity_days is passed in another diff (I think you have that)

network = models.ForeignKey('Network', null=True, on_delete=models.CASCADE)

def __unicode__(self):
return "Amount %s - %d for %s(days)" % (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: humanize_credits on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit # 1367cfd

CURRENCIES[currency]).amount_raw
validity_days = int(request.POST.get('validity_days')) or 0
if validity_days > 10000:
validity_days = 10000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Raise an error rather than forcing a maximum? Just saying you can do a lot of these checks in subclasses of forms.Form and raise forms.ValidationError and keep the post handler for more involved checks of combined fields/writing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit # 1367cfd Create configurable setting for limit and showing error now

return redirect(urlresolvers.reverse('network-denominations'))

user_profile = models.UserProfile.objects.get(user=request.user)
with transaction.atomic():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

@facebook-github-bot
Copy link

@shivkumarsah updated the pull request - view changes

Copy link
Contributor

@9muir 9muir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new changes look good. We'll review the whole PR and hopefully get it merged quickly

@shivkumarsah
Copy link
Contributor Author

To vacuum subscriber balances after validity_days, we have created another PR #42

@facebook-github-bot
Copy link

@kkroo has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@9muir 9muir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to go ahead and merge this set of changes, in the interest of moving things forward, but please create a new PR to address the comments below about the tests that were created.

self.client.get('/logout')


class DenominationUITest(TestBase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really a UI test, but an API test. And it's testing Denomination, not User.

class DenominationUITest(TestBase):
"""Testing that we can add User in the UI."""

def test_add_denominaton(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests should be broken out into a small set of tests that verify, for each operation, that an unauthenticated user cannot do them (and also that an authenticated user without the appropriate permission cannot do them either), and then a much larger set of tests that verify the various constraints on denominations.

self.logout()
response = self.client.get('/dashboard/network/denominations')
# Anonymous User can not see this page so returning permission denied.
self.assertEqual(302, response.status_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

302 doesn't seem like the correct return code here, unless it's an artifact of authentication failure being translated into redirection back to the login page. That doesn't seem like the right behaviour an API call though.

'validity_days': 3
}
response = self.client.post('/dashboard/network/denominations', data)
self.assertEqual(302, response.status_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does an authenticated user get a 302 here? Isn't the point of this test that it should pass?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants