Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve invalid package dimensions exceptions #35

Merged
merged 6 commits into from
Apr 19, 2017

Conversation

osantana
Copy link
Contributor

Improve package dimension validation to raise different exceptions for minimum vs. maximum invalid dimensions.

I'll wait for #34 merge and then bump minor version to make a release of this PR.

@adlermedrado
Copy link
Contributor

👍

Copy link
Contributor

@caiocarrara caiocarrara left a comment

Choose a reason for hiding this comment

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

Do not forget to bump the version when other PR be merged.


if service and service.max_weight and weight > service.max_weight:
raise InvalidPackageWeightError("Max weight exceeded {!r}g (max. {!r}g)".format(weight, service.max_weight))
raise exceptions.InvalidPackageWeightError(
Copy link
Contributor

@lamenezes lamenezes Apr 18, 2017

Choose a reason for hiding this comment

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

I believe the correct exception here is InvalidMaxPackageWeightError. Isn't it?

@osantana
Copy link
Contributor Author

I'll will change the minimum validations to d <= 0 instead of MIN_D. We can send packages with, eg, width == 1. But we've to use max(width, MIN_WIDTH) for volume/freight calculation.

@georgeyk
Copy link
Contributor

I'll will change the minimum validations to d <= 0 instead of MIN_D.

Why ? Isn't d=0, invalid ?

@osantana
Copy link
Contributor Author

Why ? Isn't d=0, invalid ?

if d <= 0: raises minimum error instead of if d < MIN_D: raises min error

@osantana
Copy link
Contributor Author

I rewrote the whole PR to allow dimensions below the minimum in the packages but maintaining the minimum dimensions for volume and weight calculation.

if weight <= 0:
raise exceptions.InvalidMinPackageWeightError("Invalid weight {!r}g".format(weight))

if self.service and weight > self.service.max_weight:
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things here:

  • As I could see, it's possible to exist a Package without a service. The business rules allow a Package without service? Seems weird.
  • I think the exception message could be improved putting the service name on it. Max weight exceeded [...] for service xpto. If you accept it, there's another equal message in validate()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I could see, it's possible to exist a Package without a service. The business rules allow a Package without service? Seems weird.

A Package is just a package with their type and dimensions and weight. So we can have a package before the Service definition (we can choose the service for this package after the package already exists). We can also choose the correct service as a consequence of the package weight.

There is a modeling issue: package doesn't need a service property/attribute. It must delegate the weight validation to the ShippingLabel. But this is a hard refactor to do and we don't need it for now.

I think the exception message could be improved putting the service name on it. Max weight exceeded [...] for service xpto. If you accept it, there's another equal message in validate()

👍

Copy link
Contributor

@lamenezes lamenezes left a comment

Choose a reason for hiding this comment

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

Só um pequeno comentário, o resto tá 👍

self.sequence = sequence
self.service = service

@property
def volumetric_weight(self):
def width(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

nessas properties não vão type hints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

esquecimento :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

feito

@lamenezes lamenezes merged commit 0d1e517 into master Apr 19, 2017
@lamenezes lamenezes deleted the improve-validate-pak-size branch April 19, 2017 13:54
@osantana osantana restored the improve-validate-pak-size branch April 19, 2017 14:03
@osantana osantana deleted the improve-validate-pak-size branch April 19, 2017 14:05
@osantana osantana restored the improve-validate-pak-size branch April 19, 2017 14:07
@osantana osantana deleted the improve-validate-pak-size branch April 19, 2017 18:39
osantana pushed a commit that referenced this pull request Apr 28, 2017
Improve invalid package dimensions exceptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants