-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'production' of github.com:zakarm/ft_transcendence into …
…production
- Loading branch information
Showing
74 changed files
with
1,389 additions
and
634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Pylint | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.12"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
cp app/back-end/requirements.txt . | ||
pip install -r requirements.txt | ||
pip install pylint pylint-django | ||
- name: Analysing the code with pylint | ||
run: | | ||
cp app/back-end/.pylintrc . | ||
pylint $(git ls-files '*.py') --rcfile=.pylintrc --django-settings=ft_transcendence.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,83 @@ | ||
dc-up = docker-compose up | ||
dc-upb = docker-compose up --build | ||
dc-down = docker-compose down | ||
dp = docker ps | ||
drm = docker system prune -af | ||
dc-downp = docker-compose down --rmi all --volumes --remove-orphans | ||
# Makefile | ||
# Set default shell | ||
SHELL := /bin/bash | ||
|
||
all: mkdir upb | ||
# Set variables | ||
DOCKER_COMPOSE := docker-compose | ||
DOCKER_COMPOSE_FILE := docker-compose.yml | ||
DOCKER_COMPOSE_FLAGS := --env-file .env | ||
MAJOR ?= 3 | ||
MINOR ?= 8 | ||
PATCH ?= 0 | ||
VERSION := $(MAJOR).$(MINOR).$(PATCH) | ||
DATA_DIR := /Users/${USER}/Desktop/data | ||
|
||
mkdir: | ||
mkdir -p /Users/$(USER)/Desktop/data | ||
# Define colors | ||
GREEN := $(shell tput -Txterm setaf 2) | ||
YELLOW := $(shell tput -Txterm setaf 3) | ||
RESET := $(shell tput -Txterm sgr0) | ||
|
||
rmdir: down | ||
rm -rf /Users/$(USER)/Desktop/data | ||
# Define targets | ||
.PHONY: help build up down restart logs | ||
|
||
up: | ||
$(dc-up) | ||
help: ## Show this help message | ||
@echo "Usage: make [target]" | ||
@echo "" | ||
@echo "Targets:" | ||
@egrep '^(.+)\:\ ##\ (.+)' $(MAKEFILE_LIST) | column -t -c 2 -s ':#' | ||
|
||
upb: | ||
$(dc-upb) | ||
build: ## Build Docker images | ||
@echo "$(GREEN)Building Docker images...$(RESET)" | ||
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) $(DOCKER_COMPOSE_FLAGS) build --no-cache | ||
|
||
down: | ||
$(dc-down) | ||
up: ## Start Docker containers | ||
@echo "$(GREEN)Starting Docker containers...$(RESET)" | ||
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) $(DOCKER_COMPOSE_FLAGS) up -d | ||
|
||
ps: | ||
$(dp) | ||
down: ## Stop and remove Docker containers | ||
@echo "$(YELLOW)Stopping and removing Docker containers...$(RESET)" | ||
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) $(DOCKER_COMPOSE_FLAGS) down | ||
|
||
prune: | ||
$(drm) | ||
restart: down up ## Restart Docker containers | ||
|
||
front-end: | ||
docker-compose up -d front-end | ||
logs: ## View logs from Docker containers | ||
@echo "$(GREEN)Viewing logs from Docker containers...$(RESET)" | ||
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) $(DOCKER_COMPOSE_FLAGS) logs -f | ||
|
||
back-end: | ||
docker-compose up -d back-end | ||
version: ## Show the current version | ||
@echo "$(GREEN)Current version: $(VERSION)$(RESET)" | ||
|
||
data-base: | ||
docker-compose up -d data-base | ||
remove-data-dir: ## Remove the data directory | ||
@echo "$(YELLOW)Removing data directory $(DATA_DIR)...$(RESET)" | ||
rm -rf $(DATA_DIR) | ||
|
||
clean: | ||
$(dc-downp) | ||
create-data-dir: ## Create the data directory | ||
@echo "$(GREEN)Creating data directory $(DATA_DIR)...$(RESET)" | ||
mkdir -p $(DATA_DIR) | ||
|
||
fclean: rmdir prune | ||
remove-volumes: ## Remove Docker volumes | ||
@echo "$(YELLOW)Removing Docker volumes...$(RESET)" | ||
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) $(DOCKER_COMPOSE_FLAGS) down -v | ||
|
||
.PHONY: clean-all | ||
clean-all: down remove-volumes remove-data-dir ## Clean up Docker containers, volumes, and data directory | ||
@echo "$(GREEN)Clean up completed.$(RESET)" | ||
|
||
clean: clean-all ## Remove build artifacts and temporary files | ||
@echo "$(YELLOW)Cleaning up build artifacts and temporary files...$(RESET)" | ||
rm -rf ./app/front-end/node_modules | ||
rm -rf ./app/front-end/.next | ||
rm -rf ./app/back-end/__pycache__ | ||
find . -type f -name '*.pyc' -delete | ||
find . -type d -name '__pycache__' -delete | ||
|
||
.PHONY: update-version | ||
update-version: ## Update the version number | ||
@read -p "Enter new version (MAJOR.MINOR.PATCH): " NEW_VERSION; \ | ||
MAJOR=$$(echo $$NEW_VERSION | cut -d'.' -f1); \ | ||
MINOR=$$(echo $$NEW_VERSION | cut -d'.' -f2); \ | ||
PATCH=$$(echo $$NEW_VERSION | cut -d'.' -f3); \ | ||
sed -i '' "s/MAJOR ?= [0-9]*/MAJOR ?= $$MAJOR/" $(MAKEFILE_LIST); \ | ||
sed -i '' "s/MINOR ?= [0-9]*/MINOR ?= $$MINOR/" $(MAKEFILE_LIST); \ | ||
sed -i '' "s/PATCH ?= [0-9]*/PATCH ?= $$PATCH/" $(MAKEFILE_LIST); \ | ||
echo "$(GREEN)Version updated to $$NEW_VERSION$(RESET)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[MASTER] | ||
load-plugins=pylint_django | ||
django-settings-module=ft_transcendence.settings | ||
|
||
[MESSAGES CONTROL] | ||
disable=missing-docstring, | ||
import-error, | ||
invalid-name, | ||
too-few-public-methods, | ||
abstract-method, | ||
arguments-renamed, | ||
too-many-locals, | ||
too-many-branches, | ||
too-many-statements, | ||
import-outside-toplevel, | ||
arguments-differ, | ||
no-else-return | ||
|
||
[FORMAT] | ||
max-line-length=120 | ||
|
||
[DESIGN] | ||
max-parents=13 | ||
|
||
[TYPECHECK] | ||
ignored-modules=django.contrib.admin | ||
|
||
[REPORTS] | ||
output-format=colorized | ||
reports=no | ||
|
||
[BASIC] | ||
good-names=i,j,k,ex,pk,Run,_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,31 @@ | ||
from django.test import TestCase | ||
from rest_framework.test import APIClient, force_authenticate | ||
from rest_framework.test import APIClient | ||
from rest_framework import status | ||
from .models import User | ||
import requests_mock | ||
from django.test import TestCase, RequestFactory | ||
from .views import GithubLogin | ||
import jwt | ||
from django.test import Client | ||
|
||
class SignInTest(TestCase): | ||
def setUp(self): | ||
self.client = APIClient() | ||
self.user = User.objects.create_user( email='zakariaemrabet48@gmail.com', password='admin') | ||
|
||
def test_login(self): | ||
response = self.client.post('/api/sign-in', {'email': 'zakariaemrabet48@gmail.com', 'password': 'admin'}, format='json') | ||
response = self.client.post('/api/sign-in', | ||
{'email': 'zakariaemrabet48@gmail.com', | ||
'password': 'admin'}, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertIn('tokens', response.data) | ||
self.assertIn('access', response.data['tokens']) | ||
self.assertIn('refresh', response.data['tokens']) | ||
self.assertIn('access', response.data) | ||
self.assertIn('refresh', response.data) | ||
self.assertIn('email', response.data) | ||
self.assertIn('is_2fa_enabled', response.data) | ||
|
||
|
||
class GithubLoginTest(TestCase): | ||
class SignUpTest(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
self.view = GithubLogin.as_view() | ||
self.client = APIClient() | ||
|
||
@requests_mock.Mocker() | ||
def test_github_login(self, m): | ||
m.get('https://api.github.com/user', json={'login': 'zakarm', 'id': 1}) | ||
m.get('https://api.github.com/user/emails', json=[{'email': 'zakariaemrabet1@gmail.com', 'primary': True, 'verified': True}]) | ||
response = self.client.post('/api/github', {'token': 'testtoken'}, format='json') | ||
self.assertEqual(response.status_code, 200) | ||
decoded_jwt = jwt.decode(response.data['access'], options={"verify_signature": False}) | ||
self.assertEqual(decoded_jwt['user_id'], 1) | ||
def test_signup(self): | ||
response = self.client.post('/api/sign-up', | ||
{'email': 'zakariaemrabet48@gmail.com', | ||
'username': 'testuser', | ||
'password': 'admin'}, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertIn('email', response.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
from django.urls import path, include, re_path | ||
from .views import * | ||
""" | ||
Module providing urls utils | ||
""" | ||
from django.urls import path, re_path | ||
from .views import (SignIn2Fa, SignInView, SocialAuthExchangeView, | ||
SocialAuthRedirectView, SignUpView, SignOutView) | ||
|
||
urlpatterns = [ | ||
path("sign-up", SignUpView.as_view(), name="sign-up"), | ||
path("sign-in", SignInView.as_view(), name="sign-in"), | ||
path("sign-out", SignUpView.as_view(), name="sign-out"), | ||
path("sign-out", SignOutView.as_view(), name="sign-out"), | ||
|
||
# re_path(r'^social/(?P<platform>(github|42|google))/auth$', SocialAuthView.as_view(), name='social-auth'), | ||
path('two-fa', SignIn2Fa.as_view(), name="two-fa"), | ||
re_path(r'^social/(?P<platform>(github|42|google))/redirect$', SocialAuthRedirectView.as_view(), name='social-redirect'), | ||
re_path(r'^social/(?P<platform>(github|42|google))/callback$', SocialAuthExchangeView.as_view(), name='social-callback'), | ||
] | ||
re_path(r'^social/(?P<platform>(github|42|google))/redirect$', | ||
SocialAuthRedirectView.as_view(), name='social-redirect'), | ||
re_path(r'^social/(?P<platform>(github|42|google))/callback$', | ||
SocialAuthExchangeView.as_view(), name='social-callback'), | ||
] |
Oops, something went wrong.