Source code for goat.tests.test_tasks_search

import unittest, mock, types

from goat import tasks
from goat.models import *
from django.contrib.auth.models import User

with open('goat/tests/authorities/conceptpower.json') as f:
    configuration = f.read()


[docs]class TestTaskSearch(unittest.TestCase):
[docs] def setUp(self): self.user = User.objects.create(username='testUser') self.authority = Authority.objects.create( name="testAuthority", added_by=self.user, configuration=configuration, namespace='http://www.digitalhps.org/' ) self.viaf = Authority.objects.create( name='VIAF', added_by=self.user, namespace='http://viaf.org/viaf/' )
@mock.patch('requests.get')
[docs] def test_search_pos(self, mock_get): class MockResponse(object): def __init__(self, content): self.content = content with open('goat/tests/mock_responses/cp_search.xml', 'r') as f: mock_get.return_value = MockResponse(f.read()) path = 'http://chps.asu.edu/conceptpower/rest/ConceptLookup/test/verb' query = {'q': 'test', 'pos': 'verb'} results, _ = tasks.search(self.user, self.authority, query, None) args, kwargs = mock_get.call_args self.assertEqual(args[0], path)
@mock.patch('requests.get')
[docs] def tearDown(self): for model in [User, Concept, Authority, Identity, IdentitySystem, SearchResultSet]: model.objects.all().delete()