Skip to content

Instantly share code, notes, and snippets.

@neosergio
Created August 19, 2021 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosergio/1463dad2e3c007965c764a98d2dc0235 to your computer and use it in GitHub Desktop.
Save neosergio/1463dad2e3c007965c764a98d2dc0235 to your computer and use it in GitHub Desktop.

Write a simple property

  • Write a simple Promo class. Its constructor receives two variables: name (which must be a string) and expires (which must be a datetime object).

  • Add a property called expired which returns a boolean value indicating whether the promo has expired or not.

Proposed solution

from datetime import datetime, timedelta

NOW = datetime.now()


class Promo:
    def __init__(self, name, expires):
        self.name = str(name)
        self.expires = expires
    
    @property    
    def expired(self):
        if self.expires < NOW:
            return True
        return False

Unit Testing

Write tests for:

  • Check output with promo expired
  • Check output with promo not expired
  • Check if property is used in the Promo class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment