Skip to content

Commit

Permalink
feat:restructureing
Browse files Browse the repository at this point in the history
  • Loading branch information
arunavabasucom committed Aug 12, 2023
1 parent b946499 commit a8d263d
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 32 deletions.
Empty file added backend/__tests__/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions backend/__tests__/test_calculateSpectrum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
####Adds higher directory to python modules path.####
import sys
sys.path.append("..")
####Adds higher directory to python modules path.####

from src.main import app # assuming your FastAPI app instance is named 'app'
from fastapi.testclient import TestClient

client = TestClient(app)

def test_calc_spectrum():
payload_data = {
"species": [
{
"molecule": "CO",
"mole_fraction": 0.2
}
],
"mode": "absorbance",
"database": "hitran",
"tgas": 300,
"min_wavenumber_range": 1900,
"max_wavenumber_range": 2300,
"pressure": 1.01325,
"path_length": 11,
"use_simulate_slit": 'true',
"simulate_slit": 5,
"wavelength_units": "1/u.cm",
"path_length_units": "u.km",
"pressure_units": "cds.atm"
}
response = client.post("/calculate-spectrum", json=payload_data)

data = response.json()["data"]
assert response.status_code == 200
assert "x" in data
assert "y" in data
assert "units" in data


18 changes: 18 additions & 0 deletions backend/__tests__/test_downloadSpectrum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from src.main import app
from fastapi.testclient import TestClient

client = TestClient(app)

def test_download_spec():
payload_data = {
# provide your payload data here
}
response = client.post("/download-spectrum", json=payload_data)

assert response.status_code == 200
assert response.headers["content-type"] == "application/octet-stream"

# You can add more assertions for response content, filename, etc.
# For example:
assert "filename" in response.headers
assert response.headers["filename"].endswith(".spec")
28 changes: 0 additions & 28 deletions backend/__tests__/test_main.py

This file was deleted.

2 changes: 2 additions & 0 deletions backend/src/helpers/calculateSpectrum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import radis
import astropy.units as u
from astropy.units import cds
from src.models.payload import Payload

def calculate_spectrum(payload: Payload):
Expand Down
6 changes: 4 additions & 2 deletions backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from src.routes import calculateSpectrum ,downloadSpectrum,downloadTxt

from src.routes import calculateSpectrum ,downloadSpectrum,downloadTxt,root
import astropy.units as u
from astropy.units import cds


# for high resolution
Expand All @@ -15,6 +16,7 @@
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(root.router)
app.include_router(calculateSpectrum.router)
app.include_router(downloadSpectrum.router)
app.include_router(downloadTxt.router)
2 changes: 0 additions & 2 deletions backend/src/models/payload.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import astropy.units as u
from astropy.units import cds
from pydantic import BaseModel
from typing import List, Optional
from src.models.species import Species
Expand Down
1 change: 1 addition & 0 deletions backend/src/routes/calculateSpectrum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import radis
import numpy as np
from fastapi import APIRouter
import astropy.units as u
from src.models.payload import Payload
from src.helpers.calculateSpectrum import calculate_spectrum

Expand Down
7 changes: 7 additions & 0 deletions backend/src/routes/root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import APIRouter

router = APIRouter()

@router.get("/")
async def root_handler():
return {"message": "Hello World"}

0 comments on commit a8d263d

Please sign in to comment.