Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Nov 22, 2023
1 parent 99ec0c8 commit 9760640
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions breathecode/authenticate/tests/urls/tests_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,110 @@ def test_task__post__without_user_invite(bc: Breathecode, client: APIClient, val
assert bc.database.list_of('payments.Plan') == []


# """
# 🔽🔽🔽 Post without UserInvite with Asset slug
# """


@patch('django.utils.timezone.now', MagicMock(return_value=now))
def test_task__post__without_user_invite_with_asset_slug(bc: Breathecode, client: APIClient, validation_res):
url = reverse_lazy('authenticate:subscribe')
data = {
'email': 'pokemon@potato.io',
'first_name': 'lord',
'last_name': 'valdomero',
'phone': '+123123123',
'asset_slug': 'pokemon_exercise',
}

access_token = bc.random.string(lower=True, upper=True, number=True, size=40)
with patch('binascii.hexlify', MagicMock(return_value=bytes(access_token, 'utf-8'))):
response = client.post(url, data, format='json')

json = response.json()
expected = post_serializer(data={
'id': 1,
'access_token': access_token,
'user': 1,
**data,
'status': 'ACCEPTED',
})

assert json == expected
assert response.status_code == status.HTTP_201_CREATED
assert bc.database.list_of('authenticate.UserInvite') == [
user_invite_db_item(
data={
'token': hashlib.sha512(('pokemon@potato.io').encode('UTF-8') + b).hexdigest(),
'process_status': 'DONE',
'status': 'ACCEPTED',
'user_id': 1,
'city': None,
'country': None,
'latitude': None,
'longitude': None,
'email_quality': None,
'email_status': None,
**data,
}),
]

assert bc.database.list_of('marketing.Course') == []
assert bc.database.list_of('payments.Plan') == []


# """
# 🔽🔽🔽 Post without UserInvite with Event slug
# """


@patch('django.utils.timezone.now', MagicMock(return_value=now))
def test_task__post__without_user_invite_with_event_slug(bc: Breathecode, client: APIClient, validation_res):
url = reverse_lazy('authenticate:subscribe')
data = {
'email': 'pokemon@potato.io',
'first_name': 'lord',
'last_name': 'valdomero',
'phone': '+123123123',
'event_slug': 'pokemon_event',
}

access_token = bc.random.string(lower=True, upper=True, number=True, size=40)
with patch('binascii.hexlify', MagicMock(return_value=bytes(access_token, 'utf-8'))):
response = client.post(url, data, format='json')

json = response.json()
expected = post_serializer(data={
'id': 1,
'access_token': access_token,
'user': 1,
**data,
'status': 'ACCEPTED',
})

assert json == expected
assert response.status_code == status.HTTP_201_CREATED
assert bc.database.list_of('authenticate.UserInvite') == [
user_invite_db_item(
data={
'token': hashlib.sha512(('pokemon@potato.io').encode('UTF-8') + b).hexdigest(),
'process_status': 'DONE',
'status': 'ACCEPTED',
'user_id': 1,
'city': None,
'country': None,
'latitude': None,
'longitude': None,
'email_quality': None,
'email_status': None,
**data,
}),
]

assert bc.database.list_of('marketing.Course') == []
assert bc.database.list_of('payments.Plan') == []


# """
# 🔽🔽🔽 Post with UserInvite
# """
Expand Down

0 comments on commit 9760640

Please sign in to comment.