Skip to content

Commit

Permalink
Merge pull request #31 from galliumplus/feature/database
Browse files Browse the repository at this point in the history
LET'S FUCKING GOOOO
  • Loading branch information
louisdevie authored Sep 24, 2023
2 parents 885bc91 + 5474bb4 commit 34f5c9b
Show file tree
Hide file tree
Showing 104 changed files with 2,596 additions and 551 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Vérifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore /warnaserror -c Test
run: dotnet build --no-restore /warnaserror -c Release

unit-tests:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

MariaDbTests

# User-specific files
*.rsuser
*.suo
Expand Down
4 changes: 3 additions & 1 deletion .tests/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import urllib3
import requests
import decimal

from utils.launcher import Launcher

Expand All @@ -13,4 +14,5 @@


if __name__ == "__main__":
Launcher.launch("0.4.0")
decimal.DefaultContext.prec = 2
Launcher.launch("0.5.0")
Binary file modified .tests/requirements.txt
Binary file not shown.
14 changes: 7 additions & 7 deletions .tests/tests/access_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ def test_login_permissions_normal(self):
president_token = self.expect(president_session).to.have.an_item("token").value
president_token_auth = BearerAuth(president_token)

member_read_response = self.get("products/0", auth=member_token_auth)
member_read_response = self.get("products/1", auth=member_token_auth)
self.expect(member_read_response.status_code).to.be.equal_to(403)

member_edit_response = self.post(
"categories", json={"name": "Catégorie"}, auth=member_token_auth
)
self.expect(member_edit_response.status_code).to.be.equal_to(403)

president_read_response = self.get("products/0", auth=president_token_auth)
president_read_response = self.get("products/1", auth=president_token_auth)
self.expect(president_read_response.status_code).to.be.equal_to(200)

president_edit_response = self.post(
Expand All @@ -106,7 +106,7 @@ def test_login_permissions_normal(self):
def test_login_permissions_restricted(self):
member_auth = BasicAuth("lomens", "motdepasse")
president_auth = BasicAuth("eb069420", "motdepasse")
key = "test-api-key-restricted"
key = "test-api-key-restric"

member_response = self.post(
"login", auth=member_auth, headers={"X-Api-Key": key}
Expand Down Expand Up @@ -140,15 +140,15 @@ def test_login_permissions_restricted(self):
president_token = self.expect(president_session).to.have.an_item("token").value
president_token_auth = BearerAuth(president_token)

member_read_response = self.get("products/0", auth=member_token_auth)
member_read_response = self.get("products/1", auth=member_token_auth)
self.expect(member_read_response.status_code).to.be.equal_to(403)

member_edit_response = self.post(
"categories", json={"name": "Catégorie"}, auth=member_token_auth
)
self.expect(member_edit_response.status_code).to.be.equal_to(403)

president_read_response = self.get("products/0", auth=president_token_auth)
president_read_response = self.get("products/1", auth=president_token_auth)
self.expect(president_read_response.status_code).to.be.equal_to(200)

president_edit_response = self.post(
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_login_permissions_minimum(self):
president_token = self.expect(president_session).to.have.an_item("token").value
president_token_auth = BearerAuth(president_token)

member_read_response = self.get("products/0", auth=member_token_auth)
member_read_response = self.get("products/1", auth=member_token_auth)
# allowed by api key
self.expect(member_read_response.status_code).to.be.equal_to(200)

Expand All @@ -203,7 +203,7 @@ def test_login_permissions_minimum(self):
)
self.expect(member_edit_response.status_code).to.be.equal_to(403)

president_read_response = self.get("products/0", auth=president_token_auth)
president_read_response = self.get("products/1", auth=president_token_auth)
self.expect(president_read_response.status_code).to.be.equal_to(200)

president_edit_response = self.post(
Expand Down
12 changes: 6 additions & 6 deletions .tests/tests/category_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def test_category_no_authentification(self):
self.expect(response.status_code).to.be.equal_to(401)
response = self.post("categories", {})
self.expect(response.status_code).to.be.equal_to(401)
response = self.get("categories/0")
response = self.get("categories/1")
self.expect(response.status_code).to.be.equal_to(401)
response = self.put("categories/0", {})
response = self.put("categories/1", {})
self.expect(response.status_code).to.be.equal_to(401)
response = self.delete("categories/0")
response = self.delete("categories/1")
self.expect(response.status_code).to.be.equal_to(401)

def test_category_no_permission(self):
Expand All @@ -153,9 +153,9 @@ def test_category_no_permission(self):
self.expect(response.status_code).to.be.equal_to(403)
response = self.post("categories", {"name": "/"})
self.expect(response.status_code).to.be.equal_to(403)
response = self.get("categories/0")
response = self.get("categories/1")
self.expect(response.status_code).to.be.equal_to(403)
response = self.put("categories/0", {"name": "/"})
response = self.put("categories/1", {"name": "/"})
self.expect(response.status_code).to.be.equal_to(403)
response = self.delete("categories/0")
response = self.delete("categories/1")
self.expect(response.status_code).to.be.equal_to(403)
55 changes: 28 additions & 27 deletions .tests/tests/order_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from random import randint
from decimal import Decimal, getcontext as decimal_context

from utils.test_base import TestBase
from utils.auth import BearerAuth
Expand All @@ -22,8 +23,8 @@ def test_buy_nothing(self):
)

def test_buy_not_deposit(self):
self.set_stock(0, 50)
self.set_stock(1, 50)
self.set_stock(2, 50)

self.buy_not_deposit("CASH")
self.buy_not_deposit("CREDIT_CARD")
Expand All @@ -36,13 +37,13 @@ def test_buy_not_deposit(self):
self.buy_not_deposit("PAYPAL", "lomens")

# 9x2 achetés
self.expect(self.stock(0)).to.be.equal_to(32)
self.expect(self.stock(1)).to.be.equal_to(32)
# 9x3 achetés
self.expect(self.stock(1)).to.be.equal_to(23)
self.expect(self.stock(2)).to.be.equal_to(23)

def buy_not_deposit(self, payment_method, customer=None):
valid_order = {
"items": [{"product": 0, "quantity": 2}, {"product": 1, "quantity": 3}],
"items": [{"product": 1, "quantity": 2}, {"product": 2, "quantity": 3}],
"paymentMethod": payment_method,
}

Expand All @@ -53,14 +54,14 @@ def buy_not_deposit(self, payment_method, customer=None):
self.expect(response.status_code).to.be.equal_to(200)

def test_buy_deposit_invalid(self):
self.set_stock(0, 50)
self.set_stock(1, 50)
self.set_stock(2, 50)
self.set_deposit("lomens", 20)

# id adhérent manquant

order = {
"items": [{"product": 0, "quantity": 2}, {"product": 1, "quantity": 3}],
"items": [{"product": 1, "quantity": 2}, {"product": 2, "quantity": 3}],
"paymentMethod": "DEPOSIT",
}

Expand Down Expand Up @@ -89,58 +90,58 @@ def test_buy_deposit_invalid(self):
self.expect(response.status_code).to.be.equal_to(400)

def test_buy_deposit_member(self):
self.set_stock(0, 20)
self.set_stock(1, 20)
self.set_stock(2, 20)
self.set_deposit("lomens", 20)
self.grant_membership("lomens")

order = {
"items": [{"product": 0, "quantity": 2}, {"product": 1, "quantity": 3}],
"items": [{"product": 1, "quantity": 2}, {"product": 2, "quantity": 3}],
"paymentMethod": "DEPOSIT",
"customer": "lomens",
}

response = self.post("orders", order)
self.expect(response.status_code).to.be.equal_to(200)

self.expect(self.stock(0)).to.be.equal_to(18)
self.expect(self.stock(1)).to.be.equal_to(17)
self.expect(self.stock(1)).to.be.equal_to(18)
self.expect(self.stock(2)).to.be.equal_to(17)

product_0_price = self.get("products/0").json()["memberPrice"]
product_1_price = self.get("products/1").json()["memberPrice"]
product_0_price = self.get("products/1").json()["memberPrice"]
product_1_price = self.get("products/2").json()["memberPrice"]
expected_price = product_0_price * 2 + product_1_price * 3
self.expect(self.deposit("lomens")).to.be.equal_to(20 - expected_price)

def test_buy_deposit_non_member(self):
self.set_stock(0, 20)
self.set_stock(1, 20)
self.set_stock(2, 20)
self.set_deposit("lomens", 20)
self.revoke_membership("lomens")

order = {
"items": [{"product": 0, "quantity": 2}, {"product": 1, "quantity": 3}],
"items": [{"product": 1, "quantity": 2}, {"product": 2, "quantity": 3}],
"paymentMethod": "DEPOSIT",
"customer": "lomens",
}

response = self.post("orders", order)
self.expect(response.status_code).to.be.equal_to(200)

self.expect(self.stock(0)).to.be.equal_to(18)
self.expect(self.stock(1)).to.be.equal_to(17)
self.expect(self.stock(1)).to.be.equal_to(18)
self.expect(self.stock(2)).to.be.equal_to(17)

product_0_price = self.get("products/0").json()["nonMemberPrice"]
product_1_price = self.get("products/1").json()["nonMemberPrice"]
product_0_price = self.get("products/1").json()["nonMemberPrice"]
product_1_price = self.get("products/2").json()["nonMemberPrice"]
expected_price = product_0_price * 2 + product_1_price * 3
self.expect(self.deposit("lomens")).to.be.equal_to(20 - expected_price)

def test_buy_quantity(self):
# quantité < stock

self.set_stock(0, 6)
self.set_stock(1, 6)

order = {
"items": [{"product": 0, "quantity": 3}],
"items": [{"product": 1, "quantity": 3}],
"paymentMethod": "CASH",
}

Expand All @@ -149,7 +150,7 @@ def test_buy_quantity(self):

# quantité = stock

self.set_stock(0, 6)
self.set_stock(1, 6)

order["items"][0]["quantity"] = 6

Expand All @@ -158,7 +159,7 @@ def test_buy_quantity(self):

# quantité > stock

self.set_stock(0, 6)
self.set_stock(1, 6)

order["items"][0]["quantity"] = 9

Expand All @@ -180,14 +181,14 @@ def test_buy_quantity(self):
self.expect(response.status_code).to.be.equal_to(400)

def test_buy_deposit_amount(self):
self.set_stock(0, 100)
self.set_stock(1, 100)

order = {
"items": [{"product": 0, "quantity": 3}],
"items": [{"product": 1, "quantity": 3}],
"paymentMethod": "DEPOSIT",
"customer": "lomens",
}
product_price = self.get("products/0").json()["memberPrice"]
product_price = Decimal(self.get("products/1").json()["memberPrice"])
order_total_price = product_price * 3

self.grant_membership("lomens")
Expand All @@ -201,7 +202,7 @@ def test_buy_deposit_amount(self):

# crédit = prix

self.set_deposit("lomens", order_total_price * 2)
self.set_deposit("lomens", order_total_price)

response = self.post("orders", order)
self.expect(response.status_code).to.be.equal_to(200)
Expand All @@ -223,7 +224,7 @@ def test_buy_no_authorization(self):
self.set_authentification(BearerAuth("12345678901234567890"))

order = {
"items": [{"product": 0, "quantity": 2}, {"product": 1, "quantity": 3}],
"items": [{"product": 1, "quantity": 2}, {"product": 2, "quantity": 3}],
"paymentMethod": "DEPOSIT",
"customer": "lomens",
}
Expand Down
12 changes: 6 additions & 6 deletions .tests/tests/product_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ def test_product_no_authentification(self):
self.expect(response.status_code).to.be.equal_to(401)
response = self.post("products", {})
self.expect(response.status_code).to.be.equal_to(401)
response = self.get("products/0")
response = self.get("products/1")
self.expect(response.status_code).to.be.equal_to(401)
response = self.put("products/0", {})
response = self.put("products/1", {})
self.expect(response.status_code).to.be.equal_to(401)
response = self.delete("products/0")
response = self.delete("products/1")
self.expect(response.status_code).to.be.equal_to(401)

def test_product_no_permission(self):
Expand All @@ -309,9 +309,9 @@ def test_product_no_permission(self):
self.expect(response.status_code).to.be.equal_to(403)
response = self.post("products", product)
self.expect(response.status_code).to.be.equal_to(403)
response = self.get("products/0")
response = self.get("products/1")
self.expect(response.status_code).to.be.equal_to(403)
response = self.put("products/0", product)
response = self.put("products/1", product)
self.expect(response.status_code).to.be.equal_to(403)
response = self.delete("products/0")
response = self.delete("products/1")
self.expect(response.status_code).to.be.equal_to(403)
20 changes: 10 additions & 10 deletions .tests/tests/role_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def test_role_create(self):
def test_role_edit(self):
valid_role = {"name": "Trésorier", "permissions": 0}

response = self.put("roles/0", valid_role)
response = self.put("roles/1", valid_role)
self.expect(response.status_code).to.be.equal_to(200)

edited_role = self.get("roles/0").json()
edited_role = self.get("roles/1").json()
self.expect(edited_role["name"]).to.be.equal_to("Trésorier")
self.expect(edited_role["permissions"]).to.be.equal_to(0)

Expand All @@ -123,7 +123,7 @@ def test_role_edit(self):
# Informations manquantes

invalid_role = {"name": "Vice-Trésorier"}
response = self.put("roles/0", invalid_role)
response = self.put("roles/1", invalid_role)
self.expect(response.status_code).to.be.equal_to(400)
self.expect(response.json()).to.have.an_item("code").that._is.equal_to(
"INVALID_ITEM"
Expand All @@ -132,7 +132,7 @@ def test_role_edit(self):
# Informations non valides

invalid_role = {"name": "", "permissions": -1}
response = self.put("roles/0", invalid_role)
response = self.put("roles/1", invalid_role)
self.expect(response.status_code).to.be.equal_to(400)
self.expect(response.json()).to.have.an_item("code").that._is.equal_to(
"INVALID_ITEM"
Expand Down Expand Up @@ -164,11 +164,11 @@ def test_role_no_authentification(self):
self.expect(response.status_code).to.be.equal_to(401)
response = self.post("roles", {})
self.expect(response.status_code).to.be.equal_to(401)
response = self.get("roles/0")
response = self.get("roles/1")
self.expect(response.status_code).to.be.equal_to(401)
response = self.put("roles/0", {})
response = self.put("roles/1", {})
self.expect(response.status_code).to.be.equal_to(401)
response = self.delete("roles/0")
response = self.delete("roles/1")
self.expect(response.status_code).to.be.equal_to(401)

def test_role_no_permission(self):
Expand All @@ -178,9 +178,9 @@ def test_role_no_permission(self):
self.expect(response.status_code).to.be.equal_to(403)
response = self.post("roles", {"name": "/", "permissions": 0})
self.expect(response.status_code).to.be.equal_to(403)
response = self.get("roles/0")
response = self.get("roles/1")
self.expect(response.status_code).to.be.equal_to(403)
response = self.put("roles/0", {"name": "/", "permissions": 0})
response = self.put("roles/1", {"name": "/", "permissions": 0})
self.expect(response.status_code).to.be.equal_to(403)
response = self.delete("roles/0")
response = self.delete("roles/1")
self.expect(response.status_code).to.be.equal_to(403)
Loading

0 comments on commit 34f5c9b

Please sign in to comment.