-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add get endpoint for cached stamps (#68)
* feat(db-cache): updating readme * feat(api): add get endpoint for cached stamps * fix(api): remove api key * fix(api): remove api key from tests * Switched json parameter type from string to Any * fix(api): remove outdated token test * feat(db_cache): adding admin for ceramic cache * feat(db_cache): fixing test failures + adding code that was lost in merge --------- Co-authored-by: nutrina <nutrina9@gmail.com> Co-authored-by: Lucian Hymer <lucian.hymer@gmail.com>
- Loading branch information
1 parent
237c903
commit 14a4541
Showing
6 changed files
with
125 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
""" | ||
Admin for the ceramic cache app | ||
""" | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import CeramicCache | ||
|
||
|
||
class CeramicCacheAdmin(admin.ModelAdmin): | ||
list_display = ("id", "address", "provider", "deleted_at") | ||
search_fields = ("address", "provider") | ||
|
||
|
||
class AccountAPIKeyAdmin(admin.ModelAdmin): | ||
list_display = ("id", "name", "prefix", "created", "expiry_date", "revoked") | ||
search_fields = ("id", "name", "prefix") | ||
|
||
|
||
admin.site.register(CeramicCache, CeramicCacheAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytest | ||
from django.test import Client | ||
from ceramic_cache.models import CeramicCache | ||
from datetime import datetime | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
client = Client() | ||
|
||
|
||
class TestGetStamp: | ||
def test_succesfully_get_stamp( | ||
self, sample_provider, sample_address, verifiable_credential | ||
): | ||
CeramicCache.objects.create( | ||
address=sample_address, | ||
provider=sample_provider, | ||
stamp=verifiable_credential, | ||
) | ||
|
||
response = client.get( | ||
f"/ceramic-cache/stamp?address={sample_address}", | ||
) | ||
|
||
first_stamp = response.json()["stamps"][0] | ||
|
||
assert response.status_code is 200 | ||
assert first_stamp["address"] == sample_address.lower() | ||
assert first_stamp["provider"] == sample_provider | ||
assert first_stamp["stamp"] == verifiable_credential | ||
|
||
def test_get_stamp_returns_empty_list_if_no_stamps_exist(self, sample_address): | ||
response = client.get( | ||
f"/ceramic-cache/stamp?address={sample_address}", | ||
) | ||
|
||
assert response.status_code is 200 | ||
assert response.json()["stamps"] == [] | ||
|
||
def test_deleted_stamps_are_not_returned( | ||
self, sample_address, sample_provider, verifiable_credential | ||
): | ||
CeramicCache.objects.create( | ||
address=sample_address, | ||
provider=sample_provider, | ||
stamp=verifiable_credential, | ||
) | ||
CeramicCache.objects.create( | ||
address=sample_address, | ||
provider="Google", | ||
stamp=verifiable_credential, | ||
deleted_at=datetime.now(), | ||
) | ||
|
||
response = client.get( | ||
f"/ceramic-cache/stamp?address={sample_address}", | ||
) | ||
|
||
assert response.status_code is 200 | ||
assert len(response.json()["stamps"]) is 1 | ||
assert response.json()["stamps"][0]["provider"] == sample_provider | ||
|
||
def test_get_stamp_returns_422_if_address_is_not_provided(self): | ||
response = client.get( | ||
"/ceramic-cache/stamp", | ||
) | ||
|
||
assert response.status_code == 422 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters