Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tddd96-grupp11/teknikattan-scoring-system
1 result
Show changes
Commits on Source (5)
Showing with 589 additions and 133 deletions
__pycache__
*.db
*/env
*.coverage
\ No newline at end of file
*.coverage
.pytest_cache
\ No newline at end of file
stages:
- setup
- test
include:
- local: .gitlab/server.gitlab-ci.yml
image: python
cache:
paths:
- server/env/
before_script:
- python --version
- pip install virtualenv
- cd server/
- python -m venv env
- source env/bin/activate
- pip install -r requirements.txt
test-server:
stage: test
script:
- pytest --cov app tests/
......@@ -5,6 +5,7 @@
"pranaygp.vscode-css-peek",
"dbaeumer.vscode-eslint",
"ms-vsliveshare.vsliveshare",
"cssho.vscode-svgviewer"
"cssho.vscode-svgviewer",
"esbenp.prettier-vscode"
]
}
\ No newline at end of file
{
//editor
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"editor.tabCompletion": "on",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": true
},
//python
"python.venvPath": "${workspaceFolder}\\server",
"python.analysis.extraPaths": ["server"],
"python.terminal.activateEnvironment": true,
......@@ -11,5 +17,18 @@
"--line-length",
"119"
],
"git.ignoreLimitWarning": true
//eslint
"eslint.workingDirectories": ["./client"],
"eslint.options": {
"configFile":"./.eslintrc"
},
//git
"git.ignoreLimitWarning": true,
//language specific
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
\ No newline at end of file
......@@ -29,14 +29,12 @@
"label": "Test Server",
"type": "shell",
"group": "build",
"command": "${workspaceFolder}/server/env/Scripts/python test.py",
"command": "env/Scripts/pytest.exe --cov app tests/",
"problemMatcher": [],
"options": {
"cwd": "${workspaceFolder}/server"
},
"presentation": {
"group": "Client/Server"
}
},
{
"label": "Client + Server",
......
![coverage report](https://gitlab.liu.se/tddd96-grupp11/teknikattan-scoring-system/badges/dev/coverage.svg?job=test-server&key_text=Server+Coverage&key_width=110)
# Scoring system for Teknikåttan
This is the scoring system for Teknikåttan!
......
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"project": ["tsconfig.json"],
"ecmaVersion": 2021,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
}
},
"extends": [
"airbnb-typescript",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"rules": {
"semi":"off",
"react/jsx-one-expression-per-line": "off"
}
}
{
"semi": false,
"trailingComma": "none",
"singleQuote": true,
"printWidth": 80
}
\ No newline at end of file
This diff is collapsed.
......@@ -17,17 +17,27 @@
"axios": "^0.21.1",
"web-vitals": "^1.1.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "4.2.0",
"@typescript-eslint/parser": "4.2.0",
"eslint": "7.19.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^7.2.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-json": "^2.1.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"prettier": "^2.2.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"eject": "react-scripts eject",
"lint": "eslint \"./src/**/*.{js,ts,tsx}\""
},
"browserslist": {
"production": [
......
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
import React from 'react'
import { render, screen } from '@testing-library/react'
import App from './App'
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
render(<App />)
const linkElement = screen.getByText(/learn react/i)
expect(linkElement).toBeInTheDocument()
})
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { useState, useEffect } from "react";
import axios from "axios";
import axios from 'axios'
import React, { useEffect, useState } from 'react'
import './App.css'
import logo from './logo.svg'
interface Message {
message: string;
message: string
}
function App() {
const [currentMessage, setCurrentMessage] = useState<Message>();
const App: React.FC = () => {
const [currentMessage, setCurrentMessage] = useState<Message>()
useEffect(() => {
axios.get<Message>("users/test").then(response=> {
setCurrentMessage(response.data);
});
}, []);
axios.get<Message>('users/test').then((response) => {
setCurrentMessage(response.data)
})
}, [])
return (
<div className="App">
......@@ -34,7 +33,7 @@ function App() {
<p>Current message is {currentMessage?.message}</p>
</header>
</div>
);
)
}
export default App;
export default App
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import './index.css'
import reportWebVitals from './reportWebVitals'
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
)
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
reportWebVitals()
import { ReportHandler } from 'web-vitals';
import { ReportHandler } from 'web-vitals'
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
getCLS(onPerfEntry)
getFID(onPerfEntry)
getFCP(onPerfEntry)
getLCP(onPerfEntry)
getTTFB(onPerfEntry)
})
}
};
}
export default reportWebVitals;
export default reportWebVitals
......@@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import '@testing-library/jest-dom'
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
from app import create_app, db
import unittest
import json
class Test(unittest.TestCase):
def setUp(self):
"""Before each test, set up a blank database"""
self.app = create_app("configmodule.TestingConfig")
self.app.testing = True
self.client = self.app.test_client()
with self.app.app_context():
db.drop_all()
db.create_all()
# Called after every test
def tearDown(self):
with self.app.app_context():
db.session.remove()
db.drop_all()
def test_user(self):
# Create user
rv = self.client.post(
"/api/users/",
data=json.dumps({"email": "test@test.se", "password": "abc123"}),
)
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
assert rv_dict["id"] == 1
assert "password" not in rv_dict
assert rv_dict["email"] == "test@test.se"
# Try loggin with wrong PASSWORD
rv = self.client.post("/api/users/login", data=json.dumps({"email": "test@test.se", "password": "abc1234"}))
assert rv.status_code == 401
# Try loggin with wrong Email
rv = self.client.post("/api/users/login", data=json.dumps({"email": "test1@test.se", "password": "abc1234"}))
assert rv.status_code == 401
# Try loggin with right PASSWORD
rv = self.client.post("/api/users/login", data=json.dumps({"email": "test@test.se", "password": "abc123"}))
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
headers = {"Authorization": "Bearer " + rv_dict["access_token"]}
# Get the current user
rv = self.client.get("/api/users/", headers=headers)
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
assert rv_dict["email"] == "test@test.se"
rv = self.client.put("/api/users/", data=json.dumps({"name": "carl carlsson"}), headers=headers)
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
assert rv_dict["name"] == "Carl Carlsson"
def test_empty(self):
# Try loggin withou any users
rv = self.client.post("/api/users/login", data=json.dumps({"email": "test@test.se", "password": "abc123"}))
assert rv.status_code == 401
if __name__ == "__main__":
unittest.main()
import pytest
from app import create_app, db
@pytest.fixture
def app():
app = create_app("configmodule.TestingConfig")
with app.app_context():
db.drop_all()
db.create_all()
return app
@pytest.fixture
def client(app):
return app.test_client()
from tests import app, client
import json
def test_app(client):
# Create user
rv = client.post(
"/api/users/",
data=json.dumps({"email": "test@test.se", "password": "abc123"}),
)
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
assert rv_dict["id"] == 1
assert "password" not in rv_dict
assert rv_dict["email"] == "test@test.se"
# Try loggin with wrong PASSWORD
rv = client.post("/api/users/login", data=json.dumps({"email": "test@test.se", "password": "abc1234"}))
assert rv.status_code == 401
# Try loggin with wrong Email
rv = client.post("/api/users/login", data=json.dumps({"email": "test1@test.se", "password": "abc1234"}))
assert rv.status_code == 401
# Try loggin with right PASSWORD
rv = client.post("/api/users/login", data=json.dumps({"email": "test@test.se", "password": "abc123"}))
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
headers = {"Authorization": "Bearer " + rv_dict["access_token"]}
# Get the current user
rv = client.get("/api/users/", headers=headers)
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
assert rv_dict["email"] == "test@test.se"
rv = client.put("/api/users/", data=json.dumps({"name": "carl carlsson"}), headers=headers)
rv_dict = json.loads(rv.data.decode())
assert rv.status_code == 200
assert rv_dict["name"] == "Carl Carlsson"