Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Oct 2, 2024
1 parent 7317706 commit 9adf18e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions breathecode/provisioning/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ContainerMeBigSerializer(serpy.Serializer):
class GetProvisioningVendorSerializer(serpy.Serializer):
id = serpy.Field()
name = serpy.Field()
workspaces_url = serpy.Field()


class GetProvisioningBillSmallSerializer(serpy.Serializer):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
Test /v1/provisioning/academy/provisioningprofile
"""

import json
import os
from django.urls.base import reverse_lazy
from rest_framework import status

from ..mixins import ProvisioningTestCase


def get_serializer(provisioning_profile, data={}):
return {
"id": provisioning_profile.id,
"vendor": provisioning_profile.vendor,
"academy": {
"id": provisioning_profile.academy.id,
"name": provisioning_profile.academy.name,
"slug": provisioning_profile.academy.slug,
},
**data,
}


class ProvisioningTestSuite(ProvisioningTestCase):

# When: no auth
# Then: should return 401
def test_upload_without_auth(self):

url = reverse_lazy("provisioning:academy_id_provisioning_profile", kwargs={"academy_id": 1})

response = self.client.get(url)
json = response.json()
expected = {"detail": "Authentication credentials were not provided.", "status_code": 401}

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

def test_no_profiles(self):

url = reverse_lazy("provisioning:academy_id_provisioning_profile", kwargs={"academy_id": 1})

model = self.bc.database.create(
user=1,
profile_academy=1,
)
self.client.force_authenticate(model.user)

response = self.client.get(url)
json = response.json()
expected = []

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_provisioning_profiles(self):

url = reverse_lazy("provisioning:academy_id_provisioning_profile", kwargs={"academy_id": 1})

model = self.bc.database.create(
user=1,
profile_academy=1,
provisioning_profile=1,
vendor=1,
)
self.client.force_authenticate(model.user)

response = self.client.get(url)
json = response.json()
expected = [get_serializer(model.provisioning_profile)]

self.assertEqual(json, expected)
self.assertEqual(response.status_code, status.HTTP_200_OK)

0 comments on commit 9adf18e

Please sign in to comment.