Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General testing #46

Merged
merged 222 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
222 commits
Select commit Hold shift + click to select a range
c55360e
amplify pipeline
larasakarya Jun 7, 2023
b41a236
amp pipeline
larasakarya Jun 7, 2023
e7ad840
pipeline
larasakarya Jun 7, 2023
15550d9
i wish the pipeline worked
larasakarya Jun 7, 2023
7bebe7e
aaaaaaaaa
larasakarya Jun 7, 2023
7cacf8b
pipeline
larasakarya Jun 7, 2023
82494ea
Merging dev into translation storage branch to fix amplify pipeline (…
larasakarya Jun 7, 2023
35524e5
ppipeline
larasakarya Jun 7, 2023
89be661
Updated graphql schema to match amplify
kyoncal Jun 7, 2023
51f9fb6
schema fixed
larasakarya Jun 7, 2023
acac5b2
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 7, 2023
ed77e0e
pipeline check
larasakarya Jun 7, 2023
acacbe2
frontend fix
larasakarya Jun 7, 2023
dd4e823
frontend trying fix
larasakarya Jun 7, 2023
b0dfbac
frontend push fix
larasakarya Jun 8, 2023
b17b3a2
unnecessary prints deleted
larasakarya Jun 8, 2023
f27ff94
checking for valid url added here
larasakarya Jun 8, 2023
fde831f
unnecessary comment deleted
larasakarya Jun 8, 2023
6b5e4b9
importing requests
larasakarya Jun 8, 2023
7e130fd
trying to fix the lambda
larasakarya Jun 8, 2023
54c221f
frontend double html issue fix
larasakarya Jun 8, 2023
ba4619f
checking for a fix
larasakarya Jun 8, 2023
53a02ff
adding functionality for the storage of translations
Tezzish Jun 8, 2023
9f589fc
frontend fix
larasakarya Jun 8, 2023
88fb722
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 8, 2023
fb8ca4a
no
larasakarya Jun 8, 2023
7d7e8cf
check
larasakarya Jun 8, 2023
2586829
trying my best
larasakarya Jun 8, 2023
6a6d8af
frontend fix
larasakarya Jun 8, 2023
710d2ba
lambda fix
larasakarya Jun 8, 2023
8f3d786
working environment + new lambda template
athan29 Jun 8, 2023
f030128
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 8, 2023
9a6ca02
redid amplify
larasakarya Jun 8, 2023
f6500b5
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 8, 2023
dafb4ab
quick fix
athan29 Jun 8, 2023
4f4cd51
conflict fixes
larasakarya Jun 8, 2023
80ee679
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 8, 2023
d429019
merge fix
larasakarya Jun 8, 2023
e770cf0
merge fixx
larasakarya Jun 8, 2023
b8d1595
amplify
athan29 Jun 8, 2023
5e622dc
merge fix
larasakarya Jun 8, 2023
e8a01fa
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 8, 2023
242cf1b
merge fix
larasakarya Jun 8, 2023
07ec7e7
deleting unnecessary function
larasakarya Jun 8, 2023
3e6b1ce
amplify?
athan29 Jun 8, 2023
e9c082e
boop
athan29 Jun 8, 2023
f8d2ae2
fix
larasakarya Jun 8, 2023
1df93bb
fix
larasakarya Jun 8, 2023
5b5f18d
fix
larasakarya Jun 8, 2023
ca94623
delete old func
athan29 Jun 8, 2023
252086a
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 8, 2023
83cea12
merge fix
larasakarya Jun 8, 2023
0259b4b
still old function
athan29 Jun 8, 2023
7b19a91
fix
larasakarya Jun 8, 2023
3d01650
bug
athan29 Jun 8, 2023
13973dc
fix
larasakarya Jun 8, 2023
32c04af
fix
larasakarya Jun 8, 2023
6fe9010
fix
larasakarya Jun 8, 2023
d96e855
fix
larasakarya Jun 9, 2023
c51e5a9
new function + cleanup
athan29 Jun 9, 2023
6ec2c33
commit
athan29 Jun 9, 2023
bf0ce23
a
larasakarya Jun 9, 2023
61a33f2
added comment to check
larasakarya Jun 9, 2023
f63ef76
amplify things
athan29 Jun 9, 2023
826eb02
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 9, 2023
05b07a1
lambda library fixed
larasakarya Jun 9, 2023
911ebc3
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 9, 2023
84f2cf9
wrong import removed
larasakarya Jun 9, 2023
c30252e
LHS working (#26)
larasakarya Jun 9, 2023
6d17e75
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 9, 2023
d4418b7
Cloud scape integration (#28)
PabloLacombe Jun 12, 2023
c0108ac
adding translation storages to s3 bucket and dynamoDB
Tezzish Jun 12, 2023
3460fb6
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 13, 2023
2f9dc5f
new lambda added to trigger step function
larasakarya Jun 13, 2023
ce04547
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 13, 2023
c11f003
url fix
larasakarya Jun 13, 2023
3d46336
working lambda
athan29 Jun 13, 2023
eaa951b
working lambda
athan29 Jun 13, 2023
b0af604
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 13, 2023
faab0fb
fixing the lambda to invoke step functions
larasakarya Jun 13, 2023
57ad98e
lambda change, returns html files
athan29 Jun 13, 2023
9dc804a
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 13, 2023
15d15d1
lambda now returns the authors and the title of the blog post as well
larasakarya Jun 13, 2023
9e7541f
lambda fix
larasakarya Jun 13, 2023
60a9b20
lhs lambda done
larasakarya Jun 13, 2023
38214be
re-adding translation storage lambda as it was deleted
Tezzish Jun 13, 2023
f1dd26b
adding script to convert dataset to csv
Tezzish Jun 13, 2023
25fea39
accidental lambda deletion fixed
larasakarya Jun 13, 2023
ac601fb
step function trigger lambda updated according to graohql query
larasakarya Jun 13, 2023
22c3cd6
updated lambda
larasakarya Jun 14, 2023
f0a5843
comments added to lambda
larasakarya Jun 14, 2023
0016cfe
passing new lambda args
athan29 Jun 14, 2023
3c88df5
updated invoker step function lambda to return the result of the step…
larasakarya Jun 14, 2023
c707515
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 14, 2023
e7bee41
step function invoker complete
larasakarya Jun 14, 2023
be5c5f3
frontend needs to be updated, commented out for now
larasakarya Jun 14, 2023
205b524
step func invoker updated
larasakarya Jun 14, 2023
a3c3f13
updated lambda according to query
larasakarya Jun 14, 2023
18a4bd7
steo invoker works fully
larasakarya Jun 14, 2023
1136ed8
updated graphql schema
larasakarya Jun 14, 2023
573e98e
graphwl fixed
larasakarya Jun 14, 2023
dfb1b31
graphwl fixed
larasakarya Jun 14, 2023
d9c05e6
conflicts fixed
larasakarya Jun 14, 2023
e9fe9ca
graphwl fixed
larasakarya Jun 14, 2023
9326f97
revert
larasakarya Jun 14, 2023
e20d516
after amplify pull functions were restored, one lambda had to be upda…
larasakarya Jun 15, 2023
4134cf9
schema updated
larasakarya Jun 15, 2023
23447a7
commented out a query for now
larasakarya Jun 15, 2023
62e5785
mini step function fix
larasakarya Jun 15, 2023
6a3e1f9
missing import added
larasakarya Jun 15, 2023
8e5ed22
fixing amplify
larasakarya Jun 15, 2023
b47da27
adding translation storage lambda to amplify + layer
Tezzish Jun 15, 2023
05523ef
fixing package-lock.json for pipeline
Tezzish Jun 15, 2023
f447584
running npm install to get package.json and package-lock.json to be i…
Tezzish Jun 15, 2023
3c46444
frontend needs to be worked on, commented out for now
larasakarya Jun 15, 2023
ab8ca4d
restored lambdas
larasakarya Jun 16, 2023
49c5cce
setup ready
athan29 Jun 16, 2023
d93a500
Added RHS reconstructin function
PabloLacombe Jun 16, 2023
9670d9e
url string fixed
larasakarya Jun 16, 2023
276f945
newDB table
athan29 Jun 16, 2023
8dece7b
merge conflict resolved
athan29 Jun 16, 2023
3ed503a
Changed logo after client feedback (#30)
PabloLacombe Jun 20, 2023
5951374
Merge pull request #29 from Tezzish/Translation-storage-RHS-Integration
PabloLacombe Jun 20, 2023
d06dc1b
Allow the RatingIds to be autogenerated by appSync (#32)
kyoncal Jun 20, 2023
1c08091
amplify setup complete
larasakarya Jun 20, 2023
39b663d
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 20, 2023
d4a9912
storingTranslation function updated
larasakarya Jun 20, 2023
e0bfb2c
unnecessary comments deleted
larasakarya Jun 20, 2023
2dfded5
trying to fix translation storage function
larasakarya Jun 20, 2023
36855ed
database query fixed for new db
athan29 Jun 20, 2023
b5e1d3c
fully working frontend
athan29 Jun 20, 2023
5d7d9cb
build
athan29 Jun 20, 2023
d2f5624
Added translation support for lists (#33)
PabloLacombe Jun 21, 2023
0953b01
merge fix
larasakarya Jun 21, 2023
558a6e9
merge conflicts fixed
larasakarya Jun 21, 2023
bbd4533
working on frontend
larasakarya Jun 21, 2023
1158e07
frontend fix for visuals
larasakarya Jun 21, 2023
3599c47
frontend final fix complete
larasakarya Jun 21, 2023
8405a4d
trying to fix node pipeline
larasakarya Jun 21, 2023
dff66d6
Added rating, missing id from return
PabloLacombe Jun 21, 2023
9794780
fixing ratings
athan29 Jun 21, 2023
5ef04f2
added id to be returned
larasakarya Jun 21, 2023
f40cf31
Merge branch 'Translation-storage' of github.com:Tezzish/awsome-nlp i…
larasakarya Jun 21, 2023
e6d1d14
Cdk init (#35)
kyoncal Jun 21, 2023
e67256c
trying to fix frontend
larasakarya Jun 21, 2023
7fb20f3
working frontend + backend without ratings
athan29 Jun 21, 2023
4c8f018
Ratings and content display
PabloLacombe Jun 21, 2023
99af348
updated package-lock for pipeline fix
PabloLacombe Jun 21, 2023
9f3c946
Merge branch 'dev' into Translation-storage
PabloLacombe Jun 21, 2023
ac98979
Removed second 'export default App'
PabloLacombe Jun 21, 2023
d215fea
Github pipeline fix 0
PabloLacombe Jun 21, 2023
6356ecb
updated css
PabloLacombe Jun 22, 2023
e64f4da
css visuals and translation functionality successful
PabloLacombe Jun 22, 2023
b49f6e6
schema.graphql fix
athan29 Jun 22, 2023
258f660
css + rating fix frontend
athan29 Jun 22, 2023
bbf903e
removed hardcoding of languages and models
PabloLacombe Jun 22, 2023
eed3410
Pipeline errors and function additions
PabloLacombe Jun 22, 2023
6813805
pipeline typo
PabloLacombe Jun 22, 2023
c26a1b4
returned checkstyle warnings
PabloLacombe Jun 22, 2023
3d0a9b9
Added requirements and tests to functions
PabloLacombe Jun 22, 2023
24291a4
removed json from requiremnts.txt
PabloLacombe Jun 22, 2023
e799284
removed copy and time from requirements.txt
PabloLacombe Jun 22, 2023
03b1e2c
Javascript pipeline
PabloLacombe Jun 22, 2023
d018981
Initial translationStorage tests
PabloLacombe Jun 22, 2023
e8c32f8
test revert
PabloLacombe Jun 22, 2023
ad8c6dc
fixing python pipeline
athan29 Jun 22, 2023
e8e08ff
conflicts
athan29 Jun 22, 2023
8fd2d98
python pipeline...again
athan29 Jun 22, 2023
fe85cdf
pytests pipeline
athan29 Jun 22, 2023
5173cbe
reformated pipelines & reset src\aws_exports.js
PabloLacombe Jun 22, 2023
22d428f
Merge remote-tracking branch 'origin/Translation-storage' into Transl…
PabloLacombe Jun 22, 2023
c917b42
removed print satements
athan29 Jun 22, 2023
f59e4ff
Pipeline name
PabloLacombe Jun 22, 2023
a573d74
removed print satements v2
athan29 Jun 22, 2023
473b0dc
Merge branch 'Translation-storage' of https://github.com/Tezzish/awso…
athan29 Jun 22, 2023
151b01a
fixed bucket name
athan29 Jun 22, 2023
1365c3e
Merge pull request #36 from Tezzish/Translation-storage
athan29 Jun 22, 2023
e9034d4
Frontend documentation (#34)
PabloLacombe Jun 23, 2023
8719014
testing
larasakarya Jun 23, 2023
3f9ca62
check done
larasakarya Jun 23, 2023
d5c327e
adding frontend tess
larasakarya Jun 24, 2023
dbd6b88
trying to make testing work
larasakarya Jun 24, 2023
1d2c008
trying to make testing work
larasakarya Jun 24, 2023
51acb89
Code cleanup and documentation (#38)
kyoncal Jun 24, 2023
ac53eab
trying to fix frontend
larasakarya Jun 24, 2023
8a0c095
getBlogContent testing
athan29 Jun 24, 2023
c7e1206
pipeline fix
athan29 Jun 24, 2023
6c32e56
test_replace_text_with_translation
PabloLacombe Jun 24, 2023
ecf8a44
frontend test
larasakarya Jun 25, 2023
c67efa3
testing checkingUrl, stepFunctionInvoker
athan29 Jun 25, 2023
fc531bc
frontend testing finalized
larasakarya Jun 25, 2023
98ca74e
Merge branch 'GeneralTesting' of github.com:Tezzish/awsome-nlp into G…
larasakarya Jun 25, 2023
d70510c
Merge branch 'GeneralTesting' of https://github.com/Tezzish/awsome-nl…
athan29 Jun 25, 2023
8f74568
pipeline change
athan29 Jun 25, 2023
44f750f
pipeline python
athan29 Jun 25, 2023
7190405
pipeline python
athan29 Jun 25, 2023
ac6feac
pipeline python
athan29 Jun 25, 2023
464fb13
small test changes
athan29 Jun 25, 2023
23e0f98
pipeline
athan29 Jun 25, 2023
98613d8
Merge branch 'dev' into GeneralTesting
PabloLacombe Jun 25, 2023
d099a53
pipeline
athan29 Jun 25, 2023
42c27b4
Merge remote-tracking branch 'origin/GeneralTesting' into GeneralTesting
PabloLacombe Jun 25, 2023
2fafac6
pipeline
athan29 Jun 25, 2023
c732d74
Merge branch 'GeneralTesting' of https://github.com/Tezzish/awsome-nl…
athan29 Jun 25, 2023
4dd7c96
frontend back
larasakarya Jun 25, 2023
2d55a23
frontend back
larasakarya Jun 25, 2023
afaa002
frontend back
larasakarya Jun 25, 2023
b4b794c
frontend back
larasakarya Jun 25, 2023
96ab5a5
pip
athan29 Jun 25, 2023
1dd3f9b
pip
athan29 Jun 25, 2023
557da0a
frontend back
larasakarya Jun 25, 2023
ae951e2
Merge branch 'GeneralTesting' of github.com:Tezzish/awsome-nlp into G…
larasakarya Jun 25, 2023
bdabf51
frontend back
larasakarya Jun 25, 2023
b91ac73
asfsa
athan29 Jun 25, 2023
c6342c1
checking url tests are fixed
larasakarya Jun 26, 2023
8a32c30
stepfunction invoker tests are fixed
larasakarya Jun 26, 2023
a3af770
tests fixed
larasakarya Jun 26, 2023
a409c1c
Co-authored-by: Athanasios Christopoulos <athan29@users.noreply.githu…
larasakarya Jun 26, 2023
68c284b
Merge branch 'GeneralTesting' of github.com:Tezzish/awsome-nlp into G…
larasakarya Jun 26, 2023
8634252
tests fixed
larasakarya Jun 26, 2023
1a2c42f
testing working
athan29 Jun 26, 2023
d1ef61a
Merge branch 'main' of https://github.com/Tezzish/awsome-nlp into Gen…
athan29 Jun 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
node-version: [ 16.x]
directory: ['./amplify/backend/function/checkingUrl/']
directory: [ './src/', './amplify/backend/function/checkingUrl/']

steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,28 @@ jobs:
working-directory: ${{ matrix.directory }}
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8 pytest botocore boto3

if [ -f Requirements.txt ]; then pip install -r Requirements.txt; fi

- name: Set AWS region
run: |
echo "AWS_DEFAULT_REGION=eu-west-1" >> $GITHUB_ENV

- name: Lint with flake8
working-directory: ${{ matrix.directory }}
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Test with pytest
if: matrix.directory != './amplify/backend/function/getBlogContent/'
working-directory: ${{ matrix.directory }}
run: |
pytest

- name: Test with unittest
if: matrix.directory == './amplify/backend/function/getBlogContent/'
working-directory: ${{ matrix.directory }}
run: |
python -m unittest discover -s tests
141 changes: 137 additions & 4 deletions amplify/backend/function/checkingUrl/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,139 @@
const AWS = require('aws-sdk');
const lambda = require('../index.js');

jest.mock('aws-sdk');

// Test that 1 = 1
test('1 = 1', () => {
expect(1).toBe(1);
})
describe('Lambda Function', () => {
let docClientGetSpy;
let s3GetObjectMock;

beforeEach(() => {
docClientGetSpy = jest.spyOn(AWS.DynamoDB.DocumentClient.prototype, 'get').mockImplementation(() => ({
promise: jest.fn().mockResolvedValue({}),
}));

s3GetObjectMock = jest.fn().mockImplementation(() => ({
promise: jest.fn().mockResolvedValue({
Body: Buffer.from('Mocked S3 response', 'utf-8'),
}),
}));

AWS.S3.prototype.getObject = s3GetObjectMock;
});

afterEach(() => {
jest.restoreAllMocks();
});

it('should return expected response when data is not found in DynamoDB', async () => {
const event = {
url: 'example.com',
targetLanguage: { code: 'en' },
translationModel: { type: 'type' },
};
const expectedResponse = {
urlPresent: false,
url: 'example.com',
targetLanguage: { code: 'en' },
sourceLanguage: undefined,
translationModel: { type: 'type' },
};

docClientGetSpy.mockImplementation(() => ({
promise: jest.fn().mockResolvedValue({}),
}));

const response = await lambda.handler(event, {});

expect(response).toEqual(expectedResponse);
expect(docClientGetSpy).toHaveBeenCalledTimes(1);
expect(docClientGetSpy).toHaveBeenCalledWith({
TableName: process.env.TRANSLATION_TABLE_NAME,
Key: { URL: 'example.com[translated]-en-type' },
});
});

it('should return expected response when data is found in DynamoDB', async () => {
const event = {
url: 'example.com',
targetLanguage: { code: 'en' },
sourceLanguage: { code: 'fr' },
translationModel: { type: 'type' },
};
const data = {
Item: {
URL: 'example.com[translated]-en-type',
LHS_s3_loc: 'https://s3.amazonaws.com/bucket/lhs-key',
RHS_s3_loc: 'https://s3.amazonaws.com/bucket/rhs-key',
},
};
const lhsResponse = {
Body: Buffer.from('LHS content', 'utf-8'),
};
const rhsResponse = {
Body: Buffer.from('RHS content', 'utf-8'),
};
const expectedResponse = {
statusCode: 200,
urlPresent: true,
body: { lhs: 'LHS content', rhs: 'RHS content', id: 'example.com[translated]-en-type' },
};

docClientGetSpy.mockImplementation(() => ({
promise: jest.fn().mockResolvedValue(data),
}));
s3GetObjectMock.mockImplementation((params) => ({
promise: jest.fn().mockResolvedValue({
Body: params.Key === 'lhs-key' ? lhsResponse.Body : rhsResponse.Body,
}),
}));

const response = await lambda.handler(event, {});

expect(response).toEqual(expectedResponse);
expect(docClientGetSpy).toHaveBeenCalledTimes(1);
expect(docClientGetSpy).toHaveBeenCalledWith({
TableName: process.env.TRANSLATION_TABLE_NAME,
Key: { URL: 'example.com[translated]-en-type' },
});
expect(s3GetObjectMock).toHaveBeenCalledTimes(2);
expect(s3GetObjectMock).toHaveBeenCalledWith({ Bucket: 'bucket', Key: 'lhs-key' });
expect(s3GetObjectMock).toHaveBeenCalledWith({ Bucket: 'bucket', Key: 'rhs-key' });
});

it('should return error response when S3 getObject throws an error', async () => {
const event = {
url: 'example.com',
targetLanguage: { code: 'en' },
sourceLanguage: { code: 'fr' },
translationModel: { type: 'type' },
};
const data = {
Item: {
URL: 'example.com[translated]-en-type',
LHS_s3_loc: 'https://s3.amazonaws.com/bucket/lhs-key',
RHS_s3_loc: 'https://s3.amazonaws.com/bucket/rhs-key',
},
};
const expectedError = new Error('S3 getObject error');

docClientGetSpy.mockImplementation(() => ({
promise: jest.fn().mockResolvedValue(data),
}));
s3GetObjectMock.mockImplementation(() => ({
promise: jest.fn().mockRejectedValue(expectedError),
}));

const response = await lambda.handler(event, {});

expect(response.statusCode).toBe(500);
expect(response.body).toEqual(JSON.stringify({ error: expectedError.message }));
expect(docClientGetSpy).toHaveBeenCalledTimes(1);
expect(docClientGetSpy).toHaveBeenCalledWith({
TableName: process.env.TRANSLATION_TABLE_NAME,
Key: { URL: 'example.com[translated]-en-type' },
});
expect(s3GetObjectMock).toHaveBeenCalledTimes(1);
expect(s3GetObjectMock).toHaveBeenCalledWith({ Bucket: 'bucket', Key: 'lhs-key' });
});
});
Binary file not shown.
Binary file not shown.
5 changes: 0 additions & 5 deletions amplify/backend/function/getBlogContent/test/test_module.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
74 changes: 74 additions & 0 deletions amplify/backend/function/getBlogContent/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import unittest
from unittest.mock import patch, MagicMock
import sys
import os


# Navigate to the parent directory
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# Add the 'src' directory to sys.path
src_dir = os.path.join(parent_dir, 'src')
sys.path.append(src_dir)
import app

class TestHandler(unittest.TestCase):

@patch('app.urlopen')
def test_handler(self, mock_urlopen):
mock_response = MagicMock()
mock_response.status = 200 # mock a successful response
mock_response.read.return_value = '<div class="aws-blog-content">Content</div>' # Mock the HTML content
mock_urlopen.return_value = mock_response
event = {'url': 'https://aws.amazon.com/blogs/training-and-certification/5-tips-for-a-successful-online-proctored-aws-certification-exam/'}
context = {}

result = app.handler(event, context)

# assertions will depend on the expected output of your function
self.assertEqual(result['statusCode'], 200)


class TestGetTitle(unittest.TestCase):

@patch('app.urlopen')
def test_get_title(self, mock_urlopen):
# mock the response from urlopen
mock_response = MagicMock()
mock_response.read.return_value = b'<h1 class="lb-h2 blog-post-title" property="name headline">Accelerate time to business insights with the Amazon SageMaker Data Wrangler direct connection to Snowflake</h1>'
mock_urlopen.return_value = mock_response

title = app.getTitle('https://aws.amazon.com/blogs/machine-learning/accelerate-time-to-business-insights-with-the-amazon-sagemaker-data-wrangler-direct-connection-to-snowflake/')

self.assertEqual(title, 'Accelerate time to business insights with the Amazon SageMaker Data Wrangler direct connection to Snowflake')


class TestGetAuthorNames(unittest.TestCase):

@patch('app.urlopen')
def test_get_author_names(self, mock_urlopen):
# mock the response from urlopen
mock_response = MagicMock()
mock_response.read.return_value = b'<span property="author" typeof="Person"><span property="name">Tingyi Li</span></span> " and " <span property="author" typeof="Person"><span property="name">Demir Catovic</span></span>'
mock_urlopen.return_value = mock_response

author_names = app.getAuthorNames('https://aws.amazon.com/blogs/machine-learning/deploy-a-serverless-ml-inference-endpoint-of-large-language-models-using-fastapi-aws-lambda-and-aws-cdk/')

self.assertEqual(author_names, ['Tingyi Li', 'Demir Catovic'])


class TestParser(unittest.TestCase):

@patch('app.urlopen')
def test_parser(self, mock_urlopen):
# mock the response from urlopen
mock_response = MagicMock()
mock_response.read.return_value = b'<div class="aws-blog-content">Content</div>'
mock_urlopen.return_value = mock_response

content = app.parser('https://aws.amazon.com/blogs/training-and-certification/5-tips-for-a-successful-online-proctored-aws-certification-exam/')
self.assertEqual(content, '<div class="aws-blog-content">\n Content\n</div>\n')


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Binary file not shown.
123 changes: 120 additions & 3 deletions amplify/backend/function/stepFunctionInvoker/test/test_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,122 @@
import pytest
import json
from unittest import TestCase, mock
import os
import sys

# Navigate to the parent directory
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

def test_init():
assert pytest.approx(1.0) == 1.00000001
# Add the 'src' directory to sys.path
src_dir = os.path.join(parent_dir, 'src')
sys.path.append(src_dir)

from index import handler


class TestLambdaHandler(TestCase):
@classmethod
def setUpClass(cls):
cls.event = {
'arguments': {
'input': {
'url': 'https://example.com',
'targetLanguage': 'es',
'sourceLanguage': 'en',
'translationModel': 'custom'
}
}
}

@mock.patch('index.client')
def test_handler_successful_execution(self, mock_client):
# Mocking start_execution response
execution_arn = os.getenv('STEP_FUNCTION_ARN'),
mock_client.start_execution.return_value = {'executionArn': execution_arn}

# Mocking describe_execution response during SUCCEEDED status
mock_client.describe_execution.return_value = {
'status': 'SUCCEEDED',
'output': json.dumps({
'body': {
'id': '123',
'lhs': 'left',
'rhs': 'right'
}
})
}

expected_result = {
'id': '123',
'lhs': 'left',
'rhs': 'right'
}

# Call the handler function
result = handler(self.event, None)

# Assertions
mock_client.start_execution.assert_called_once_with(
stateMachineArn= os.getenv('STEP_FUNCTION_ARN'),
input=json.dumps({
'url': self.event['arguments']['input']['url'],
'targetLanguage': self.event['arguments']['input']['targetLanguage'],
'sourceLanguage': self.event['arguments']['input']['sourceLanguage'],
'translationModel': self.event['arguments']['input']['translationModel']
})
)
mock_client.describe_execution.assert_called_once_with(executionArn=execution_arn)
self.assertEqual(result, expected_result)

@mock.patch('index.client')
def test_handler_failed_execution(self, mock_client):
# Mocking start_execution response
execution_arn = os.getenv('STEP_FUNCTION_ARN'),
mock_client.start_execution.return_value = {'executionArn': execution_arn}

# Mocking describe_execution response during FAILED status
mock_client.describe_execution.return_value = {'status': 'FAILED'}

# Call the handler function
result = handler(self.event, None)

# Assertions
mock_client.start_execution.assert_called_once_with(
stateMachineArn= os.getenv('STEP_FUNCTION_ARN'),
input=json.dumps({
'url': self.event['arguments']['input']['url'],
'targetLanguage': self.event['arguments']['input']['targetLanguage'],
'sourceLanguage': self.event['arguments']['input']['sourceLanguage'],
'translationModel': self.event['arguments']['input']['translationModel']
})
)
mock_client.describe_execution.assert_called_once_with(executionArn=execution_arn)
self.assertEqual(result, {'statusCode': 500, 'body': "'body'"})

@mock.patch('index.client')
def test_handler_client_error(self, mock_client):
# Mocking start_execution response without raising an error
mock_client.start_execution.return_value = {'executionArn': 'mock-execution-arn'}

# Mocking describe_execution response to indicate execution is still in progress
mock_client.describe_execution.side_effect = [
{'status': 'RUNNING'}, # First call returns running status
{'status': 'SUCCEEDED'} # Second call returns succeeded status
]

# Call the handler function
result = handler(self.event, None)

# Assertions
mock_client.start_execution.assert_called_once_with(
stateMachineArn=os.getenv('STEP_FUNCTION_ARN'),
input=json.dumps({
'url': self.event['arguments']['input']['url'],
'targetLanguage': self.event['arguments']['input']['targetLanguage'],
'sourceLanguage': self.event['arguments']['input']['sourceLanguage'],
'translationModel': self.event['arguments']['input']['translationModel']
})
)
mock_client.describe_execution.assert_called_with(
executionArn='mock-execution-arn'
)
self.assertEqual(result, {'statusCode': 500, 'body': "'body'"})
Loading