Skip to content

Commit

Permalink
create asset ai context on fetch if it is none
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Nov 7, 2024
1 parent fc664eb commit d40f2eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions breathecode/registry/tests/urls/v1/tests_asset_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def get_serializer(asset_context, data={}):
}


def test_with_no_context(bc: Breathecode, client):
def test_with_no_assets(bc: Breathecode, client):

url = reverse_lazy("registry:asset_context", kwargs={"asset_id": 1})
response = client.get(url)
json = response.json()

assert json == {"detail": "context-not-found", "status_code": 404}
assert json == {"detail": "asset-not-found", "status_code": 404}
assert response.status_code == 404
11 changes: 8 additions & 3 deletions breathecode/registry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,14 @@ def get(self, request, asset_id=None):

asset_context = AssetContext.objects.filter(asset__id=asset_id).first()
if asset_context is None:
raise ValidationException(
f"No context found for asset {asset_id}", status.HTTP_404_NOT_FOUND, slug="context-not-found"
)
asset = Asset.objects.filter(id=asset_id).first()
if asset is None:
raise ValidationException(
f"Asset {asset_id} not found", status.HTTP_404_NOT_FOUND, slug="asset-not-found"
)
asset_context = AssetContext(asset=asset)
asset_context.ai_context = asset.build_ai_context()
asset_context.save()

serializer = AssetContextSerializer(asset_context, many=False)

Expand Down

0 comments on commit d40f2eb

Please sign in to comment.