def test_read_slices():
  setup(store)
  actual = voting.read_slices("config::snow white","tiddlyvoting")
  
  expected = {"increment.range":u"-5,30","increment.limit":u"2"}
  for i in actual:
    assert i in expected
    assert expected[i] == actual[i]
def test_unauthenticated_user_increments():
  setup(store)
  config['tiddlyweb.usersign']={"name":"GUEST"} 
  config['tiddlyweb.query'] = {"bag":["mr_and_mrs"],"tiddler":["mr strong"]}
  result,code = voting.perform_action(config)
  assert result is False

  try:
    tiddler = store.get(Tiddler("mr strong","mr_and_mrs"))
    value = tiddler.fields["%s.total"%votebag]
  except KeyError:
    value = False  
  assert value == "923"
def test_minmax_votes():
  setup(store)
  config['tiddlyweb.usersign']={"name":"jon"} 
  config['tiddlyweb.query'] = {"bag":["snow white"],"tiddler":["grumpy"]}
  for i in range(-25,10): #the vote cannot exceed 10 in this case
     value = i
     config['tiddlyweb.query']['value'] = ["%s"%value]
     voting.perform_action(config)

  try:
    tiddler = store.get(Tiddler("grumpy","snow white"))
    value = tiddler.fields["%s.total"%votebag]
  except KeyError:
    value = False  
  '''
  the only votes that count bearing in mind the range -5 to 30 for values and the limit of 2 votes per user is -5 and -4 
  '''
  assert value == "-9"
def test_alloweduser_increments():
  setup(store)
  config['tiddlyweb.usersign']={"name":"jon"} 
  config['tiddlyweb.query'] = {"bag":["mr_and_mrs"],"tiddler":["mr strong"]}
  result,code = voting.perform_action(config)
  assert result is True
  
  try:
    tiddler = store.get(Tiddler("mr strong","mr_and_mrs"))
    value = tiddler.fields["%s.total"%votebag]
  except KeyError:
    value = False  
  assert value == "1"
  
  try:
    tiddler = store.get(Tiddler("jon increment mr strong in mr_and_mrs",votebag))
  except NoTiddlerError:
    tiddler = False
  assert tiddler is not False
Esempio n. 5
0
def test_badvalues():
  setup(store)
  config['tiddlyweb.usersign']={"name":"GUEST"} 
  config['tiddlyweb.query'] = {"bag":["films"],"tiddler":["Kill Bill"]}
  config['tiddlyweb.query']['value'] = ["bad bad"]
  status,code=voting.perform_action(config)
  assert code is 5
  assert status is False
  
  config['tiddlyweb.query'] = {"bag":["filmz"],"tiddler":["Kill Bill"]}
  config['tiddlyweb.query']['value'] = ["4"]
  status,code=voting.perform_action(config)
  assert code is 2
  assert status is False

  config['tiddlyweb.query'] = {"bag":["films"],"tiddler":["Kilsl Bill"]}
  status,code=voting.perform_action(config)
  assert code is 6
  assert status is False
def test_vote_log():
  setup(store)
  config['tiddlyweb.usersign']={"name":"jon"} 
  config['tiddlyweb.query'] = {"bag":["mr_and_mrs"],"tiddler":["little miss naughty"]}
  config['tiddlyweb.query']['value'] = ["10"]
  vote1,code1= voting.perform_action(config)
  config['tiddlyweb.query']['value'] = ["14"]
  vote2,code2=voting.perform_action(config)
  #a user then edits the tiddler through another means than tiddlyvoting
  tiddler = store.get(Tiddler("little miss naughty","mr_and_mrs"))
  tiddler.fields['tiddlyvoting.total'] = u"2000000" #very naughty change
  store.put(tiddler) #saves hoping no one will notice

  config['tiddlyweb.query']['value'] = ["-2"]
  vote3,code3= voting.perform_action(config) #on this vote the tiddler corrects itself

  #check all the votes worked..
  assert vote1 is True
  assert vote2 is True
  assert vote3 is True

  try:
    voteLog = store.get(Tiddler("data::little miss naughty in mr_and_mrs","tiddlyvoting"))
    expected = ["-2::1","10::1","14::1","tiddlyvoting.total::22","tiddlyvoting.frequency::3","tiddlyvoting.average::7.33"]
    actual = voteLog.text.split("\n")
    for i in expected:
      assert i in actual
  except NoTiddlerError:
    assert False is True

  try:
    tiddler = store.get(Tiddler("little miss naughty","mr_and_mrs"))
    revision = tiddler.revision
    value = tiddler.fields["tiddlyvoting.total"]
  except KeyError:
    value = False  
    revision = False
  assert revision == 5
  assert value == "22" #the manual edit didn't work
