Changeset 179:a5588860c659

Show
Ignore:
Timestamp:
08/30/08 13:12:29 (2 years ago)
Author:
rgrp
Branch:
default
convert_revision:
svn:10edda23-d834-0410-9182-b00384516d49/trunk@191
Message:

[lib/json,lib/cli][s]: expand demo-data to also load napoleon campaign thread.

  • lib/json.py: As a result of this found a bug in json load code (was not loading threads correctly). Fixed this.
  • tests/: this change required a minor fix to teardown in factlet functional test.
Location:
microfacts
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • microfacts/lib/cli.py

    r172 r179  
    3838import paste.script 
    3939class DemoData(MicrofactsCommand): 
    40     '''Create some demo data in the DB (Bloomsbury Group etc). 
     40    '''Create some demo data in the DB (Bloomsbury Group + Napoleon). 
    4141    ''' 
    4242    summary = __doc__.split('\n')[0] 
     
    5959        if self.verbose: 
    6060            print 'Creating test data' 
     61        print 'Loading Bloomsbury data' 
    6162        self.make_data() 
     63        print 'Loading Napoleon data' 
     64        self.make_data_napoleon() 
    6265        if self.verbose: 
    6366            print 'Creating test data: Complete!' 
     
    8891                in self.thread_titles ] 
    8992        return factlets, threads 
     93 
     94    @classmethod 
     95    def make_data_napoleon(self): 
     96        import pkg_resources 
     97        import microfacts.model as model 
     98        import microfacts.lib.json 
     99        data = pkg_resources.resource_stream('microfacts', 
     100                'data/napoleon.js') 
     101        out = microfacts.lib.json.load(data) 
     102        data.close() 
    90103 
    91104class Dbpedia(MicrofactsCommand): 
  • microfacts/lib/json.py

    r146 r179  
    183183            results['factlets'] += ft_converter.to_domain_objects(data['factlets']) 
    184184        _to_threads(data['threads']) 
    185     elif 'factlets' in data and 'title' not in 'data': # just factlets 
     185    elif 'factlets' in data and 'title' not in data: # just factlets 
    186186        results['factlets'] += ft_converter.to_domain_objects(data['factlets']) 
    187187    elif 'factlets' in data and 'title' in data: # a thread 
    188         td_converter.to_domain_object([data]) 
     188        thread = td_converter.to_domain_object(data) 
     189        results['threads'] = [ thread ] 
     190        results['factlets'] = thread.factlets 
    189191    else: # just a single factlet 
    190192        tempft = ft_converter.to_domain_object(data) 
  • microfacts/tests/functional/test_factlet.py

    r172 r179  
    1313        ) 
    1414        out = microfacts.lib.json.load(sample) 
     15        self.thread = out['threads'][0] 
    1516        self.factlets = out['factlets'] 
    1617        assert len(self.factlets) == 6 
     
    2021 
    2122    def tearDown(self): 
     23        model.Session.delete(self.thread) 
    2224        for fct in self.factlets: 
    2325            model.Session.delete(fct) 
  • microfacts/tests/test_json.py

    r172 r179  
    117117        assert results is not None 
    118118        assert len(results['factlets']) == 6 
     119        assert len(results['threads']) == 1 
    119120 
    120121