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)


		
		
예제 #2
0
 def __init__(self):
     BaseRepo.__init__(self, Menu)
     self.meal_repo = MealItemRepo()
예제 #3
0
 def __init__(self):
     BaseRepo.__init__(self, Activity)
예제 #4
0
 def setUp(self):
     self.BaseSetUp()
     self.repo = BaseRepo(Vendor)
예제 #5
0
 def __init__(self):
     BaseRepo.__init__(self, Permission)
예제 #6
0
 def __init__(self):
     BaseRepo.__init__(self, UserRole)
     self.redis_set = RedisSet()
예제 #7
0
 def __init__(self):
     BaseRepo.__init__(self, Order)
     self.meal_item_repo = MealItemRepo()
예제 #8
0
 def __init__(self):
     BaseRepo.__init__(self, VendorEngagement)
예제 #9
0
 def __init__(self):
     BaseRepo.__init__(self, FlightSeat)
예제 #10
0
 def __init__(self):
     BaseRepo.__init__(self, UserEmploymentSkill)
예제 #11
0
 def __init__(self):
     BaseRepo.__init__(self, Event)
예제 #12
0
 def __init__(self):
     BaseRepo.__init__(self, UserEducation)
예제 #13
0
 def __init__(self):
     BaseRepo.__init__(self, UserClient)
예제 #14
0
	def __init__(self):
		BaseRepo.__init__(self, Admin)
예제 #15
0
 def __init__(self):
     BaseRepo.__init__(self, Faq)
예제 #16
0
 def __init__(self):
     BaseRepo.__init__(self, MealItem)
예제 #17
0
 def __init__(self):
     BaseRepo.__init__(self, Student)
예제 #18
0
 def __init__(self):
     BaseRepo.__init__(self, SkillCategory)
예제 #19
0
 def __init__(self):
     BaseRepo.__init__(self, Ticket)
예제 #20
0
 def __init__(self):
     BaseRepo.__init__(self, UserSkill)
 def __init__(self):
     BaseRepo.__init__(self, MealSession)
예제 #22
0
 def __init__(self):
     BaseRepo.__init__(self, Location)
예제 #23
0
 def __init__(self):
     BaseRepo.__init__(self, MealService)
예제 #24
0
 def __init__(self):
     BaseRepo.__init__(self, Role)
예제 #25
0
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)
예제 #26
0
	def __init__(self):
		BaseRepo.__init__(self, Vendor)
예제 #27
0
 def __init__(self):
     BaseRepo.__init__(self, UserRole)
예제 #28
0
 def __init__(self):
     BaseRepo.__init__(self, LectureAdmin)
예제 #29
0
 def __init__(self):
     BaseRepo.__init__(self, ProductRating)
예제 #30
0
 def __init__(self):
     BaseRepo.__init__(self, CardDetail)