Skip to content

Updates for Summer 2024 Semester #16

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

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Image for a NYU Lab development environment
FROM rofrano/nyu-devops-base:sp24
FROM rofrano/nyu-devops-base:su24

# Set up the Python development environment
WORKDIR /app
Expand Down
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"customizations": {
"vscode": {
"settings": {
"cSpell.words": [
"sqlalchemy",
"psycopg",
"pytest"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
Expand Down
7 changes: 4 additions & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ services:
- ..:/app
command: sleep infinity
environment:
PORT: 8000
PORT: 8080
FLASK_APP: wsgi:app
FLASK_DEBUG: "True"
GUNICORN_BIND: "0.0.0.0:8000"
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/postgres
GUNICORN_BIND: "0.0.0.0:8080"
DATABASE_URI: postgresql+psycopg://postgres:pgs3cr3t@postgres:5432/accounts
networks:
- dev
depends_on:
Expand All @@ -29,6 +29,7 @@ services:
# - 5432:5432
environment:
POSTGRES_PASSWORD: pgs3cr3t
POSTGRES_DB: accounts
volumes:
- postgres:/var/lib/postgresql/data
networks:
Expand Down
2 changes: 1 addition & 1 deletion .flaskenv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FLASK_RUN_PORT=8000
FLASK_RUN_PORT=8080
FLASK_APP=wsgi:app
946 changes: 674 additions & 272 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
Flask = "^3.0.2"
Flask = "^3.0.3"
Flask-SQLAlchemy = "^3.1.1"
psycopg = {extras = ["binary"], version = "^3.1.17"}
retry = "^0.9.2"
psycopg = {extras = ["binary"], version = "^3.1.19"}
retry2 = "^0.9.5"
python-dotenv = "^1.0.1"
gunicorn = "^22.0.0"

[tool.poetry.group.dev.dependencies]
honcho = "^1.1.0"
pylint = "^3.0.2"
flake8 = "^6.1.0"
black = "^24.3.0"
pytest = "^7.4.3"
pylint = "^3.2.2"
flake8 = "^7.0.0"
black = "^24.4.2"
pytest = "^8.2.1"
pytest-pspec = "^0.0.4"
pytest-cov = "^4.1.0"
pytest-cov = "^5.0.0"
factory-boy = "^3.3.0"
coverage = "^7.3.2"
coverage = "^7.5.3"
httpie = "^3.2.2"

[build-system]
requires = ["poetry-core"]
Expand Down Expand Up @@ -56,7 +57,6 @@ exclude_lines = [
"pragma: no cover",
"pragma: no branch",
"pass",
"subprocess.CalledProcessError",
"sys.exit",
"if __name__ == .__main__.:"
]
Expand Down
9 changes: 6 additions & 3 deletions service/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
######################################################################

# cspell: ignore= userid, backref
"""
Persistent Base class for database CRUD functions
"""
Expand All @@ -36,8 +36,9 @@ class Account(db.Model, PersistentBase):

# Table Schema
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64))
email = db.Column(db.String(64))
name = db.Column(db.String(64), nullable=False)
userid = db.Column(db.String(16), nullable=False)
email = db.Column(db.String(64), nullable=False)
phone_number = db.Column(db.String(32), nullable=True) # phone number is optional
date_joined = db.Column(db.Date(), nullable=False, default=date.today())
addresses = db.relationship("Address", backref="account", passive_deletes=True)
Expand All @@ -50,6 +51,7 @@ def serialize(self):
account = {
"id": self.id,
"name": self.name,
"userid": self.userid,
"email": self.email,
"phone_number": self.phone_number,
"date_joined": self.date_joined.isoformat(),
Expand All @@ -68,6 +70,7 @@ def deserialize(self, data):
"""
try:
self.name = data["name"]
self.userid = data["userid"]
self.email = data["email"]
self.phone_number = data.get("phone_number")
self.date_joined = date.fromisoformat(data["date_joined"])
Expand Down
31 changes: 16 additions & 15 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
######################################################################

# cspell:ignore userid postalcode
"""
Test Factory to make fake objects for testing
"""
from datetime import date
import factory
from factory import Factory, SubFactory, Sequence, Faker, post_generation
from factory.fuzzy import FuzzyChoice, FuzzyDate
from service.models import Account, Address


class AccountFactory(factory.Factory):
class AccountFactory(Factory):
"""Creates fake Accounts"""

# pylint: disable=too-few-public-methods
Expand All @@ -32,15 +32,16 @@ class Meta:

model = Account

id = factory.Sequence(lambda n: n)
name = factory.Faker("name")
email = factory.Faker("email")
phone_number = factory.Faker("phone_number")
id = Sequence(lambda n: n)
name = Faker("name")
userid = Sequence(lambda n: f"User{n:04d}")
email = Faker("email")
phone_number = Faker("phone_number")
date_joined = FuzzyDate(date(2008, 1, 1))
# the many side of relationships can be a little wonky in factory boy:
# https://factoryboy.readthedocs.io/en/latest/recipes.html#simple-many-to-many-relationship

@factory.post_generation
@post_generation
def addresses(
self, create, extracted, **kwargs
): # pylint: disable=method-hidden, unused-argument
Expand All @@ -52,7 +53,7 @@ def addresses(
self.addresses = extracted


class AddressFactory(factory.Factory):
class AddressFactory(Factory):
"""Creates fake Addresses"""

# pylint: disable=too-few-public-methods
Expand All @@ -61,11 +62,11 @@ class Meta:

model = Address

id = factory.Sequence(lambda n: n)
id = Sequence(lambda n: n)
account_id = None
name = FuzzyChoice(choices=["home", "work", "other"])
street = factory.Faker("street_address")
city = factory.Faker("city")
state = factory.Faker("state_abbr")
postal_code = factory.Faker("postalcode")
account = factory.SubFactory(AccountFactory)
street = Faker("street_address")
city = Faker("city")
state = Faker("state_abbr")
postal_code = Faker("postalcode")
account = SubFactory(AccountFactory)
7 changes: 6 additions & 1 deletion tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
######################################################################

# cspell:ignore userid
"""
Test cases for Account Model
"""
Expand Down Expand Up @@ -71,13 +71,15 @@ def test_create_an_account(self):
# pylint: disable=unexpected-keyword-arg
account = Account(
name=fake_account.name,
userid=fake_account.userid,
email=fake_account.email,
phone_number=fake_account.phone_number,
date_joined=fake_account.date_joined,
)
self.assertIsNotNone(account)
self.assertEqual(account.id, None)
self.assertEqual(account.name, fake_account.name)
self.assertEqual(account.userid, fake_account.userid)
self.assertEqual(account.email, fake_account.email)
self.assertEqual(account.phone_number, fake_account.phone_number)
self.assertEqual(account.date_joined, fake_account.date_joined)
Expand Down Expand Up @@ -109,6 +111,7 @@ def test_read_account(self):
found_account = Account.find(account.id)
self.assertEqual(found_account.id, account.id)
self.assertEqual(found_account.name, account.name)
self.assertEqual(found_account.userid, account.userid)
self.assertEqual(found_account.email, account.email)
self.assertEqual(found_account.phone_number, account.phone_number)
self.assertEqual(found_account.date_joined, account.date_joined)
Expand Down Expand Up @@ -188,6 +191,7 @@ def test_serialize_an_account(self):
serial_account = account.serialize()
self.assertEqual(serial_account["id"], account.id)
self.assertEqual(serial_account["name"], account.name)
self.assertEqual(serial_account["userid"], account.userid)
self.assertEqual(serial_account["email"], account.email)
self.assertEqual(serial_account["phone_number"], account.phone_number)
self.assertEqual(serial_account["date_joined"], str(account.date_joined))
Expand All @@ -210,6 +214,7 @@ def test_deserialize_an_account(self):
new_account = Account()
new_account.deserialize(serial_account)
self.assertEqual(new_account.name, account.name)
self.assertEqual(new_account.userid, account.userid)
self.assertEqual(new_account.email, account.email)
self.assertEqual(new_account.phone_number, account.phone_number)
self.assertEqual(new_account.date_joined, account.date_joined)
Expand Down
Loading