def save_commercial(self, data): try: commercial = Commercial() commercial.name = data.get('name') commercial.brand = Brand.objects.get(pk=data.get('brand')) commercial.save() if settings.APPLICATION_CACHE: clean_cache = CleanCache() clean_cache.set_cache_result_tag(Commercial.get_commercial_tag()) clean_cache.set_model(Commercial) clean_cache.update_cache_by_id([commercial.id], CleanCache.MODE_INSERT) return commercial, self.SAVE_SUCCESSFUL except Exception, e: return None, self.SAVE_ERROR
def insert_commercial(self): if not Commercial.objects.filter(name='Comercial de prueba').exists(): entry = Entry() entry.name = 'Rubro de prueba' entry.save() brand = Brand() brand.entry = entry brand.name = 'Marca de prueba' brand.save() commercial = Commercial() commercial.brand = brand commercial.name = 'Comercial de prueba' commercial.save()
def test_list_view_commercial(self): """ Tests List """ self.insert_test_data() view = CommercialListView.as_view() request = self.request_factory.get(reverse('commercial_list')) request.user = self.user response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context_data['object_list']), 4) commercial = Commercial() commercial.brand = Brand.objects.latest('id') commercial.save() response = view(request) self.assertEqual(len(response.context_data['object_list']), 5)
def test_data_list(self): """ Tests List """ self.insert_test_data() view = CommercialDataListView.as_view() request = self.request_factory.get(reverse('commercial_data_list')) request.user = self.user response = view(request) self.assertEqual(response.status_code, 200) content = json.loads(response._container[0]) self.assertEqual(len(content.get('commercial')), 4) commercial = Commercial() commercial.brand = Brand.objects.latest('id') commercial.save() response = view(request) content = json.loads(response._container[0]) self.assertEqual(len(content.get('commercial')), 5)
def test_list_view_commercial(self): """ Tests List """ self.insert_test_data() view = CommercialListView.as_view() request = self.request_factory.get( reverse('commercial_list') ) request.user = self.user response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context_data['object_list']), 4) commercial = Commercial() commercial.brand = Brand.objects.latest('id') commercial.save() response = view(request) self.assertEqual(len(response.context_data['object_list']), 5)
def test_data_list(self): """ Tests List """ self.insert_test_data() view = CommercialDataListView.as_view() request = self.request_factory.get( reverse('commercial_data_list') ) request.user = self.user response = view(request) self.assertEqual(response.status_code, 200) content = json.loads(response._container[0]) self.assertEqual(len( content.get('commercial')), 4) commercial = Commercial() commercial.brand = Brand.objects.latest('id') commercial.save() response = view(request) content = json.loads(response._container[0]) self.assertEqual(len( content.get('commercial')), 5)