예제 #1
0
def _related_variables_by_concept(variable, concept):
    """Two variables that are related by concept"""
    variable.concept = concept
    variable.save()
    other_variable = VariableFactory(name="other-variable")
    other_variable.concept = concept
    other_variable.save()
    return variable, other_variable
예제 #2
0
    def test_query_parameter_concept(self):
        concept_name = self.concept.name
        variable_list = []

        for number in range(1, 11):
            _variable = VariableFactory(name=str(number))
            _variable.concept = self.concept
            _variable.save()
            variable_list.append(_variable)

        for number in range(11, 21):
            _variable = VariableFactory(name=str(number))
            variable_list.append(_variable)

        response = self.client.get(self.API_PATH + f"?concept={concept_name}")
        content = json.loads(response.content)
        self.assertEqual(10, len(content))
예제 #3
0
    def test_basket_variable_limit_topic_and_concept_POST(self):
        """Define how the basket limit should work."""
        too_many_variables = []
        topic = TopicFactory(name="test-topic")
        concept = ConceptFactory(name="test-concept")
        concept.topics.set([topic])
        concept.save()
        for number in range(1, 12):
            variable = VariableFactory(name=str(number))
            variable.concept = concept
            variable.save()
            too_many_variables.append(variable)

        with patch(
                "ddionrails.api.views.user_tools.BasketVariableSet.basket_limit",
                new_callable=PropertyMock,
        ) as basket_limit:
            basket_limit.return_value = 10
            post_data = {"basket": str(self.basket.id), "topic": topic.name}
            self.client.force_authenticate(user=self.user)
            post_response = self.client.post(self.API_PATH,
                                             post_data,
                                             format="json")
            self.assertEqual(406, post_response.status_code)
            self.assertIn(b"basket size limit", post_response.content)

            BasketVariable.objects.all().delete()

            post_data = {
                "basket": str(self.basket.id),
                "concept": concept.name
            }
            self.client.force_authenticate(user=self.user)
            post_response = self.client.post(self.API_PATH,
                                             post_data,
                                             format="json")
            self.assertEqual(406, post_response.status_code)
            self.assertIn(b"basket size limit", post_response.content)