Skip to content

Commit

Permalink
Migrates inet:web:acct:occupation from str:txt to str:lwr
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexmc committed Oct 11, 2017
1 parent 0133563 commit d8fd5aa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
19 changes: 18 additions & 1 deletion synapse/models/inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,23 @@ def _updateXref(xref_props, oldform, newform):
continue
self.core.store.updateProperty(old, new)

@modelrev('inet', 201710111553)
def _revModl201710111553(self):

adds, dels = [], []
with self.core.getCoreXact() as xact:
for i, p, v, t in self.core.getRowsByProp('inet:web:acct:occupation'):
newv = v.lower()
if newv != v:
adds.append((i, p, newv, t),)
dels.append((i, p, v),)

if adds:
self.core.addRows(adds)

for i, p, v in dels:
self.core.delRowsByIdProp(i, p, v)

@staticmethod
def getBaseModels():
modl = {
Expand Down Expand Up @@ -932,7 +949,7 @@ def getBaseModels():

('tagline', {'ptype': 'str:txt', 'doc': 'A web account status/tag line text'}),
('loc', {'ptype': 'str:lwr', 'doc': 'The web account self declared location'}),
('occupation', {'ptype': 'str:txt', 'doc': 'A web account self declared occupation'}),
('occupation', {'ptype': 'str:lwr', 'doc': 'A web account self declared occupation'}),
# ('gender',{'ptype':'inet:fqdn','ro':1}),

('name', {'ptype': 'inet:user'}),
Expand Down
41 changes: 41 additions & 0 deletions synapse/tests/test_model_inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,3 +1295,44 @@ def addrows(mesg):
self.len(2, core.getRowsByProp('syn:tagform:form', 'inet:web:logon'))
self.len(1, core.getRowsByProp('_:*inet:web:logon#hehe.hoho'))
self.len(1, core.getRowsByProp('_:*inet:web:logon#hehe'))

def test_model_inet_201710111553(self):

adds = []

iden, tick = guid(), now()
adds.extend([
(iden, 'tufo:form', 'inet:web:acct', tick),
(iden, 'inet:web:acct', 'vertex.link/pennywise1', tick),
(iden, 'inet:web:acct:site', 'vertex.link', tick),
(iden, 'inet:web:acct:user', 'pennywise', tick),
(iden, 'inet:web:acct:occupation', 'EnterTainEr', tick),
])

iden, tick = guid(), now()
adds.extend([
(iden, 'tufo:form', 'inet:web:acct', tick),
(iden, 'inet:web:acct', 'vertex.link/pennywise2', tick),
(iden, 'inet:web:acct:site', 'vertex.link', tick),
(iden, 'inet:web:acct:user', 'pennywise', tick),
(iden, 'inet:web:acct:occupation', 'entertainer', tick),
])

with s_cortex.openstore('ram:///') as stor:

stor.setModlVers('inet', 0)
def addrows(mesg):
stor.addRows(adds)
stor.on('modl:vers:rev', addrows, name='inet', vers=201710111553)

with s_cortex.fromstore(stor) as core:

tufo = core.getTufoByProp('inet:web:acct', 'vertex.link/pennywise1')
self.eq(tufo[1]['tufo:form'], 'inet:web:acct')
self.eq(tufo[1]['inet:web:acct'], 'vertex.link/pennywise1')
self.eq(tufo[1]['inet:web:acct:occupation'], 'entertainer')

tufo = core.getTufoByProp('inet:web:acct', 'vertex.link/pennywise2')
self.eq(tufo[1]['tufo:form'], 'inet:web:acct')
self.eq(tufo[1]['inet:web:acct'], 'vertex.link/pennywise2')
self.eq(tufo[1]['inet:web:acct:occupation'], 'entertainer')

0 comments on commit d8fd5aa

Please sign in to comment.