Skip to content

Commit

Permalink
feat: Release 7 - 28 December 2022 (#115)
Browse files Browse the repository at this point in the history
* feat: change status page dashboard query and add forget password validation (#114)

* [REFACTOR] update query for status page dashboard

* [FIX] fix change password validation

* [CHORES] add technical documentation and youtube link

* chores: add release notes 7
  • Loading branch information
andrew-susanto authored Dec 28, 2022
1 parent 2264d34 commit e6497c4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ This repository is providing backend service for MonAPI, written in Python and u
- [Run Development Server](https://github.com/MonAPI-xyz/MonAPI/blob/staging/docs/development.md)

## Latest Release Notes
Version: v1.0.0<br>
Date: 12th December 2022
1. Status Page Integration
2. Email register verification
3. Create new category directly when create API Monitor
4. Partial Assertions Text
5. Release 1st version of MonAPI
Version: v1.0.1<br>
Date: 28th December 2022
1. Fix bug password validation on forget password
2. Update pagerduty email configuration title


Full release notes can be found in [Release Notes](https://github.com/MonAPI-xyz/MonAPI/blob/staging/docs/release_notes.md)
Expand All @@ -61,6 +58,11 @@ Full release notes can be found in [Release Notes](https://github.com/MonAPI-xyz

📝 [User Manual - https://docs.monapi.xyz](https://docs.monapi.xyz)

📝 [Technical Documentation - https://docs.monapi.xyz/monapi-tech-documentation/](https://docs.monapi.xyz/monapi-tech-documentation/)

📺 [Youtube - https://www.youtube.com/@monapi](https://www.youtube.com/@monapi)


## Our Teams
- Lucky Susanto
- Ferdi Fadillah
Expand Down
7 changes: 7 additions & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ Date: 12th December 2022
3. Create new category directly when create API Monitor
4. Partial Assertions Text
5. Release 1st version of MonAPI


### Release 7
Version: v1.0.1<br>
Date: 28th December 2022
1. Fix bug password validation on forget password
2. Update pagerduty email configuration title
9 changes: 9 additions & 0 deletions forget_password/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from rest_framework import serializers
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError


class RequestForgetPasswordTokenSerializer(serializers.Serializer):
Expand All @@ -12,3 +14,10 @@ class ForgetPasswordTokenCheckSerializer(serializers.Serializer):
class ResetPasswordSerializer(serializers.Serializer):
password = serializers.CharField(max_length=128)
key = serializers.CharField(max_length=256)

def validate_password(self, password):
try:
validate_password(password)
except ValidationError as exc:
raise exc
return password
27 changes: 21 additions & 6 deletions forget_password/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,47 @@ def test_if_key_not_exists_then_return_error(self):
def test_if_key_exists_but_token_invalid_then_return_error(self):
response = self.client.post(self.test_url, {
'key': 'abc',
'password': 'newpassword',
'password': 'Test123486827',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {'error': 'Invalid token'})

def test_if_key_exists_and_token_valid__and_pasword_same_as_old_then_return_error(self):
user = User.objects.create_user(username='test', email='[email protected]', password='test123')
user = User.objects.create_user(username='test', email='[email protected]', password='Test123486827')
token = ForgetPasswordToken.objects.create(user=user)
response = self.client.post(self.test_url, {
'key': token.key,
'password': 'test123',
'password': 'Test123486827',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {'error': 'Please choose password that different from your current password'})

def test_if_key_exists_token_valid_but_invalid_password_then_return_error(self):
user = User.objects.create_user(username='test', email='[email protected]', password='Test123486827')
token = ForgetPasswordToken.objects.create(user=user)
response = self.client.post(self.test_url, {
'key': token.key,
'password': 'abc',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {"password": [
"This password is too short. It must contain at least 8 characters.",
"This password is too common.",
"The password must contain at least 1 digit, 0-9.",
"The password must contain at least 1 uppercase letter, A-Z."
]})

def test_if_key_exists_and_token_valid_then_return_success(self):
user = User.objects.create_user(username='test', email='[email protected]', password='test123')
user = User.objects.create_user(username='test', email='[email protected]', password='Test123486827')
token = ForgetPasswordToken.objects.create(user=user)
response = self.client.post(self.test_url, {
'key': token.key,
'password': 'newpassword',
'password': 'Test1234868271',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, {'success': True})

user = User.objects.get(email='[email protected]')
self.assertTrue(user.check_password('newpassword'))
self.assertTrue(user.check_password('Test1234868271'))


21 changes: 12 additions & 9 deletions statuspage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def list(self, request):

for category in queryset:
success_rate_category = []
api_monitor_category = APIMonitorResult.objects \
.filter(monitor__status_page_category=category)
api_monitor_result_count = APIMonitorResult.objects \
.filter(monitor__status_page_category=category).count()

if len(api_monitor_category) == 0:
if api_monitor_result_count == 0:
category.success_rate_category = success_rate_category
continue

Expand All @@ -83,12 +83,15 @@ def list(self, request):
end_time = last_24_hour + timedelta(hours=1)

# Average success rate
success_count = api_monitor_category.filter(execution_time__gte=start_time, execution_time__lte=end_time) \
.aggregate(
s=Count('success', filter=Q(success=True)),
f=Count('success', filter=Q(success=False)),
total=Count('pk'),
)
success_count = APIMonitorResult.objects.filter(
monitor__status_page_category=category,
execution_time__gte=start_time,
execution_time__lte=end_time
).aggregate(
s=Count('success', filter=Q(success=True)),
f=Count('success', filter=Q(success=False)),
total=Count('pk'),
)

success_rate_category.append({
"start_time": start_time,
Expand Down

0 comments on commit e6497c4

Please sign in to comment.