| author | Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> |
| Thu, 18 Aug 2011 00:30:15 +0200 | |
| changeset 257 | 6d1d70b9b525 |
| parent 254 | 2209e66bb50b |
| child 289 | a5eff8f2b81d |
| permissions | -rw-r--r-- |
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
1 |
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
2 |
from sqlalchemy.ext.declarative import declarative_base |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
3 |
from sqlalchemy.orm import relationship, backref |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
4 |
import unittest #@UnresolvedImport |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
5 |
from sqlalchemy.orm import sessionmaker |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
6 |
from iri_tweet.utils import ObjectsBuffer, TwitterProcessor |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
7 |
from iri_tweet import models |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
8 |
import tempfile #@UnresolvedImport |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
9 |
import os |
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
10 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
11 |
Base = declarative_base() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
12 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
13 |
class User(Base): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
14 |
__tablename__ = 'users' |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
15 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
16 |
id = Column(Integer, primary_key=True) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
17 |
name = Column(String) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
18 |
fullname = Column(String) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
19 |
password = Column(String) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
20 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
21 |
def __init__(self, name, fullname, password): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
22 |
self.name = name |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
23 |
self.fullname = fullname |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
24 |
self.password = password |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
25 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
26 |
def __repr__(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
27 |
return "<User('%s','%s', '%s')>" % (self.name, self.fullname, self.password) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
28 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
29 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
30 |
class Address(Base): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
31 |
__tablename__ = 'addresses' |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
32 |
id = Column(Integer, primary_key=True) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
33 |
email_address = Column(String, nullable=False) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
34 |
user_id = Column(Integer, ForeignKey('users.id')) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
35 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
36 |
user = relationship("User", backref=backref('addresses', order_by=id)) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
37 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
38 |
def __init__(self, user_id, email_address): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
39 |
self.email_address = email_address |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
40 |
self.user_id = user_id |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
41 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
42 |
def __repr__(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
43 |
return "<Address('%s')>" % self.email_address |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
44 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
45 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
46 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
47 |
class TestObjectBuffer(unittest.TestCase): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
48 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
49 |
def setUp(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
50 |
self.engine = create_engine('sqlite:///:memory:', echo=False) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
51 |
Base.metadata.create_all(self.engine) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
52 |
sessionMaker = sessionmaker(bind=self.engine) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
53 |
self.session = sessionMaker() |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
54 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
55 |
def tearDown(self): |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
56 |
self.session.close() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
57 |
self.engine.dispose() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
58 |
|
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
59 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
60 |
def testCreateUser(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
61 |
ed_user = User('ed', 'Ed Jones', 'edspassword') |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
62 |
self.session.add(ed_user) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
63 |
self.assertTrue(ed_user.id is None) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
64 |
self.session.commit() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
65 |
self.assertTrue(ed_user.id is not None) |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
66 |
|
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
67 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
68 |
def testSimpleBuffer(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
69 |
obj_buffer = ObjectsBuffer() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
70 |
obj_proxy = obj_buffer.add_object(User, ['ed1', 'Ed1 Jones', 'edspassword'], None, False) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
71 |
self.assertTrue(obj_proxy.id() is None) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
72 |
obj_buffer.persists(self.session) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
73 |
self.assertTrue(obj_proxy.id() is None) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
74 |
self.session.commit() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
75 |
self.assertTrue(obj_proxy.id() is not None) |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
76 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
77 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
78 |
def testSimpleBufferKwargs(self): |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
79 |
obj_buffer = ObjectsBuffer() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
80 |
obj_proxy = obj_buffer.add_object(User, None, {'name':'ed1b', 'fullname':'Ed1b Jones', 'password':'edspassword'}, False) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
81 |
self.assertTrue(obj_proxy.id() is None) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
82 |
obj_buffer.persists(self.session) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
83 |
self.assertTrue(obj_proxy.id() is None) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
84 |
self.session.commit() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
85 |
self.assertTrue(obj_proxy.id() is not None) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
86 |
|
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
87 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
88 |
def testSimpleBufferFlush(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
89 |
obj_buffer = ObjectsBuffer() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
90 |
obj_proxy = obj_buffer.add_object(User, ['ed2', 'Ed2 Jones', 'edspassword'], None, True) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
91 |
self.assertTrue(obj_proxy.id() is None) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
92 |
obj_buffer.persists(self.session) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
93 |
self.assertTrue(obj_proxy.id() is not None) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
94 |
self.session.commit() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
95 |
self.assertTrue(obj_proxy.id() is not None) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
96 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
97 |
def testRelationBuffer(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
98 |
obj_buffer = ObjectsBuffer() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
99 |
user1_proxy = obj_buffer.add_object(User, ['ed3', 'Ed3 Jones', 'edspassword'], None, True) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
100 |
obj_buffer.add_object(Address, [user1_proxy.id,'ed3@mail.com'], None, False) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
101 |
obj_buffer.add_object(Address, [user1_proxy.id,'ed3@other.com'], None, False) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
102 |
user2_proxy = obj_buffer.add_object(User, ['ed4', 'Ed3 Jones', 'edspassword'], None, True) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
103 |
obj_buffer.add_object(Address, [user2_proxy.id,'ed4@mail.com'], None, False) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
104 |
obj_buffer.persists(self.session) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
105 |
self.session.commit() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
106 |
ed_user = self.session.query(User).filter_by(name='ed3').first() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
107 |
self.assertEquals(2, len(ed_user.addresses)) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
108 |
ed_user = self.session.query(User).filter_by(name='ed4').first() |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
109 |
self.assertEquals(1, len(ed_user.addresses)) |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
110 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
111 |
|
|
257
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
112 |
def testGet(self): |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
113 |
obj_buffer = ObjectsBuffer() |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
114 |
user1_proxy = obj_buffer.add_object(User, None, {'name':'ed2', 'fullname':'Ed2 Jones', 'password':'edspassword'}, True) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
115 |
adress_proxy = obj_buffer.add_object(Address, None, {'user_id':user1_proxy.id,'email_address':'ed2@other.com'}, False) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
116 |
user2_proxy = obj_buffer.add_object(User, None, {'name':'ed3', 'fullname':'Ed3 Jones', 'password':'edspassword'}, True) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
117 |
obj_buffer.add_object(Address, None, {'user_id':user2_proxy.id,'email_address':'ed3@other.com'}, False) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
118 |
self.assertEquals(user1_proxy, obj_buffer.get(User, name='ed2')) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
119 |
self.assertEquals(adress_proxy, obj_buffer.get(Address, email_address='ed2@other.com')) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
120 |
self.assertEquals(user2_proxy, obj_buffer.get(User, name='ed3')) |
|
6d1d70b9b525
improve tests on get
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
254
diff
changeset
|
121 |
self.assertTrue(obj_buffer.get(User, name='ed3', fullname='Ed2 Jones') is None) |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
122 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
123 |
original_json = u'{"in_reply_to_user_id_str":null,"text":"RT @BieberEagle: \\"I love my haters. They spend so much time thinking about me. Aren\u2019t they sweet?\\" - Justin Bieber","contributors":null,"retweeted":false,"coordinates":null,"retweeted_status":{"in_reply_to_user_id_str":null,"text":"\\"I love my haters. They spend so much time thinking about me. Aren\u2019t they sweet?\\" - Justin Bieber","contributors":null,"retweeted":false,"coordinates":null,"retweet_count":"100+","source":"web","entities":{"user_mentions":[],"hashtags":[],"urls":[]},"truncated":false,"place":null,"id_str":"96638597737889792","in_reply_to_user_id":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_to_status_id_str":null,"user":{"is_translator":false,"profile_background_tile":true,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/298443445\/355584171.jpg","listed_count":5040,"friends_count":8477,"profile_link_color":"ff0000","profile_sidebar_border_color":"000000","url":"http:\/\/twitpic.com\/photos\/BieberEagle","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1465491672\/355584171_normal.jpg","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1465491672\/355584171_normal.jpg","description":"1 name, 1 inspiration, 1 hero, 1 smile, 1 singer, 1 boy who changed my life. B.\u0130.E.B.E.R-Believe In Everything Because Everything\'s Reachable. #NEVERSAYNEVER","default_profile":false,"notifications":null,"time_zone":"Paris","followers_count":14506,"default_profile_image":false,"lang":"en","profile_use_background_image":true,"screen_name":"BieberEagle","show_all_inline_media":false,"geo_enabled":false,"profile_background_color":"ffffff","location":"\u2665 Albania \u2665 ","id_str":"229067923","profile_background_image_url":"http:\/\/a2.twimg.com\/profile_background_images\/298443445\/355584171.jpg","favourites_count":89,"protected":false,"follow_request_sent":null,"following":null,"name":"truebelieber","statuses_count":24279,"verified":false,"created_at":"Tue Dec 21 12:35:18 +0000 2010","profile_text_color":"000000","id":229067923,"contributors_enabled":false,"utc_offset":3600,"profile_sidebar_fill_color":""},"id":96638597737889792,"created_at":"Thu Jul 28 17:50:11 +0000 2011","geo":null,"in_reply_to_screen_name":null},"retweet_count":"100+","source":"web","entities":{"user_mentions":[{"indices":[3,15],"screen_name":"BieberEagle","id_str":"229067923","name":"truebelieber","id":229067923}],"hashtags":[],"urls":[]},"truncated":false,"place":null,"id_str":"96965037637382145","in_reply_to_user_id":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_to_status_id_str":null,"user":{"is_translator":false,"profile_background_tile":true,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/300419382\/ipod.7.14_054.JPG","listed_count":3,"friends_count":1150,"profile_link_color":"00cccc","profile_sidebar_border_color":"c8ff00","url":"http:\/\/www.facebook.com\/blovedbecca180","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1466752962\/block_party_7.27.11_015_normal.JPG","profile_image_url":"http:\/\/a3.twimg.com\/profile_images\/1466752962\/block_party_7.27.11_015_normal.JPG","description":"if ya wanna know something about me, then get to know me. \\n\\r\\n\\ri promise, you wont regret it. (:\\r\\ni love justin bieber with an extreme burning passion!","default_profile":false,"notifications":null,"time_zone":"Central Time (US & Canada)","followers_count":361,"default_profile_image":false,"lang":"en","profile_use_background_image":true,"screen_name":"beccaxannxx","show_all_inline_media":false,"geo_enabled":false,"profile_background_color":"ff0066","location":"","id_str":"65624607","profile_background_image_url":"http:\/\/a3.twimg.com\/profile_background_images\/300419382\/ipod.7.14_054.JPG","favourites_count":266,"protected":false,"follow_request_sent":null,"following":null,"name":"beccaxannxx","statuses_count":2512,"verified":false,"created_at":"Fri Aug 14 12:36:35 +0000 2009","profile_text_color":"6a39d4","id":65624607,"contributors_enabled":false,"utc_offset":-21600,"profile_sidebar_fill_color":"ff00bb"},"id":96965037637382145,"created_at":"Fri Jul 29 15:27:21 +0000 2011","geo":null,"in_reply_to_screen_name":null}' |
|
254
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
124 |
original_json_media = u'{"user": {"follow_request_sent": null, "profile_use_background_image": true, "id": 34311537, "verified": false, "profile_image_url_https": "https://si0.twimg.com/profile_images/1452959211/63440_1494505009634_1444332638_31074099_4058882_n_normal.jpg", "profile_sidebar_fill_color": "DAECF4", "is_translator": false, "geo_enabled": false, "profile_text_color": "663B12", "followers_count": 29, "profile_sidebar_border_color": "C6E2EE", "id_str": "34311537", "default_profile_image": false, "location": "", "utc_offset": -25200, "statuses_count": 813, "description": "i like joe jonas, justin bieber, ashley tisdale, selena gomez, megen fox, kim kardashian and demi lovoto and many more.", "friends_count": 101, "profile_link_color": "1F98C7", "profile_image_url": "http://a1.twimg.com/profile_images/1452959211/63440_1494505009634_1444332638_31074099_4058882_n_normal.jpg", "notifications": null, "show_all_inline_media": false, "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/298244445/tour2011.jpg", "profile_background_color": "C6E2EE", "profile_background_image_url": "http://a1.twimg.com/profile_background_images/298244445/tour2011.jpg", "name": "mikayla", "lang": "en", "profile_background_tile": true, "favourites_count": 231, "screen_name": "bieberfever17ya", "url": null, "created_at": "Wed Apr 22 16:04:28 +0000 2009", "contributors_enabled": false, "time_zone": "Mountain Time (US & Canada)", "protected": false, "default_profile": false, "following": null, "listed_count": 1}, "favorited": false, "entities": {"user_mentions": [], "media": [{"media_url_https": "https://p.twimg.com/AWea5Z-CQAAvfvK.jpg", "expanded_url": "http://twitter.com/bieberfever17ya/status/101219827649232896/photo/1", "sizes": {"small": {"h": 240, "w": 201, "resize": "fit"}, "large": {"h": 240, "w": 201, "resize": "fit"}, "medium": {"h": 240, "w": 201, "resize": "fit"}, "thumb": {"h": 150, "w": 150, "resize": "crop"}}, "url": "http://t.co/N7yZ8hS", "display_url": "pic.twitter.com/N7yZ8hS", "id_str": "101219827653427200", "indices": [31, 50], "type": "photo", "id": 101219827653427200, "media_url": "http://p.twimg.com/AWea5Z-CQAAvfvK.jpg"}], "hashtags": [], "urls": []}, "contributors": null, "truncated": false, "text": "i love you justin bieber <3 http://t.co/N7yZ8hS", "created_at": "Wed Aug 10 09:14:22 +0000 2011", "retweeted": false, "in_reply_to_status_id": null, "coordinates": null, "id": 101219827649232896, "source": "web", "in_reply_to_status_id_str": null, "place": null, "in_reply_to_user_id": null, "in_reply_to_screen_name": null, "retweet_count": 0, "geo": null, "in_reply_to_user_id_str": null, "possibly_sensitive": false, "id_str": "101219827649232896"}' |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
125 |
original_json_media_others = u'{"user": {"utc_offset": -25200, "statuses_count": 813, "default_profile_image": false, "friends_count": 101, "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/298244445/tour2011.jpg", "profile_use_background_image": true, "profile_sidebar_fill_color": "DAECF4", "profile_link_color": "1F98C7", "profile_image_url": "http://a1.twimg.com/profile_images/1452959211/63440_1494505009634_1444332638_31074099_4058882_n_normal.jpg", "time_zone": "Mountain Time (US & Canada)", "is_translator": false, "screen_name": "bieberfever17ya", "url": null, "show_all_inline_media": false, "geo_enabled": false, "profile_background_color": "C6E2EE", "id": 34311537, "profile_background_image_url": "http://a1.twimg.com/profile_background_images/298244445/tour2011.jpg", "description": "i like joe jonas, justin bieber, ashley tisdale, selena gomez, megen fox, kim kardashian and demi lovoto and many more.", "lang": "en", "profile_background_tile": true, "favourites_count": 231, "name": "mikayla", "notifications": null, "follow_request_sent": null, "created_at": "Wed Apr 22 16:04:28 +0000 2009", "verified": false, "contributors_enabled": false, "location": "", "profile_text_color": "663B12", "followers_count": 29, "profile_sidebar_border_color": "C6E2EE", "id_str": "34311537", "default_profile": false, "following": null, "protected": false, "profile_image_url_https": "https://si0.twimg.com/profile_images/1452959211/63440_1494505009634_1444332638_31074099_4058882_n_normal.jpg", "listed_count": 1}, "favorited": false, "contributors": null, "source": "web", "text": "i love you justin bieber <3 http://t.co/N7yZ8hS", "created_at": "Wed Aug 10 09:14:22 +0000 2011", "truncated": false, "retweeted": false, "in_reply_to_status_id_str": null, "coordinates": null, "in_reply_to_user_id_str": null, "entities": {"user_mentions": [], "media": [], "hashtags": [], "urls": [], "others": [{"url": "http://t.co/N7yZ8hS", "text": "comments", "indices": [31, 50]}]}, "in_reply_to_status_id": null, "in_reply_to_screen_name": null, "id_str": "101219827649232896", "place": null, "retweet_count": 0, "geo": null, "id": 101219827649232896, "possibly_sensitive": false, "in_reply_to_user_id": null}' |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
126 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
127 |
class TestTwitterProcessor(unittest.TestCase): |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
128 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
129 |
def setUp(self): |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
130 |
self.engine, self.metadata = models.setup_database('sqlite:///:memory:', echo=True) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
131 |
sessionMaker = sessionmaker(bind=self.engine) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
132 |
self.session = sessionMaker() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
133 |
file, self.tmpfilepath = tempfile.mkstemp() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
134 |
os.close(file) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
135 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
136 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
137 |
def testTwitterProcessor(self): |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
138 |
tp = TwitterProcessor(None, original_json, None, self.session, self.tmpfilepath) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
139 |
tp.process() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
140 |
self.session.commit() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
141 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
142 |
self.assertEquals(1, self.session.query(models.TweetSource).count()) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
143 |
self.assertEquals(1, self.session.query(models.Tweet).count()) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
144 |
self.assertEquals(2, self.session.query(models.User).count()) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
145 |
tweet = self.session.query(models.Tweet).first() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
146 |
self.assertFalse(tweet.user is None) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
147 |
self.assertEqual(u"beccaxannxx",tweet.user.name) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
148 |
self.assertEqual(65624607,tweet.user.id) |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
149 |
self.assertEqual(1,len(tweet.entity_list)) |
|
254
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
150 |
entity = tweet.entity_list[0] |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
151 |
self.assertEqual(u"BieberEagle", entity.user.screen_name) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
152 |
self.assertTrue(entity.user.created_at is None) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
153 |
self.assertEqual("entity_user", entity.type) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
154 |
self.assertEqual("user_mentions", entity.entity_type.label) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
155 |
|
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
156 |
|
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
157 |
def testTwitterProcessorMedia(self): |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
158 |
tp = TwitterProcessor(None, original_json_media, None, self.session, self.tmpfilepath) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
159 |
tp.process() |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
160 |
self.session.commit() |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
161 |
|
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
162 |
self.assertEquals(1, self.session.query(models.TweetSource).count()) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
163 |
self.assertEquals(1, self.session.query(models.Tweet).count()) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
164 |
self.assertEquals(1, self.session.query(models.User).count()) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
165 |
tweet = self.session.query(models.Tweet).first() |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
166 |
self.assertFalse(tweet.user is None) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
167 |
self.assertEqual(u"mikayla",tweet.user.name) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
168 |
self.assertEqual(34311537,tweet.user.id) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
169 |
self.assertEqual(1,len(tweet.entity_list)) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
170 |
entity = tweet.entity_list[0] |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
171 |
self.assertEqual(101219827653427200, entity.media.id) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
172 |
self.assertEqual("photo", entity.media.type.label) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
173 |
self.assertEqual("entity_media", entity.type) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
174 |
self.assertEqual("media", entity.entity_type.label) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
175 |
|
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
176 |
|
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
177 |
def testTwitterProcessorMediaOthers(self): |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
178 |
tp = TwitterProcessor(None, original_json_media_others, None, self.session, self.tmpfilepath) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
179 |
tp.process() |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
180 |
self.session.commit() |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
181 |
|
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
182 |
self.assertEquals(1, self.session.query(models.TweetSource).count()) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
183 |
self.assertEquals(1, self.session.query(models.Tweet).count()) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
184 |
tweet = self.session.query(models.Tweet).first() |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
185 |
self.assertEqual(1,len(tweet.entity_list)) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
186 |
entity = tweet.entity_list[0] |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
187 |
self.assertEqual("entity_entity", entity.type) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
188 |
self.assertEqual("others", entity.entity_type.label) |
|
2209e66bb50b
multiple debugging and corrections
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
244
diff
changeset
|
189 |
|
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
190 |
|
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
191 |
|
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
192 |
def tearDown(self): |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
193 |
self.session.close() |
|
244
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
194 |
self.engine.dispose() |
|
d4b7d6e2633f
migrate twitter processor to use object buffer and add tests
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
243
diff
changeset
|
195 |
os.remove(self.tmpfilepath) |
|
243
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
196 |
|
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
197 |
if __name__ == '__main__': |
|
9213a63fa34a
- debug multithread (still database lock problem)
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
198 |
unittest.main() |