class TestTheListOfStores(WebTestCase): anonymous = True def setUp(self): super(TestTheListOfStores, self).setUp() self.main_location = 'POINT(144.917908 -37.815751)' self.other_location = 'POINT(144.998401 -37.772895)' self.main_store = StoreFactory( name="Main store in Southbank", is_pickup_store=True, location=self.main_location, ) self.other_store = StoreFactory( name="Other store in Northcote", is_pickup_store=True, location=self.other_location, ) def test_displays_all_stores_unfiltered(self): page = self.get(reverse('stores:index')) self.assertContains(page, self.main_store.name) self.assertContains(page, self.other_store.name) def test_can_be_filtered_by_location(self): page = self.get(reverse('stores:index')) search_form = page.forms['store-search'] search_form['latitude'] = '-37.7736132' search_form['longitude'] = '-144.9997396' page = search_form.submit() self.assertContains(page, self.main_store.name) self.assertContains(page, self.other_store.name) stores = page.context[0].get('object_list') self.assertSequenceEqual(stores, [self.other_store, self.main_store]) def test_can_be_filtered_by_store_group(self): north_group = StoreGroupFactory(name="North") south_group = StoreGroupFactory(name="South") self.main_store.group = south_group self.main_store.save() self.other_store.group = north_group self.other_store.save() page = self.get(reverse('stores:index')) search_form = page.forms['store-search'] search_form['group'] = south_group.id page = search_form.submit() self.assertContains(page, self.main_store.name) stores = page.context[0].get('object_list') self.assertSequenceEqual(stores, [self.main_store])
def setUp(self): super(TestDashboardStoreSearchForm, self).setUp() location = '{"type": "Point", "coordinates": [144.917908,-37.815751]}' location = 'POINT(144.917908 -37.815751)' self.store1 = StoreFactory(name='store1', location=location) self.store2 = StoreFactory(name='store2', location=location) StoreAddressFactory(store=self.store1, line1='Great Portland st., London') StoreAddressFactory(store=self.store2, line1='Sturt Street, Melbourne')
def test_querying_available_pickup_stores(self): sample_location = '{"type": "Point", "coordinates": [88.39,11.02]}' store1 = StoreFactory(is_pickup_store=True, location=sample_location) store2 = StoreFactory(is_pickup_store=True, location=sample_location) StoreFactory(is_pickup_store=False, location=sample_location) store4 = StoreFactory(is_pickup_store=True, location=sample_location) stores = list(Store.objects.pickup_stores()) self.assertEqual(len(stores), 3) self.assertIn(store1, stores) self.assertIn(store2, stores) self.assertIn(store4, stores)
def setUp(self): self.product = ProductFactory() self.store1_location = '{"type": "Point", "coordinates": [87.39,12.02]}' self.store2_location = '{"type": "Point", "coordinates": [88.39,11.02]}' self.store1 = StoreFactory(is_pickup_store=True, location=self.store1_location) self.store2 = StoreFactory(is_pickup_store=True, location=self.store2_location) self.store_stock1 = StoreStockFactory(store=self.store1, product=self.product) self.store_stock1 = StoreStockFactory(store=self.store2, product=self.product)
def setUp(self): super(TestTheListOfStores, self).setUp() self.main_location = 'POINT(144.917908 -37.815751)' self.other_location = 'POINT(144.998401 -37.772895)' self.main_store = StoreFactory( name="Main store in Southbank", is_pickup_store=True, location=self.main_location, ) self.other_store = StoreFactory( name="Other store in Northcote", is_pickup_store=True, location=self.other_location, )
def test_can_be_set_for_a_store(self): store = StoreFactory(name='Test Store', location=Point(30.3333, 123.323)) store = store.__class__.objects.get(id=store.id) self.assertEqual(store.location.x, 30.3333) self.assertEqual(store.location.y, 123.323)
def test_filters(self): f = DashboardStoreSearchForm() Store = get_model('stores', 'Store') location = '{"type": "Point", "coordinates": [144.917908,-37.815751]}' store1 = StoreFactory(name='store1', location=location) store2 = StoreFactory(name='store2', location=location) StoreAddressFactory(store=store1, line1='Great Portland st., London') StoreAddressFactory(store=store2, line1='Sturt Street, Melbourne') f.cleaned_data = {'address': 'portland st, london'} qs = f.apply_filters(Store.objects.all()) self.assertEqual(list(qs), [store1]) f.cleaned_data = {'name': 'store2'} qs = f.apply_filters(Store.objects.all()) self.assertEqual(list(qs), [store2]) f.cleaned_data = {'name': 'store2', 'address': 'london'} qs = f.apply_filters(Store.objects.all()) self.assertEqual(list(qs), [])