Skip to content

Commit

Permalink
FEAT made test for count endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jessevz committed Dec 3, 2024
1 parent 4982f6c commit 9c3cec5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ci/apiv2/hashtopolis.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,18 @@ def delete(self, obj):
# TODO: Cleanup object to allow re-creation

def count(self, filter):
pass
self.authenticate()
uri = self._api_endpoint + self._model_uri + "/count"
headers = self._headers
payload = {}
if filter:
for k, v in filter.items():
payload[f"filter[{k}]"] = v

logger.debug("Sending GET payload: %s to %s", json.dumps(payload), uri)
r = requests.get(uri, headers=headers, params=payload)
self.validate_status_code(r, [200], "Getting count failed")
return self.resp_to_json(r)['meta']

# Build Django ORM style django.query interface
class QuerySet():
Expand Down Expand Up @@ -437,6 +447,11 @@ def get_first(cls):
@classmethod
def get(cls, **filters):
return QuerySet(cls, filters=filters).get()

@classmethod
def count(cls, **filters):
return cls.get_conn().count(filter=filters)


@classmethod
def paginate(cls, **pages):
Expand Down
23 changes: 23 additions & 0 deletions ci/apiv2/test_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from hashtopolis import HashType
from utils import BaseTest


class CountTest(BaseTest):
model_class = HashType

def create_test_objects(self, **kwargs):
objs = []
for i in range(90000, 90100, 10):
obj = HashType(hashTypeId=i,
description=f"Dummy HashType {i}",
isSalted=(i < 90050),
isSlowHash=False).save()
objs.append(obj)
self.delete_after_test(obj)
return objs

def test_count(self):
model_objs = self.create_test_objects()
model_count = len(model_objs)
api_count = HashType.objects.count(hashTypeId__gte=90000, hashTypeId__lte=91000)['count']
self.assertEqual(model_count, api_count)

0 comments on commit 9c3cec5

Please sign in to comment.