Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
ViaResto-website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aymeric Chaumont
ViaResto-website
Commits
31ba82a6
Commit
31ba82a6
authored
2 years ago
by
Aymeric Chaumont
Browse files
Options
Downloads
Plain Diff
Merge branch 'improve_ci' into 'main'
add test to ci See merge request
!59
parents
4961add0
885347f2
No related branches found
No related tags found
1 merge request
!59
add test to ci
Pipeline
#44580
failed
2 years ago
Stage: install
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+33
-53
33 additions, 53 deletions
.gitlab-ci.yml
backend/test_main.py
+67
-0
67 additions, 0 deletions
backend/test_main.py
with
100 additions
and
53 deletions
.gitlab-ci.yml
+
33
−
53
View file @
31ba82a6
image
:
python:3.9
# variables:
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
# MYSQL_USER: $MYSQL_USER
# MYSQL_PASSWORD: $MYSQL_PASSWORD
# MYSQL_DATABASE: $MYSQL_DATABASE
# services:
# - name: mysql:latest
# command: ["mysqld", "--authentication-policy=mysql_native_password"]
# alias: mysql
services
:
-
name
:
mysql:latest
command
:
[
"
mysqld"
,
"
--authentication-policy=mysql_native_password"
]
alias
:
mysql
# services:
# - name: mysql:latest
# command: ["mysqld", "--authentication-policy=mysql_native_password"]
# alias: mysql
# variables:
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
# Host: mysql
# User: $MYSQL_USER
# Password: $MYSQL_PASSWORD
# Database: $MYSQL_DATABASE
variables
:
MYSQL_DATABASE
:
$MYSQL_DATABASE
MYSQL_ROOT_PASSWORD
:
$MYSQL_ROOT_PASSWORD
MYSQL_USER
:
$MYSQL_USER
MYSQL_PASSWORD
:
$MYSQL_PASSWORD
MYSQL_DATABASE
:
$MYSQL_DATABASE
stages
:
...
...
@@ -73,9 +59,10 @@ lint-back:
before_script
:
-
python3 -m venv venv/
-
source venv/bin/activate
script
:
-
pip install pycodestyle
script
:
-
pycodestyle --config=./backend/setup.cnf ./backend
dependencies
:
[]
lint-front
:
...
...
@@ -88,24 +75,27 @@ lint-front:
-
install-npm-packages
#
test:
#
stage: test
#
variables:
test
-back
:
stage
:
test
variables
:
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
# MYSQL_DATABASE: $MYSQL_DATABASE
# MYSQL_USER: $MYSQL_USER
# MYSQL_PASSWORD: $MYSQL_PASSWORD
# DB_HOST: mysql
# DB_PORT: 3306
# WEB_ROOT: http://localhost:3000
# before_script:
# - source ./venv/bin/activate
# script:
# - cd ./backend
# - docker build -t app ./backend
# - docker run --detach -p 8000:80 app --env-file ./backend/.env
# - curl "http://localhost:8000/api/health"
DB_HOST
:
mysql
DB_PORT
:
3306
WEB_ROOT
:
http://localhost:3000
before_script
:
-
python3 -m venv venv/
-
source ./venv/bin/activate
-
apt-get update && apt-get install libgl1 -y
-
pip install -r ./backend/requirements.txt
-
pip install pytest
script
:
-
cd ./backend
-
pytest
dependencies
:
[]
#######################################################################################################################################
#### ####
...
...
@@ -160,16 +150,6 @@ lint-front:
-
scp -r build/ eatfast@"$DOMAIN":/var/www/eatfast-website/frontend ; fi
# deploy-back-staging:
# extends: .deploy
# rules:
# - if: $CI_COMMIT_BRANCH == $STAGING_BRANCH
# when: always
# variables:
# DOMAIN: nofist.test.viarezo.fr
# PRIVATE_KEY: "$SSH_PRIVATE_KEY_STAGING"
deploy-back-prod
:
extends
:
.deploy
rules
:
...
...
This diff is collapsed.
Click to expand it.
backend/test_main.py
0 → 100644
+
67
−
0
View file @
31ba82a6
from
fastapi.testclient
import
TestClient
from
datetime
import
datetime
,
timedelta
from
sqlalchemy
import
create_engine
from
dotenv
import
load_dotenv
import
pytz
from
db
import
models
from
main
import
app
import
os
client
=
TestClient
(
app
)
load_dotenv
()
user
=
os
.
getenv
(
'
MYSQL_USER
'
)
password
=
os
.
getenv
(
'
MYSQL_PASSWORD
'
)
host
=
os
.
getenv
(
'
DB_HOST
'
)
port
=
os
.
getenv
(
'
DB_PORT
'
)
database
=
os
.
getenv
(
'
MYSQL_DATABASE
'
)
SQLALCHEMY_DATABASE_URL
=
f
"
mysql+pymysql://
{
user
}
:
{
password
}
@
{
host
}
:
{
port
}
/
{
database
}
?charset=utf8
"
engine
=
create_engine
(
SQLALCHEMY_DATABASE_URL
)
models
.
Base
.
metadata
.
create_all
(
bind
=
engine
)
test
=
{
"
restaurant
"
:
{
"
place
"
:
"
restaurant test
"
,
"
day
"
:
datetime
.
now
().
weekday
(),
"
open_time
"
:
datetime
.
now
(
tz
=
pytz
.
timezone
(
"
Europe/Paris
"
)).
strftime
(
"
%H:%M:%S
"
),
"
close_time
"
:
(
datetime
.
now
(
tz
=
pytz
.
timezone
(
"
Europe/Paris
"
))
+
timedelta
(
hours
=
1
)).
strftime
(
"
%H:%M:%S
"
)
},
"
news
"
:
{
"
title
"
:
"
news test
"
,
"
content
"
:
"
content test
"
,
"
end_date
"
:
(
datetime
.
now
(
tz
=
pytz
.
timezone
(
"
Europe/Paris
"
))
+
timedelta
(
hours
=
1
)).
strftime
(
"
%Y-%m-%dT%H:%M:%S
"
),
"
place
"
:
"
restaurant test
"
},
}
def
test_post_opening_hours
():
response
=
client
.
post
(
"
/api/opening_hours
"
,
headers
=
{
"
accept
"
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json
"
},
json
=
test
[
"
restaurant
"
],
)
assert
response
.
status_code
==
200
assert
response
.
json
()[
"
place
"
]
==
test
[
"
restaurant
"
][
"
place
"
]
def
test_get_restaurants
():
response
=
client
.
get
(
"
/api/restaurants
"
)
assert
response
.
status_code
==
200
assert
len
(
response
.
json
())
==
1
assert
response
.
json
()[
0
][
"
name
"
]
==
test
[
"
restaurant
"
][
"
place
"
]
assert
response
.
json
()[
0
][
"
status
"
]
def
test_post_news_not_admin
():
response
=
client
.
post
(
"
/api/news
"
,
headers
=
{
"
Content-Type
"
:
"
application/json
"
,
"
Cookie
"
:
"
connect_id=wrong_cookie
"
},
json
=
test
[
"
news
"
],
)
assert
response
.
status_code
!=
200
assert
response
.
json
()
==
{
"
detail
"
:
"
Invalid cookie
"
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment