Skip to content

Commit

Permalink
Merge pull request #1493 from gustavomm19/asset-context
Browse files Browse the repository at this point in the history
Create asset ai context on fetch if it is none
  • Loading branch information
tommygonzaleza authored Nov 7, 2024
2 parents 0c562ff + d40f2eb commit 3248e26
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 @@ -742,9 +742,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 3248e26

Please sign in to comment.