# test_alias_service.py

python 1 week ago
# test_alias_service.py import unittest from unittest.mock import Mock, patch, MagicMock from alias_service import AliasService import pandas as pd from fastapi.responses import StreamingResponse import io class TestAliasService(unittest.TestCase): def setUp(self): # Mock dependencies self.oracle_service = Mock() self.auth_util = Mock() self.alias_service = AliasService(self.oracle_service, self.auth_util) def test_validate_excel_valid(self): # Test when the Excel sheet has the required columns and no nulls data = { "INTENT": ["Intent1"], "INTENT_CATEGORY_1": ["Category1"], "INTENT_CATEGORY_2": ["Category2"], "INTENT_CATEGORY_3": ["Category3"], "CALLER_TYPE": ["Type1"], "CLIENT_CODE": ["Code1"], "LOB": ["LOB1"], "SYSTEM_GEN_CATEGORY_1": ["SysCat1"], "SYSTEM_GEN_CATEGORY_2": ["SysCat2"], "SYSTEM_GEN_CATEGORY_3": ["SysCat3"] } df = pd.DataFrame(data) result = self.alias_service.validate_excel(df) self.assertTrue(result) def test_validate_excel_missing_columns(self): # Test when the Excel sheet is missing required columns data = {"INTENT": ["Intent1"]} df = pd.DataFrame(data) result = self.alias_service.validate_excel(df) self.assertFalse(result) def test_validate_excel_null_values(self): # Test when the Excel sheet has null values data = { "INTENT": ["Intent1", None], "INTENT_CATEGORY_1": ["Category1", "Category2"], "INTENT_CATEGORY_2": ["Category2", "Category2"], "INTENT_CATEGORY_3": ["Category3", None], "CALLER_TYPE": ["Type1", "Type2"], "CLIENT_CODE": ["Code1", None], "LOB": ["LOB1", "LOB1"], "SYSTEM_GEN_CATEGORY_1": ["SysCat1", "SysCat1"], "SYSTEM_GEN_CATEGORY_2": ["SysCat2", "SysCat2"], "SYSTEM_GEN_CATEGORY_3": ["SysCat3", None] } df = pd.DataFrame(data) result = self.alias_service.validate_excel(df) self.assertFalse(result) @patch('pandas.read_excel') def test_alias_intent_successful(self, mock_read_excel): # Mock data and methods for alias_intent method mock_file = Mock() mock_file.filename = "test.xlsx" mock_file.file.read = MagicMock(return_value=b"mock content") # Simulate valid Excel data mock_df = pd.DataFrame({ "INTENT": ["Intent1"], "INTENT_CATEGORY_1": ["Category1"], "INTENT_CATEGORY_2": ["Category2"], "INTENT_CATEGORY_3": ["Category3"], "CALLER_TYPE": ["Type1"], "CLIENT_CODE": ["Code1"], "LOB": ["LOB1"], "SYSTEM_GEN_CATEGORY_1": ["SysCat1"], "SYSTEM_GEN_CATEGORY_2": ["SysCat2"], "SYSTEM_GEN_CATEGORY_3": ["SysCat3"] }) mock_read_excel.return_value = mock_df self.auth_util.get_user_email.return_value = "test@example.com" # Execute the alias_intent method result = self.alias_service.alias_intent(mock_file, "mock_token") # Assert results and method calls self.assertEqual(result["Status"], "Successfully finished aliasing test.xlsx") self.oracle_service.execute_query.assert_called() # Check if database queries were made def test_get_category_spreadsheet_valid(self): # Test for successful spreadsheet generation self.oracle_service.execute_select_query.return_value = '[{"INTENT": "Intent1", "INTENT_CATEGORY_1": "Category1", "INTENT_CATEGORY_2": "Category2", "INTENT_CATEGORY_3": "Category3", "CALLER_TYPE": "Type1", "CLIENT_CODE": "Code1", "LOB": "LOB1", "SYSTEM_GEN_CATEGORY_1": "SysCat1", "SYSTEM_GEN_CATEGORY_2": "SysCat2", "SYSTEM_GEN_CATEGORY_3": "SysCat3"}]' result = self.alias_service.get_category_spreadsheet("LOB1", "Code1", "intent") self.assertIsInstance(result, StreamingResponse) self.assertIn("attachment; filename=", result.headers["Content-Disposition"]) def test_get_category_spreadsheet_invalid_category_type(self): # Test when an invalid category type is passed result = self.alias_service.get_category_spreadsheet("LOB1", "Code1", "invalid_type") self.assertEqual(result["Status"], "Invalid category type. Must be either intent action or reason")
98
Posted By
Python Script to create AWS beanstalk
#!/usr/bin/python
  
import boto
python aws beanstalk
sandeep sandeep
List all files and folders using python os mo
import os

def list_files_folders(path):
python python-os
kishore_kumar
Get current environment variables in python
import os
env = os.environ

python python-os
kishore_kumar
Get os details using python os
import os
print os.uname()
# Don't use os.system('uname -a'), its j
python python-os
kishore_kumar
Get stats ( lines, words, char count ) of fil
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
kishore_kumar
Use map function in python
def get_double(num):
    return num * 2

python
kishore_kumar
Python sample codes for beginners
print "Welcome to python"
python
gaya38 gaya38
Python program for even number checking
a=input("Enter a value:")
if (a%2==0):
    print "The given number is even numb
python
gaya38 gaya38
Python program for prime number check
a=input("Enter a value:")
k=0
b=(a/2)+1
python
gaya38 gaya38
Pass command line arguments in python
import sys
x=len(sys.argv)
a=[]
python
gaya38 gaya38
Python program for the largest number in an a
a = [1,43,98,5]#Dummy data
for l in range(len(a)-1):
        if (a[l]>a[l+1]):
python
gaya38 gaya38
print list of even numbers within a range
n=100
a=[10,20,30,40,50]
b=[60,70,80,90]
python
gaya38 gaya38
generate fibonacci series in python
n=input("Enter the constraint to print n
m=input("Enter the maximum value to prin
a=0
python
gaya38 gaya38
Generate Random number within the range in py
import random
print random.uniform(10,500)
python
gaya38 gaya38
Shuffle list elements in python
import random;
z = [1,90,4,2]
z = random.shuffle(z)
python
gaya38 gaya38
use python requests to get contents of url (
import requests

req = requests.get("https://httpbin.org/
python python-requests
kishore_kumar
how to iterate or get values in python dictio
sample_dict = { "number": 1, "fruits": [

for key in sample_dict:
python
kishore_kumar
create matrix and multiply using numpy in pyt
import numpy as np

matrix = [[1,2,3], [4,5,6], [7,8,9]]
python numpy
kishore_kumar
generate random numbers matrix with numpy pyt
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
kishore_kumar
Find min , max and mean for numpy arrays
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
kishore_kumar