~robru/friends/facebook-stories

« back to all changes in this revision

Viewing changes to friends/main.py

  • Committer: Robert Bruce Park
  • Date: 2013-03-14 19:14:03 UTC
  • Revision ID: robert.park@canonical.com-20130314191403-5oxy3wqqud8zdnsp
Centralize TestModel creation in friends.utils.mocks.

This reduces a little chunk of redundant code duplication.

This commit also includes a minor unused imports cleanup in the
testsuite thanks to pyflakes.

I also discovered that friends.utils.model.persist_model was untested
thanks to pyflakes, so I wrote a quick test for that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
args = Options().parser.parse_args()
43
43
 
44
44
if args.test:
 
45
    import os
 
46
    import tempfile
 
47
    import shutil
 
48
 
45
49
    from friends.service.mock_service import Dispatcher
46
 
    from friends.utils.model import COLUMN_TYPES
 
50
    from friends.utils.mocks import TestModel
47
51
    from gi.repository import Dee
48
52
 
49
 
    TestModel = Dee.SharedModel.new('com.canonical.Friends.TestSharedModel')
50
 
    TestModel.set_schema_full(COLUMN_TYPES)
 
53
    temp_cache = tempfile.mkdtemp()
 
54
    root = JsonCache._root = os.path.join(temp_cache, '{}.json')
 
55
    account = FakeAccount()
 
56
    protocol = Facebook(self.account)
 
57
    protocol.source_registry = EDSRegistry()
 
58
    with mock.patch('friends.utils.http.Soup.Message',
 
59
                    FakeSoupMessage('friends.tests.data',
 
60
                                    'facebook-login.dat')) as fb:
51
61
 
52
62
    Dispatcher()
53
63
    try:
54
64
        loop.run()
55
65
    except KeyboardInterrupt:
56
66
        pass
 
67
 
 
68
    shutil.rmtree(temp_cache)
57
69
    sys.exit(0)
58
70
 
59
71