class TestBaseRepository(BaseTestCase): def setUp(self): self.BaseSetUp() self.repo = BaseRepo(Vendor) def test_repo_get_method_returns_value_by_id(self): vendor = VendorFactory() vendor_ = self.repo.get(vendor.id) self.assertIsInstance(vendor_, Vendor) self.assertEqual(vendor.id, vendor_.id) self.assertEqual(vendor.tel, vendor_.tel) self.assertEqual(vendor.address, vendor_.address) def test_update_method_updates_model_values(self): vendor = VendorFactory() updates = {'name': 'Jays Place', 'tel': '09012343', 'contact_person': 'Joseph Cobhams'} vendor_ = self.repo.update(vendor, **updates) self.assertIsInstance(vendor_, Vendor) self.assertEqual(vendor_.name, updates['name']) self.assertEqual(vendor_.tel, updates['tel']) self.assertEqual(vendor_.contact_person, updates['contact_person']) def test_count_method_returns_correct_count_as_integer(self): VendorFactory.create_batch(10) count = self.repo.count() self.assertIsInstance(count, int) self.assertEqual(count, 10) def test_get_first_item_method_only_returns_that(self): vendor_1 = VendorFactory() vendor_2 = VendorFactory.create() vendor_ = self.repo.get_first_item() self.assertIsInstance(vendor_, Vendor) self.assertEqual(vendor_1.id, vendor_.id) self.assertEqual(vendor_1.tel, vendor_.tel) self.assertEqual(vendor_1.address, vendor_.address) self.assertNotEqual(vendor_2.id, vendor_.id)
def __init__(self): BaseRepo.__init__(self, Menu) self.meal_repo = MealItemRepo()
def __init__(self): BaseRepo.__init__(self, Activity)
def setUp(self): self.BaseSetUp() self.repo = BaseRepo(Vendor)
def __init__(self): BaseRepo.__init__(self, Permission)
def __init__(self): BaseRepo.__init__(self, UserRole) self.redis_set = RedisSet()
def __init__(self): BaseRepo.__init__(self, Order) self.meal_item_repo = MealItemRepo()
def __init__(self): BaseRepo.__init__(self, VendorEngagement)
def __init__(self): BaseRepo.__init__(self, FlightSeat)
def __init__(self): BaseRepo.__init__(self, UserEmploymentSkill)
def __init__(self): BaseRepo.__init__(self, Event)
def __init__(self): BaseRepo.__init__(self, UserEducation)
def __init__(self): BaseRepo.__init__(self, UserClient)
def __init__(self): BaseRepo.__init__(self, Admin)
def __init__(self): BaseRepo.__init__(self, Faq)
def __init__(self): BaseRepo.__init__(self, MealItem)
def __init__(self): BaseRepo.__init__(self, Student)
def __init__(self): BaseRepo.__init__(self, SkillCategory)
def __init__(self): BaseRepo.__init__(self, Ticket)
def __init__(self): BaseRepo.__init__(self, UserSkill)
def __init__(self): BaseRepo.__init__(self, MealSession)
def __init__(self): BaseRepo.__init__(self, Location)
def __init__(self): BaseRepo.__init__(self, MealService)
def __init__(self): BaseRepo.__init__(self, Role)
class TestBaseRepository(BaseTestCase): def setUp(self): self.BaseSetUp() self.repo = BaseRepo(Vendor) def tearDown(self): self.BaseTearDown() def test_repo_get_method_returns_value_by_id(self): vendor = VendorFactory.create() vendor_ = self.repo.get(vendor.id) self.assertIsInstance(vendor_, Vendor) self.assertEqual(vendor.id, vendor_.id) self.assertEqual(vendor.tel, vendor_.tel) self.assertEqual(vendor.address, vendor_.address) def test_get_unpaginated_asc_orders_ascending(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() vendor_names = sorted([vendor.name for vendor in [vendor_1, vendor_2]]) results = self.repo.get_unpaginated_asc(Vendor.name) self.assertEqual(vendor_names[0], results[0].name) self.assertEqual(vendor_names[1], results[1].name) def test_get_unpaginated_desc_orders_ascending(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() vendor_names = sorted([vendor.name for vendor in [vendor_1, vendor_2]], reverse=True) results = self.repo.get_unpaginated_desc(Vendor.name) self.assertEqual(vendor_names[0], results[0].name) self.assertEqual(vendor_names[1], results[1].name) def test_update_method_updates_model_values(self): vendor = VendorFactory() updates = { 'name': 'Jays Place', 'tel': '09012343', 'contact_person': 'Joseph Cobhams' } vendor_ = self.repo.update(vendor, **updates) self.assertIsInstance(vendor_, Vendor) self.assertEqual(vendor_.name, updates['name']) self.assertEqual(vendor_.tel, updates['tel']) self.assertEqual(vendor_.contact_person, updates['contact_person']) def test_count_method_returns_correct_count_as_integer(self): VendorFactory.create_batch(10) count = self.repo.count() self.assertIsInstance(count, int) self.assertEqual(count, 10) def test_get_first_item_method_only_returns_that(self): vendor_1 = VendorFactory() vendor_2 = VendorFactory.create() vendor_ = self.repo.get_first_item() self.assertIsInstance(vendor_, Vendor) self.assertEqual(vendor_1.id, vendor_.id) self.assertEqual(vendor_1.tel, vendor_.tel) self.assertEqual(vendor_1.address, vendor_.address) self.assertNotEqual(vendor_2.id, vendor_.id) def test_fetch_all_method_returns_paginated_results(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() paginated_result = self.repo.fetch_all() self.assertEqual(len(paginated_result.items), 2) self.assertEqual(paginated_result.items[0], vendor_1) self.assertEqual(paginated_result.items[1], vendor_2) def test_filter_all_method_returns_paginated_results(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() paginated_result = self.repo.filter_all() self.assertEqual(len(paginated_result.items), 2) self.assertEqual(paginated_result.items[0], vendor_1) self.assertEqual(paginated_result.items[1], vendor_2) def test_filter_and_count_method_returns_correct_count(self): VendorFactory.create() VendorFactory.create() result = self.repo.filter_and_count() self.assertEqual(result, 2) def test_filter_and_order_method_returns_correct_order(self): VendorFactory.create() vendor_2 = VendorFactory.create() result = self.repo.filter_and_order('created_at') self.assertEqual(result.count(), 2) self.assertNotEqual(result.first(), vendor_2) def test_order_by_method_returns_correct_order(self): VendorFactory.create() vendor_2 = VendorFactory.create() result = self.repo.order_by('created_at') self.assertEqual(result.count(), 2) self.assertNotEqual(result.first(), vendor_2) def test_paginate_method_returns_paginated_results(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() paginated_result = self.repo.paginate() self.assertEqual(len(paginated_result.items), 2) self.assertEqual(paginated_result.items[0], vendor_1) self.assertEqual(paginated_result.items[1], vendor_2) def test_filter_method_returns_paginated_results(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() paginated_result = self.repo.filter() self.assertEqual(len(paginated_result.items), 2) self.assertEqual(paginated_result.items[0], vendor_1) self.assertEqual(paginated_result.items[1], vendor_2) def test_filter_by_asc_method_returns_ascending_ordered_results(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() vendor_names = sorted([vendor.name for vendor in [vendor_1, vendor_2]]) results = self.repo.filter_by_asc(Vendor.name) self.assertEqual(vendor_names[0], results.items[0].name) self.assertEqual(vendor_names[1], results.items[1].name) def test_filter_by_desc_method_returns_descending_ordered_results(self): vendor_1 = VendorFactory.create() vendor_2 = VendorFactory.create() vendor_names = sorted([vendor.name for vendor in [vendor_1, vendor_2]], reverse=True) results = self.repo.filter_by_desc(Vendor.name) self.assertEqual(vendor_names[0], results.items[0].name) self.assertEqual(vendor_names[1], results.items[1].name) def test_method_check_exists_else_where_returns_empty_list(self): vendor_1 = VendorFactory.create() results = self.repo.check_exists_else_where(Vendor, 'name', vendor_1.name, 'id', vendor_1.id) self.assertIsInstance(results, list) self.assertEqual(results, []) def test_method_check_exists_else_where_returns_populated_list(self): VendorFactory.create(name="Andela Eats") vendor_1 = VendorFactory.create() results = self.repo.check_exists_else_where(Vendor, 'name', "Andela Eats", 'id', vendor_1.id) self.assertIsInstance(results, list) self.assertNotEqual(results, []) def test_method_check_exists_else_where_returns_string(self): VendorFactory.create(name="Andela Eats") vendor_1 = VendorFactory.create() results = self.repo.check_exists_else_where(Vendor, 'names', "Andela Eats", 'id', vendor_1.id) self.assertIsInstance(results, str) assert "An error occurred during the check" in results def test_paginate_handles_invalid_type(self): with self.assertRaises(BaseModelValidationError): self.repo.paginate(page='test', per_page=20) def test_paginate_handles_negative_values(self): with self.assertRaises(BaseModelValidationError): self.repo.paginate(page=-1, per_page=20) def test_paginate_succeeds(self): page = self.repo._positive_int('page', 3) self.assertEquals(page, 3)
def __init__(self): BaseRepo.__init__(self, Vendor)
def __init__(self): BaseRepo.__init__(self, UserRole)
def __init__(self): BaseRepo.__init__(self, LectureAdmin)
def __init__(self): BaseRepo.__init__(self, ProductRating)
def __init__(self): BaseRepo.__init__(self, CardDetail)