Skip to content

Commit

Permalink
🚿
Browse files Browse the repository at this point in the history
  • Loading branch information
siriscmv committed Nov 1, 2024
1 parent f5e52b3 commit 0f1fcd2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [project2]

jobs:
check:
format:
runs-on: ubuntu-latest

steps:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ jobs:
- name: Analyzing the code with pylint
run: |
pylint $(git ls-files '*.py')
pylint $(git ls-files '*.py') > pylint_output.txt || true
score=$(tail -n 1 pylint_output.txt | awk '{print $2}') # Get the Pylint score
echo "::set-output name=score::$score" # Set the score as output
- name: Save Pylint score to file
run: echo "Pylint Score: ${{ steps.pylint.outputs.score }}" > pylint_score.txt

29 changes: 20 additions & 9 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Pytest CI

on:
Expand All @@ -10,27 +7,41 @@ on:
branches: [project2]

jobs:
build:
test:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:5.0
ports:
- 27017:27017
env:
MONGO_INITDB_DATABASE: mydatabase
options: >-
--health-cmd "mongo --eval 'db.runCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.13
uses: actions/setup-python@v2
with:
python-version: 3.13

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -r ./backend/requirements.txt
- name: Set environment variable for MongoDB
run: echo "MONGODB_HOST_STRING=mongodb://localhost:27017/mydatabase" >> $GITHUB_ENV

- name: Test with pytest, upload to codecov
run: |
cd ./backend
echo 'Created application.yml'
pwd
pytest --cov-report xml:cov.xml --cov=./ ./
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
25 changes: 17 additions & 8 deletions backend/test_app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
Test module for the backend
"""

import hashlib
from io import BytesIO

import pytest
import json
import os
import datetime
from flask_mongoengine import MongoEngine
import yaml
Expand All @@ -26,14 +28,12 @@ def client():
:return: client fixture
"""
app = create_app()
with open("application.yml") as f:
info = yaml.load(f, Loader=yaml.FullLoader)
username = info["username"]
password = info["password"]
app.config["MONGODB_SETTINGS"] = {
"db": "appTracker",
"host": f"mongodb+srv://{username}:{password}@applicationtracker.287am.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
}

app.config["MONGODB_SETTINGS"] = {
"db": "appTracker",
"host": os.getenv("MONGODB_HOST_STRING"),
}

db = MongoEngine()
db.disconnect()
db.init_app(app)
Expand Down Expand Up @@ -86,60 +86,69 @@ def test_search(client):
jdata = json.loads(rv.data.decode("utf-8"))["label"]
assert jdata == "successful test search"


def test_search_with_keywords(client):
"""Test the search endpoint with keywords only."""
rv = client.get("/search?keywords=developer")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list) # Expecting a list of job postings
assert len(jdata) >= 0 # Assuming there could be 0 or more job postings


def test_search_with_location(client):
"""Test the search endpoint with keywords and location."""
rv = client.get("/search?keywords=developer&location=New York")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list)
assert len(jdata) >= 0 # Check if you receive results


def test_search_with_job_type(client):
"""Test the search endpoint with keywords and job type."""
rv = client.get("/search?keywords=developer&jobType=full-time")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list)
assert len(jdata) >= 0


def test_search_with_location_and_job_type(client):
"""Test the search endpoint with keywords, location, and job type."""
rv = client.get("/search?keywords=developer&location=New York&jobType=part-time")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list)
assert len(jdata) >= 0


def test_search_with_invalid_parameters(client):
"""Test the search endpoint with invalid parameters."""
rv = client.get("/search?keywords=&location=&jobType=")
jdata = json.loads(rv.data.decode("utf-8"))
assert jdata["label"] == "successful test search" # Default case check


def test_search_with_special_characters(client):
"""Test the search endpoint with special characters in keywords."""
rv = client.get("/search?keywords=developer@#$%^&*()")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list)


def test_search_no_results(client):
"""Test the search endpoint with unlikely keywords."""
rv = client.get("/search?keywords=nonexistentjob&location=Nowhere")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list) # Should still return a list
assert len(jdata) == 0 # Assuming no results were found


def test_search_long_strings(client):
"""Test the search endpoint with excessively long strings."""
long_keyword = "a" * 500 # 500 characters long
rv = client.get(f"/search?keywords={long_keyword}")
jdata = json.loads(rv.data.decode("utf-8"))
assert isinstance(jdata, list)


# 3. testing if the application is getting data from database properly
def test_get_data(client, user):
"""
Expand Down

0 comments on commit 0f1fcd2

Please sign in to comment.