Changeset 179:a5588860c659
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r172
|
r179
|
|
| 38 | 38 | import paste.script |
| 39 | 39 | class DemoData(MicrofactsCommand): |
| 40 | | '''Create some demo data in the DB (Bloomsbury Group etc). |
| | 40 | '''Create some demo data in the DB (Bloomsbury Group + Napoleon). |
| 41 | 41 | ''' |
| 42 | 42 | summary = __doc__.split('\n')[0] |
| … |
… |
|
| 59 | 59 | if self.verbose: |
| 60 | 60 | print 'Creating test data' |
| | 61 | print 'Loading Bloomsbury data' |
| 61 | 62 | self.make_data() |
| | 63 | print 'Loading Napoleon data' |
| | 64 | self.make_data_napoleon() |
| 62 | 65 | if self.verbose: |
| 63 | 66 | print 'Creating test data: Complete!' |
| … |
… |
|
| 88 | 91 | in self.thread_titles ] |
| 89 | 92 | 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() |
| 90 | 103 | |
| 91 | 104 | class Dbpedia(MicrofactsCommand): |
-
|
r146
|
r179
|
|
| 183 | 183 | results['factlets'] += ft_converter.to_domain_objects(data['factlets']) |
| 184 | 184 | _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 |
| 186 | 186 | results['factlets'] += ft_converter.to_domain_objects(data['factlets']) |
| 187 | 187 | 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 |
| 189 | 191 | else: # just a single factlet |
| 190 | 192 | tempft = ft_converter.to_domain_object(data) |
-
|
r172
|
r179
|
|
| 13 | 13 | ) |
| 14 | 14 | out = microfacts.lib.json.load(sample) |
| | 15 | self.thread = out['threads'][0] |
| 15 | 16 | self.factlets = out['factlets'] |
| 16 | 17 | assert len(self.factlets) == 6 |
| … |
… |
|
| 20 | 21 | |
| 21 | 22 | def tearDown(self): |
| | 23 | model.Session.delete(self.thread) |
| 22 | 24 | for fct in self.factlets: |
| 23 | 25 | model.Session.delete(fct) |
-
|
r172
|
r179
|
|
| 117 | 117 | assert results is not None |
| 118 | 118 | assert len(results['factlets']) == 6 |
| | 119 | assert len(results['threads']) == 1 |
| 119 | 120 | |
| 120 | 121 | |