<commit_before>import os, unittest, time
from nose.tools import nottest, assert_equals

from totalimpact.backend import TotalImpactBackend, ProviderMetricsThread, ProvidersAliasThread, StoppableThread, QueueConsumer
from totalimpact.config import Configuration
from totalimpact.providers.provider import Provider, ProviderFactory
from totalimpact.queue import Queue, AliasQueue, MetricsQueue
from totalimpact.util import slow
from totalimpact import dao, api
from totalimpact.tilogging import logging

TEST_DRYAD_DOI = "10.5061/dryad.7898"

class TestAliasQueue(unittest.TestCase):
        
    def test_alias_queue(self):
        config = Configuration() 
        providers = ProviderFactory.get_providers(config)

        # setup the database
        mydao = dao.Dao(config)
        mydao.create_new_db_and_connect('alias_queue_test')
        
        # put an item in there
        app = api.app
        app.testing = True
        app.config["DB_NAME"] = "alias_queue_test"
        client = app.test_client()

        response = client.post('/item/DOI/' + TEST_DRYAD_DOI.replace("/", "%25"))
        tiid = response.data
        print tiid
        print response
        assert False 

        # now get it back out
        tiid = tiid.replace('"', '')
        response = client.get('/item/' + tiid)
        print response
        print response.data
        assert_equals(response.status_code, 200)
        
        #assert_equals(json.loads(response.data).keys(), [u'created', u'last_requested', u'metrics', u'last_modified', u'biblio', u'id', u'aliases'])
        #assert_equals(response.mimetype, "application/json")


        '''
        my_alias_queue = AliasQueue(mydao)
        assert isinstance(my_alias_queue.queue, list)

        watcher = TotalImpactBackend(config)
        assert len(my_alias_queue.queue) > 1
        first = my_alias_queue.first()
        '''
        

        ### FIXME Need to make first return an Item so that can pass to save_and_unqueue

        #assert len(first["_id"]) > 1
        ## FIXME my_alias_queue.save_and_unqueue(first)

        # TODO: once queues actually work, this should succeed
        ## FIXME assert_equals(len(my_alias_queue.queue), 0)




<commit_msg>test_alias_queue puts item in db<commit_after>import os, unittest, time
from nose.tools import nottest, assert_equals

from totalimpact.backend import TotalImpactBackend, ProviderMetricsThread, ProvidersAliasThread, StoppableThread, QueueConsumer
from totalimpact.config import Configuration
from totalimpact.providers.provider import Provider, ProviderFactory
from totalimpact.queue import Queue, AliasQueue, MetricsQueue
from totalimpact.util import slow
from totalimpact import dao, api
from totalimpact.tilogging import logging

TEST_DRYAD_DOI = "10.5061/dryad.7898"

class TestAliasQueue(unittest.TestCase):
    
    def setUp(self):
        #setup api test client
        self.app = api.app
        self.app.testing = True
        self.client = self.app.test_client()
        
        # setup the database
        self.testing_db_name = "alias_queue_test"
        self.old_db_name = self.app.config["DB_NAME"]
        self.app.config["DB_NAME"] = self.testing_db_name
        config = Configuration() 
        self.d = dao.Dao(config)
        
        
    def tearDown(self):
        self.app.config["DB_NAME"] = self.old_db_name
        
    def test_alias_queue(self):
        self.d.create_new_db_and_connect(self.testing_db_name)

        #providers = ProviderFactory.get_providers(config)

        response = self.client.post('/item/DOI/' + TEST_DRYAD_DOI.replace("/", "%25"))
        tiid = response.data
        print tiid
        print response
        #assert False

        # now get it back out
        tiid = tiid.replace('"', '')
        response = self.client.get('/item/' + tiid)
        print response
        print response.data
        assert_equals(response.status_code, 200)
        
        #assert_equals(json.loads(response.data).keys(), [u'created', u'last_requested', u'metrics', u'last_modified', u'biblio', u'id', u'aliases'])
        #assert_equals(response.mimetype, "application/json")


        '''
        my_alias_queue = AliasQueue(mydao)
        assert isinstance(my_alias_queue.queue, list)

        watcher = TotalImpactBackend(config)
        assert len(my_alias_queue.queue) > 1
        first = my_alias_queue.first()
        '''
        

        ### FIXME Need to make first return an Item so that can pass to save_and_unqueue

        #assert len(first["_id"]) > 1
        ## FIXME my_alias_queue.save_and_unqueue(first)

        # TODO: once queues actually work, this should succeed
        ## FIXME assert_equals(len(my_alias_queue.queue), 0)





{'fraction_non_alphanumeric': 0.09573338993844195, 'fraction_numerical': 0.00764168966249204, 'mean_word_length': 2.8813838550247115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1549797', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1389, 'n_words': 321}