Beispiel #1
0
    def test_retrieve_tag(self):
        utils.log_as(self, utils.UserType.STAFF)

        mathematical_object = utils.create_mathematical_object(self)
        tag_object = utils.add_tag(self,
                                   mathematical_object.id,
                                   default_tag='test_retrieve_tag' +
                                   utils.get_random_characters())

        response = self.client.get(reverse('api:tag-autocomplete'),
                                   format='json')
        self.assertContains(response, tag_object.tag)
Beispiel #2
0
    def test_retrieve_name_not_connected(self):
        utils.log_as(self, utils.UserType.STAFF)
        mathematical_object = utils.create_mathematical_object(self)
        name_object = utils.add_name(
            self,
            mathematical_object.id,
            default_name='test_retrieve_name_not_connected' +
            utils.get_random_characters())

        utils.log_as(self, utils.UserType.VISITOR)
        response = self.client.get(reverse('api:name-autocomplete'),
                                   format='json')
        self.assertNotContains(response, name_object.name)
Beispiel #3
0
    def test_retrieve_function(self):
        utils.log_as(self, utils.UserType.STAFF)

        mathematical_object = utils.create_mathematical_object(self)
        function_object = utils.add_function(
            self,
            mathematical_object.id,
            function_name='test_retrieve_function' +
            utils.get_random_characters())

        response = self.client.get(reverse('api:function-autocomplete'),
                                   format='json')
        self.assertContains(response, function_object.function)
Beispiel #4
0
    def test_retrieve_only_part_of_functions(self):
        utils.log_as(self, utils.UserType.STAFF)

        number_of_functions = 3

        mathematical_object = utils.create_mathematical_object(self)
        function_objects_without_bananas = [
            utils.add_function(
                self,
                mathematical_object.id,
                function_name='test_retrieve_only_part_of_functions' +
                utils.get_random_characters())
            for _ in range(number_of_functions)
        ]
        function_objects_with_bananas = [
            utils.add_function(self,
                               mathematical_object.id,
                               function_name='bananas' +
                               utils.get_random_characters())
            for _ in range(number_of_functions)
        ]

        response = self.client.get(reverse('api:function-autocomplete') +
                                   "?q=test",
                                   format='json')
        for function_object in function_objects_without_bananas:
            self.assertContains(response, function_object.function)
        for function_object in function_objects_with_bananas:
            self.assertNotContains(response, function_object.function)

        response = self.client.get(reverse('api:function-autocomplete') +
                                   "?q=banana",
                                   format='json')
        for function_object in function_objects_without_bananas:
            self.assertNotContains(response, function_object.function)
        for function_object in function_objects_with_bananas:
            self.assertContains(response, function_object.function)
Beispiel #5
0
    def test_retrieve_only_part_of_names(self):
        utils.log_as(self, utils.UserType.STAFF)

        number_of_names = 3

        mathematical_object = utils.create_mathematical_object(self)

        name_objects_without_bananas = [
            utils.add_name(self,
                           mathematical_object.id,
                           default_name='test_retrieve_only_part_of_names' +
                           utils.get_random_characters())
            for _ in range(number_of_names)
        ]
        name_objects_with_bananas = [
            utils.add_name(self,
                           mathematical_object.id,
                           default_name='bananas' +
                           utils.get_random_characters())
            for _ in range(number_of_names)
        ]

        response = self.client.get(reverse('api:name-autocomplete') +
                                   "?q=test",
                                   format='json')
        for name_object in name_objects_without_bananas:
            self.assertContains(response, name_object.name)
        for name_object in name_objects_with_bananas:
            self.assertNotContains(response, name_object.name)

        response = self.client.get(reverse('api:name-autocomplete') +
                                   "?q=banana",
                                   format='json')
        for name_object in name_objects_without_bananas:
            self.assertNotContains(response, name_object.name)
        for name_object in name_objects_with_bananas:
            self.assertContains(response, name_object.name)
Beispiel #6
0
    def test_retrieve_multiple_tags(self):
        utils.log_as(self, utils.UserType.STAFF)

        number_of_tags = 3

        mathematical_object = utils.create_mathematical_object(self)
        tag_objects = [
            utils.add_tag(self,
                          mathematical_object.id,
                          default_tag='test_retrieve_multiple_tags' +
                          utils.get_random_characters())
            for _ in range(number_of_tags)
        ]

        response = self.client.get(reverse('api:tag-autocomplete'),
                                   format='json')
        for tag_object in tag_objects:
            self.assertContains(response, tag_object.tag)
Beispiel #7
0
    def test_retrieve_multiple_functions(self):
        utils.log_as(self, utils.UserType.STAFF)

        number_of_functions = 3

        mathematical_object = utils.create_mathematical_object(self)
        function_objects = [
            utils.add_function(
                self,
                mathematical_object.id,
                function_name='test_retrieve_multiple_functions' +
                utils.get_random_characters())
            for _ in range(number_of_functions)
        ]

        response = self.client.get(reverse('api:function-autocomplete'),
                                   format='json')
        for function_object in function_objects:
            self.assertContains(response, function_object.function)