forked from Brunastephane/MLA-pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
unit_test_analytics_endpoint.py #3
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
Open
harini20
wants to merge
25
commits into
AlexaBrett:main
Choose a base branch
from
harini20:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
36ac5d7
Create test_api.py
harini20 306735b
deploy-analytics.yaml
harini20 0893588
Rename deploy-analytics.yaml to deploy-analytics.yml
harini20 011417f
deploy-activity-tracking.yml
harini20 feff687
Update deploy-analytics.yml
harini20 e7d8c74
Update deploy-analytics.yml
harini20 79b0b89
Update deploy-analytics.yml
harini20 7470e74
Update deploy-analytics.yml
harini20 db3db90
Create deploy-frontend.yml
harini20 14dfcfb
Create deploy-auth.yml
harini20 ec92a20
Update test_api.py
harini20 a9e36b7
Update deploy-activity-tracking.yml
harini20 7e4e5e1
Update deploy-analytics.yml
harini20 2191426
Update deploy-auth.yml
harini20 c281e5b
Update deploy-frontend.yml
harini20 2bf8113
Update test_api.py
harini20 010712e
Update requirements.txt
harini20 e628533
Update deploy-activity-tracking.yml
harini20 c3752a0
Update deploy-analytics.yml
harini20 9d372a3
Update deploy-auth.yml
harini20 c3de602
Update deploy-frontend.yml
harini20 76ebfa9
Update requirements.txt
harini20 9424cb0
Update requirements.txt
harini20 2dcf22a
Update app.py
harini20 87dd65c
Create schema.graphql
harini20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Deploy to AWS ECR | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "activity-tracking/**" | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: | | ||
| echo The PR was merged | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v1 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: eu-west-2 | ||
|
|
||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v1 | ||
|
|
||
| - name: Build, tag, and push image to Amazon ECR (Activity Tracking) | ||
| env: | ||
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| ECR_REPOSITORY: mla-fitnessapp-activity | ||
| IMAGE_TAG: latest | ||
| run: | | ||
| cd activity-tracking | ||
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Deploy to AWS ECR | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "analytics/**" | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: | | ||
| echo The PR was merged | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v1 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: eu-west-2 | ||
|
|
||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v1 | ||
|
|
||
| - name: Build, tag, and push image to Amazon ECR (Analytics) | ||
| env: | ||
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| ECR_REPOSITORY: mla-fitnessapp-analytics | ||
| IMAGE_TAG: latest | ||
| run: | | ||
| cd analytics | ||
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Deploy to AWS ECR | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "authservice/**" | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: | | ||
| echo The PR was merged | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v1 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: eu-west-2 | ||
|
|
||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v1 | ||
|
|
||
| - name: Build, tag, and push image to Amazon ECR (AuthService) | ||
| env: | ||
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| ECR_REPOSITORY: mla-fitnessapp-authservice | ||
| IMAGE_TAG: latest | ||
| run: | | ||
| cd authservice | ||
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Deploy to AWS ECR | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "frontend/**" | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: | | ||
| echo The PR was merged | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v1 | ||
| with: | ||
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: eu-west-2 | ||
|
|
||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v1 | ||
|
|
||
| - name: Build, tag, and push image to Amazon ECR (Frontend) | ||
| env: | ||
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| ECR_REPOSITORY: mla-fitnessapp-fe | ||
| IMAGE_TAG: latest | ||
| run: | | ||
| cd frontend | ||
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| schema { | ||
| query: Query | ||
| } | ||
| type Stats{ | ||
| username: String! | ||
| exercises: [Exercise] | ||
| } | ||
|
|
||
| type Exercise { | ||
| exerciseType: String | ||
| totalDuration: Int | ||
| } | ||
|
|
||
| type StatsResult { | ||
| success: Boolean! | ||
| errors: [String] | ||
| results: [Stats] | ||
| } | ||
|
|
||
| type Query { | ||
| stats: StatsResult | ||
| filteredStats(name: String): StatsResult | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # test_analytics_api.py | ||
| import unittest | ||
| from flask import json | ||
| from app import app | ||
| import mongomock | ||
|
|
||
| class AnalyticsAPITestCase(unittest.TestCase): | ||
| def setUp(self): | ||
| # Create a mongomock client | ||
| self.mock_client = mongomock.MongoClient() | ||
| app.config["MONGO_URI"] = "mongomock://localhost" | ||
|
|
||
| # Patch the application's database client with the mock client | ||
| app.db_client = self.mock_client | ||
|
|
||
| # Continue with setting up a test client for Flask | ||
| self.app = app.test_client() | ||
| #test_client used to simulate requests and test reponse without running server | ||
| self.app.testing = True | ||
|
|
||
| def test_root_endpoint(self): | ||
| response = self.app.get('/') | ||
| self.assertEqual(response.status_code, 200) | ||
| # Assuming the response is JSON with a list of exercises | ||
| data = json.loads(response.data) | ||
| self.assertIsInstance(data, list) # Check if data is a list | ||
|
|
||
| def test_stats_endpoint(self): | ||
| response = self.app.get('/stats') | ||
| self.assertEqual(response.status_code, 200) | ||
| data = json.loads(response.data) | ||
| self.assertTrue('stats' in data) # Check if 'stats' key exists in response | ||
|
|
||
| def test_user_stats_endpoint(self): | ||
| response = self.app.get('/stats/testuser') | ||
| self.assertEqual(response.status_code, 200) | ||
| data = json.loads(response.data) | ||
| self.assertTrue('stats' in data) | ||
|
|
||
| def test_weekly_user_stats(self): | ||
| response = self.app.get('/stats/weekly/?user=testuser&start=2022-01-01&end=2022-01-07') | ||
| self.assertEqual(response.status_code, 200) | ||
| data = json.loads(response.data) | ||
| self.assertTrue('stats' in data) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this sets up the db mock properly - try implementing the way we caught up about!