Esempio n. 7
0
def test_rate():
  setup(store)
  config['tiddlyweb.usersign']={"name":"jon"} 
  config['tiddlyweb.query'] = {"bag":["films"],"tiddler":["Jackie Brown"]}
  config['tiddlyweb.query']['value'] = ["1"]
  voting.perform_action(config)
  config['tiddlyweb.query']['value'][0] = "5"
  voting.perform_action(config)
  config['tiddlyweb.query']['value'][0] = "4"
  voting.perform_action(config)
  config['tiddlyweb.query']['value'][0] = "3"
  voting.perform_action(config)
  voting.perform_action(config)
  voting.perform_action(config)  
  jackiebrown = store.get(Tiddler("Jackie Brown","films"))
  assert jackiebrown.fields['tiddlyvoting.total'] == u"19"
  assert jackiebrown.fields['tiddlyvoting.average'] == u"3.17"
  assert jackiebrown.fields['tiddlyvoting.mode'] == u"3"
  assert jackiebrown.modifier == u"Ben"
  
  #make an edit
  newtext = u"new information about jackie brown"
  #user tries to edit values themselves which is not allowed
  jackiebrown.fields['tiddlyvoting.total'] = u"3040"
  jackiebrown.fields['tiddlyvoting.average'] = u"20" 
  jackiebrown.text =newtext
  voting.tiddlyvoting_validator(jackiebrown,config)
  assert jackiebrown.text == newtext
  assert jackiebrown.fields['tiddlyvoting.total'] == u"19"
  assert jackiebrown.fields['tiddlyvoting.average'] == u"3.17"
  
  
  user_rate_log = store.get(Tiddler("jon increment Jackie Brown in films","tiddlyvoting"))
  assert u"tiddlyvotingrecord" in user_rate_log.tags
  assert u"tiddlyvotingdata" not in user_rate_log.tags
  datalog = store.get(Tiddler("data::Jackie Brown in films","tiddlyvoting"))
  textLines = datalog.text.split("\n")
  for i in textLines:
    assert i in [u"1::1",u"5::1",u"3::3",u"4::1",u"tiddlyvoting.frequency::6",u"tiddlyvoting.total::19",u"tiddlyvoting.mode::3",u"tiddlyvoting.average::3.17"]
Esempio n. 8
0
def test_rate_with_floats():
  setup(store)
  config['tiddlyweb.usersign']={"name":"GUEST"} 
  config['tiddlyweb.query'] = {"bag":["films"],"tiddler":["Kill Bill"]}
  config['tiddlyweb.query']['value'] = ["1.4"]
  voting.perform_action(config)
  config['tiddlyweb.query']['value'][0] = "5.2"
  voting.perform_action(config)
  config['tiddlyweb.query']['value'][0] = "4.9"
  voting.perform_action(config)
  config['tiddlyweb.query']['value'][0] = "3.2"
  voting.perform_action(config)
  voting.perform_action(config)
  voting.perform_action(config)  
  result = store.get(Tiddler("Kill Bill","films"))
  assert result.fields['tiddlyvoting.total'] == u"20"
  assert result.fields['tiddlyvoting.average'] == u"3.33"
  assert result.fields['tiddlyvoting.mode'] == u"3"

  datalog = store.get(Tiddler("data::Kill Bill in films","tiddlyvoting"))
  assert u"tiddlyvotingdata" in datalog.tags
  textLines = datalog.text.split("\n")
  for i in [u"1::1",u"5::2",u"3::3",u"tiddlyvoting.frequency::6",u"tiddlyvoting.total::20"]:
    assert i in textLines
def test_multiple_votes():
  '''
  test 1  no limit
  
  '''
  setup(store)
  config['tiddlyweb.usersign']={"name":"jon"} 
  config['tiddlyweb.query'] = {"bag":["mr_and_mrs"],"tiddler":["mr small"]}
  for i in range(1,5): #there are no rules saying how big the vote can be used on this bag
    value = i * 10
    config['tiddlyweb.query']['value'] = ["%s"%value]
    voting.perform_action(config)
    
  try:
    tiddler = store.get(Tiddler("mr small","mr_and_mrs"))
    value = tiddler.fields["%s.total"%votebag]
  except KeyError:
    value = False  
  '''
  no limit in this bag so all 5 votes count
  votes = (1 * 10) + (2*10) + (3*10) + (4*10)
  = 10 + 20 + 30 + 40 = 100
  '''
  assert value == "100" 
  
  try:
    tiddler = store.get(Tiddler("jon increment mr small in mr_and_mrs",votebag))
    assert tiddler.revision == 4
  except NoTiddlerError:
    tiddler = False
  assert tiddler is not False
  
  '''
  test 2
  max 2 votes
  '''
  config['tiddlyweb.usersign']={"name":"jon"} 
  config['tiddlyweb.query'] = {"bag":["snow white"],"tiddler":["grumpy"]}
  for i in range(1,5): #the vote cannot exceed 10 in this case
     value = (i*10)
     config['tiddlyweb.query']['value'] = ["%s"%value]
     voting.perform_action(config)

  try:
    tiddler = store.get(Tiddler("grumpy","snow white"))
    value = tiddler.fields["%s.total"%votebag]
  except KeyError:
    value = False  
  '''
  votes = (1 * 10) + (2*10) + (3*10) + (4*10)
  = 10 + 20 + 30 + 40 = 100
  but a max 2 votes per user so only 10+  20 count
  '''
  assert value == "30" 

  try:
    tiddler = store.get(Tiddler("jon increment grumpy in snow white",votebag))
    assert tiddler.revision == 2
  except NoTiddlerError:
    tiddler = False
  assert tiddler is not False