def test_update_features(self): model = Model.objects.latest('created') self.assertEqual(model.model_feature_detail_set.all().count(), 1) model_feature_detail = ModelFeatureDetail() model_feature_detail.model = model model_feature_detail.feature_value = FeatureValue.objects.get(pk=139) model_feature_detail.description = 'Facebook' model_feature_detail.save() url = reverse('panel_model_update_feature', kwargs={'pk': model.id}) data = { "feature": { "value_id": 139, "value_name": "Twitter" }, "description": "olalal", "model_feature_id": model_feature_detail.id } view = ModelFeatureUpdateView.as_view() request = self.request_factory.post(url, data=dumps(data), content_type='application/json') request.user = self.user response = view(request, pk=model.id) content = json.loads(response._container[0]) self.assertEqual(content.get('status'), 'success') self.assertEqual(model.model_feature_detail_set.all().count(), 2)
def save_feature_model(self, data): feature_value = data.get('feature_value') feature_value = FeatureValue.objects.get( pk=feature_value.get('value_id')) feature = feature_value.feature model = Model.objects.get(pk=self.kwargs.get('pk')) description = data.get('description', None) if model.model_feature_detail_set.filter( feature_value__feature=feature).exists(): if feature.type == Feature.TYPE_UNIQUE: return None elif feature.type == Feature.TYPE_MULTIPLE: if model.model_feature_detail_set.filter( feature_value=feature_value).exists(): return None model_feature_detail = ModelFeatureDetail() model_feature_detail.feature_value = feature_value model_feature_detail.model = model model_feature_detail.description = description model_feature_detail.save() return self.result_json(model_feature_detail)
def test_update_features(self): model = Model.objects.latest('created') self.assertEqual(model.model_feature_detail_set.all().count(), 1) model_feature_detail = ModelFeatureDetail() model_feature_detail.model = model model_feature_detail.feature_value = FeatureValue.objects.get(pk=139) model_feature_detail.description = 'Facebook' model_feature_detail.save() url = reverse('panel_model_update_feature', kwargs={'pk': model.id}) data = { "feature": { "value_id": 139, "value_name": "Twitter" }, "description": "olalal", "model_feature_id": model_feature_detail.id } view = ModelFeatureUpdateView.as_view() request = self.request_factory.post( url, data=dumps(data), content_type='application/json' ) request.user = self.user response = view(request, pk=model.id) content = json.loads(response._container[0]) self.assertEqual(content.get('status'), 'success') self.assertEqual(model.model_feature_detail_set.all().count(), 2)
def save_model_feature(self, model, data): for feature in self.feature: try: model_feature_detail = ModelFeatureDetail() if self.feature[feature] == Feature.objects.get(name='Redes sociales'): if data.get(feature).find('facebook') > 0: feature_value = FeatureValue.objects.get(name='Facebook', feature=self.feature[feature]) model_feature_detail.description = data.get(feature) model_feature_detail.feature_value = feature_value if data.get(feature).find('youtube') > 0: feature_value = FeatureValue.objects.get(name='Youtube', feature=self.feature[feature]) model_feature_detail.description = data.get(feature) model_feature_detail.feature_value = feature_value else: feature_value = FeatureValue.objects.get(name=data.get(feature), feature=self.feature[feature]) model_feature_detail.description = None model_feature_detail.feature_value = feature_value model_feature_detail.model = model model_feature_detail.save() except Exception, e: pass
def test_delete_features(self): model = Model.objects.latest('created') model_feature_detail = ModelFeatureDetail() model_feature_detail.model = model model_feature_detail.feature_value = FeatureValue.objects.get(pk=139) model_feature_detail.description = 'Facebook' model_feature_detail.save() self.assertEqual(model.model_feature_detail_set.all().count(), 2) url = reverse('panel_model_delete_feature') data = str(model_feature_detail.id) view = ModelFeatureDeleteView.as_view() request = self.request_factory.post(url, data=dumps(data), content_type='application/json') request.user = self.user response = view(request) content = json.loads(response._container[0]) self.assertEqual(content.get('status'), 'success') self.assertEqual(model.model_feature_detail_set.all().count(), 1)
def test_delete_features(self): model = Model.objects.latest('created') model_feature_detail = ModelFeatureDetail() model_feature_detail.model = model model_feature_detail.feature_value = FeatureValue.objects.get(pk=139) model_feature_detail.description = 'Facebook' model_feature_detail.save() self.assertEqual(model.model_feature_detail_set.all().count(), 2) url = reverse('panel_model_delete_feature') data = str(model_feature_detail.id) view = ModelFeatureDeleteView.as_view() request = self.request_factory.post( url, data=dumps(data), content_type='application/json' ) request.user = self.user response = view(request) content = json.loads(response._container[0]) self.assertEqual(content.get('status'), 'success') self.assertEqual(model.model_feature_detail_set.all().count(), 1)
def save_feature_model(self, data): feature_value = data.get('feature_value') feature_value = FeatureValue.objects.get(pk=feature_value.get('value_id')) feature = feature_value.feature model = Model.objects.get(pk=self.kwargs.get('pk')) description = data.get('description', None) if model.model_feature_detail_set.filter(feature_value__feature=feature).exists(): if feature.type == Feature.TYPE_UNIQUE: return None elif feature.type == Feature.TYPE_MULTIPLE: if model.model_feature_detail_set.filter(feature_value=feature_value).exists(): return None model_feature_detail = ModelFeatureDetail() model_feature_detail.feature_value = feature_value model_feature_detail.model = model model_feature_detail.description = description model_feature_detail.save() return self.result_json(model_feature_detail)
def save_model_feature(self, model, data): for feature in self.feature: try: model_feature_detail = ModelFeatureDetail() if self.feature[feature] == Feature.objects.get( name='Redes sociales'): if data.get(feature).find('facebook') > 0: feature_value = FeatureValue.objects.get( name='Facebook', feature=self.feature[feature]) model_feature_detail.description = data.get(feature) model_feature_detail.feature_value = feature_value if data.get(feature).find('youtube') > 0: feature_value = FeatureValue.objects.get( name='Youtube', feature=self.feature[feature]) model_feature_detail.description = data.get(feature) model_feature_detail.feature_value = feature_value else: feature_value = FeatureValue.objects.get( name=data.get(feature), feature=self.feature[feature]) model_feature_detail.description = None model_feature_detail.feature_value = feature_value model_feature_detail.model = model model_feature_detail.save() except Exception, e: pass