Skip to content

Commit

Permalink
updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
freelancing-solutions committed Sep 19, 2021
1 parent 502c902 commit d8056a7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
9 changes: 6 additions & 3 deletions tests/test_views/test_affiliate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pytest_mock import mocker
from datetime import datetime
from random import randint, choice
from typing import List
from typing import List, Generator
from google.cloud import ndb
from config.exceptions import status_codes, InputError, UnAuthenticatedError, DataServiceError
from config.use_context import get_client
Expand All @@ -29,7 +29,6 @@

class AffiliateQueryMock:
affiliates_instance: Affiliates = Affiliates()
results_range: int = randint(0, 100)

def __init__(self):
self.affiliates_instance.affiliate_id = affiliate_data_mock.get('affiliate_id')
Expand All @@ -53,8 +52,12 @@ def rand_affiliate() -> Affiliates:
total_recruits=randint(10, 1000), is_active=bool(randint(0, 1)),
is_deleted=bool(randint(0, 1)))

def fetch_generator(self) -> Generator:
_results_range: int = randint(0, 100)
return (self.rand_affiliate() for _ in range(_results_range))

def fetch(self) -> List[Affiliates]:
return [self.rand_affiliate() for _ in range(self.results_range)]
return [affiliate for affiliate in self.fetch_generator()]

def get(self) -> Affiliates:
return self.affiliates_instance
Expand Down
9 changes: 6 additions & 3 deletions tests/test_views/test_api_keys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from random import choice, randint
from typing import List, Optional
from typing import List, Optional, Generator

from google.cloud import ndb
from pytest import raises
Expand All @@ -19,7 +19,6 @@

class APIKeysQueryMock:
api_key_instance: APIKeys = APIKeys()
results_range: int = randint(10, 1000)

def __init__(self):
self.api_key_instance.organization_id = config_instance.ORGANIZATION_ID
Expand All @@ -44,8 +43,12 @@ def rand_api_key() -> APIKeys:
domain='https://example.com',
is_active=choice([True, False]))

def fetch_generator(self) -> Generator:
_results_range: int = randint(10, 1000)
return (self.rand_api_key() for _ in range(_results_range))

def fetch(self) -> List[APIKeys]:
return [self.rand_api_key() for _ in range(self.results_range)]
return [api_key for api_key in self.fetch_generator()]

def get(self) -> APIKeys:
return self.api_key_instance
Expand Down
3 changes: 1 addition & 2 deletions tests/test_views/test_helpdesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class HelpDeskQueryMock:
helpdesk_instance: HelpDesk = HelpDesk()
results_range: int = randint(10, 1000)

def __init__(self) -> None:
self.helpdesk_instance.help_desk_active = True
Expand All @@ -34,5 +33,5 @@ def get(self) -> HelpDesk:
return self.helpdesk_instance

def fetch(self) -> List[HelpDesk]:
return [self.helpdesk_instance for _ in range(self.results_range)]
return [self.helpdesk_instance]

10 changes: 7 additions & 3 deletions tests/test_views/test_memberships_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing import Optional, List
from typing import Optional, List, Generator
from datetime import datetime, timedelta, date
from random import randint
from google.cloud import ndb
Expand All @@ -22,7 +22,6 @@

class MembershipsQueryMock:
membership_instance: Memberships = Memberships()
results_range: int = randint(0, 100)

def __init__(self) -> None:
self.membership_instance.plan_id = create_id()
Expand All @@ -46,8 +45,12 @@ def rand_membership() -> Memberships:
plan_start_date=today(), payment_method='paypal',
is_active_subscription=random.choice([True, False]))

def fetch_generator(self) -> Generator:
_results_range: int = randint(10, 1000)
return (self.rand_membership() for _ in range(_results_range))

def fetch(self) -> List[Memberships]:
return [self.rand_membership() for _ in range(self.results_range)]
return [membership for membership in self.fetch_generator()]

def get(self) -> Memberships:
return self.membership_instance
Expand Down Expand Up @@ -76,6 +79,7 @@ def __init__(self):
self.membership_plan_instance.registration_amount = AmountMixin(
amount_cents=10000, currency=random.choice(currency_util.currency_symbols()))

# TODO add fetch_generator
def fetch(self) -> List[MembershipPlans]:
return [self.membership_plan_instance for _ in range(self.results_range)]

Expand Down
9 changes: 6 additions & 3 deletions tests/test_views/test_organizations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from random import choice, randint
from typing import List, Optional
from typing import List, Optional, Generator

import pytest
from google.cloud import ndb
Expand All @@ -18,7 +18,6 @@

class OrganizationQueryMock:
organization_instance: Organization = Organization()
results_range: int = randint(10, 1000)

def __init__(self):
self.organization_instance.organization_id = create_id()
Expand Down Expand Up @@ -54,12 +53,16 @@ def rand_organization() -> Organization:
recovery_callback_url='https://memberships-affiliates-api.heroku.com/recovery'
)

def fetch_generator(self) -> Generator:
_results_range: int = randint(10, 1000)
return (self.rand_organization() for _ in range(_results_range))

def fetch(self) -> List[Organization]:
"""
:param self:
:return:
"""
return [self.rand_organization() for _ in range(self.results_range)]
return [organization for organization in self.fetch_generator()]

def get(self) -> Organization:
return self.organization_instance
Expand Down
8 changes: 6 additions & 2 deletions tests/test_views/test_users.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from random import choice, randint, choices
from string import ascii_lowercase
from string import digits as digits_characters
from typing import List, Optional
from typing import List, Optional, Generator

from google.cloud import ndb
from pytest import raises
Expand Down Expand Up @@ -49,13 +49,17 @@ def rand_user() -> UserModel:
is_active=choice([True, False]), time_registered=timestamp(), is_admin=choice([True, False]),
is_support=choice([True, False]), last_login_date=today())

def fetch_generator(self) -> Generator:
_results_range: int = randint(10, 1000)
return (self.rand_user() for _ in range(_results_range))

def fetch(self) -> List[UserModel]:
"""
**fetch**
returns a list of users
:return:
"""
return [self.rand_user() for _ in range(self.results_range)]
return [_user for _user in self.fetch_generator()]

def get(self) -> UserModel:
return self.user_instance
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def task_counter(timer_limit: int = 1000000) -> any:
:param timer_limit:
:return:
"""
yield [y for y in range(timer_limit)][0]
return (y for y in range(timer_limit))


# Counter Generator
Expand Down

0 comments on commit d8056a7

Please sign in to comment.