Skip to content

Commit

Permalink
Merge pull request #50 from oss-slu/issue48_fix_test_cases
Browse files Browse the repository at this point in the history
Issue48: fix test cases
  • Loading branch information
SiriChandanaGarimella authored Apr 22, 2024
2 parents 601a060 + 6808dd0 commit e469fff
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application
name: Backend testing
on: push
jobs:
pytest:
Expand All @@ -19,9 +16,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install pytest coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -r ./Backend/requirements.txt
- name: Test with pytest
run: |
Expand Down
5 changes: 5 additions & 0 deletions Backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flask
flask-cors
pytest
coverage
python-docx
31 changes: 15 additions & 16 deletions Backend/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,23 @@ def get_data():
@app.route('/find-sections', methods=['POST'])
def find_sections():

#Ensures the additional data sent is properly received.
# Ensures the additional data sent is properly received.
data = request.get_json(force=True)


# Extracting each piece of data from the JSON object
file_path = data['file_path']
search_terms = data['search_terms']
sections = list(map(int, data['sections']))
temp_specify_lines = data['specify_lines']


# Extracting each piece of data from the JSON object using .get()
file_path = data.get('file_path')
search_terms = data.get('search_terms')
sections = data.get('sections')
temp_specify_lines = data.get('specify_lines')
use_total_lines = data.get('use_total_lines', False)
total_lines = data.get('total_lines', 2000)

# Check for missing request data
if not all([file_path, search_terms, sections, temp_specify_lines]):
return jsonify({'error': 'Missing required fields'}), 400

specify_lines = []
num = 0
while num <= len(sections):
specify_lines.append(temp_specify_lines)
num += 1
sections = list(map(int, sections)) # Convert sections to int here after checking for existence
specify_lines = [temp_specify_lines] * len(sections)

# Read the file
with open(file_path, 'r') as f:
Expand Down Expand Up @@ -152,6 +147,10 @@ def save_document_to_bytes(document):

return app

app_instance = None

if __name__ == "__main__":
app = create_app()
app.run(debug=True)
app_instance = create_app()
app_instance.run(debug=True)
else:
app_instance = create_app()
23 changes: 18 additions & 5 deletions Backend/tests/test.py → Backend/tests/app_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import os
import sys
sys.path.insert(0, '/Users/samsam/orca_converter/Backend/src')

import unittest
import json
from API import app

#Get absolute path to the directory containing the script
current_dir = os.path.dirname(os.path.abspath(__file__))

#Get the path for the project directory
project_dir = os.path.join(current_dir, '..', 'src')

#Add file_path directory
file_path = os.path.abspath(os.path.join(current_dir, '..', '..', 'inputs', 'working', 'Styrene-ad1.txt'))

#Add this path to sys.path to allow script to work universally
sys.path.insert(0, project_dir)
#sys.path.insert(0, '/Users/seala/csci4961/esp/Backend/src')


from app import app_instance as app
print(sys.path)


class TestFindSections(unittest.TestCase):
Expand All @@ -23,10 +36,10 @@ def test_missing_fields(self):
def test_valid_request(self):
# Test a valid request
data = {
'file_path': '/Users/samsam/Desktop/EXAMPLE.txt',
'file_path': file_path,
'search_terms': ["CARTESIAN COORDINATES (A.U.)"],
'sections': [1],
'specifyLines': ['LAST 5'],
'specify_lines': 'LAST 5',
'use_total_lines': False,
'lines': 10
}
Expand Down

0 comments on commit e469fff

Please sign in to comment.