def member_list_no_vote_times(): ml = Global.current_member_list() if ml is None: ml = makeTestMemberList(None, False) Global.set_current_member_list(ml) db.session.commit() return ml
def test_invalid_vote_old(bare_session, proposal_vote_result): return # disabled, see 276ee5935eedbded9a474957a2e0e3db649e40bc for reason pvr = proposal_vote_result newml = makeTestMemberList(Global.current_member_list()) Global.set_current_member_list(newml) pvb = proposal_vote_ballot(pvr) with pytest.raises(ValidationError): proposal_vote_result.cast(pvb, "buip-acc-rej-abs", "accept")
def test1(bare_session): ml = makeTestMemberList(None) ml.set_current() # only formatting of action is tested, not content a = makeTestAction(author=ml.members[0], apart = (ml.hashref()+" proposal-upload file %s by member_b" % zero256))
def test_invalid_old(bare_session, member_list, member_a, member_election_result): assert member_a.eligible() mer = member_election_result newml = makeTestMemberList(Global.current_member_list()) Global.set_current_member_list(newml) with pytest.raises(ValidationError): mer.cast(member_ballot(), "member-vote-acc-rej-abs", "")
def test_invalid_newml(bare_session, member_list, member_a): newml = makeTestMemberList(Global.current_member_list()) Global.set_current_member_list(newml) # invalid action string (not current member list) action_string = config.action_prefix+member_list.hashref() privkey = bitcoin.sha256(member_a.name) signature = bitcoin.ecdsa_sign(action_string, privkey) with pytest.raises(ValidationError): Action(member_a, action_string, signature)
def small_app(): """ Flask app and session, only pre-filled with default initial member list. """ import serve app, db = serve.make_app(test_mode_internal=True) from test_tmemberlist import makeTestMemberList ml = makeTestMemberList(None) ml.set_current() db.session.add(ml) db.session.commit() return app
def test_scenario_invalid1(bare_session): """ Test invalid action type """ ml = makeTestMemberList(None) ml.set_current() proposal1 = b"Test proposal #1" hashprop1 = hashlib.sha256(proposal1).hexdigest() du = DummyUpload("test_proposal_1.txt", "text/plain") with pytest.raises(ValidationError): act_upload_invalid = makeTestAction( author=Member.by_name("member_a"), apart=(ml.hashref() + " proposal-download file %s by member_a" % hashprop1)) act_upload_invalid.apply(None, None)
def test_invalid_scenario2(bare_session): """ Test (invalid) two votes on one proposal. """ ml = makeTestMemberList(None) ml.set_current() proposal1 = b"Test proposal #1" hashprop1 = hashlib.sha256(proposal1).hexdigest() du = DummyUpload("test_proposal_1.txt", "text/plain") act_upload = makeTestAction( author=Member.by_name("member_a"), apart=(ml.hashref() + " proposal-upload file %s by member_a" % hashprop1)) act_upload.apply(du, proposal1) rf = RawFile.by_hash(hashprop1) act_publish = makeTestAction( author=Member.by_name("member_v"), apart= (ml.hashref() + " proposal-publish file %s designation BUIP0001 title 'title BUIP0001' by member_v" % hashprop1)) act_publish.apply(None, None) act_open_vote = makeTestAction( author=Member.by_name("member_v"), apart=( ml.hashref() + " open-proposal-vote meta %s by member_v method (buip-acc-rej-abs)" % (rf.proposal_metadata.hashref()))) vote = act_open_vote.apply(None, None) with pytest.raises(ValidationError): act_open_vote2 = makeTestAction( author=Member.by_name("member_v"), apart= (ml.hashref() + " open-proposal-vote meta %s by member_v method (buip-acc-rej-abs)" % (rf.proposal_metadata.hashref()))) act_open_vote2.apply(None, None)
def member_list(): ml = Global.current_member_list() if ml is None: ml = makeTestMemberList(None) Global.set_current_member_list(ml) return ml
def test_scenario1(bare_session, stopper=""): old_ml = makeTestMemberList(None) # dummy old member list ml = makeTestMemberList(old_ml) ml.set_current() proposal1 = b"Test proposal #1" hashprop1 = hashlib.sha256(proposal1).hexdigest() du = DummyUpload("test_proposal_1.txt", "text/plain") act_upload = makeTestAction( author=Member.by_name("member_a"), apart=(ml.hashref() + " proposal-upload file %s by member_a" % hashprop1), pgp=True) act_upload.apply(du, proposal1) proposal2 = b"Test proposal #2" hashprop2 = hashlib.sha256(proposal2).hexdigest() du = DummyUpload("test_proposal_2.txt", "text/plain") act_upload = makeTestAction( author=Member.by_name("member_b"), apart=(ml.hashref() + " proposal-upload file %s by member_b" % hashprop2), pgp=True) act_upload.apply(du, proposal2) if stopper == "two-unpublished": return rf = RawFile.by_hash(hashprop1) m1 = rf.proposal_metadata act_publish = makeTestAction( author=Member.by_name("member_v"), apart= (ml.hashref() + " proposal-publish file %s designation BUIP0001 title 'some annoyingly long title for BUIP0001 to test the proper formatting in all templates' by member_v" % hashprop1)) act_publish.apply(None, None) if stopper == "one-published": return act_open_vote = makeTestAction( author=Member.by_name("member_v"), apart=( ml.hashref() + " open-proposal-vote meta %s by member_v method (buip-acc-rej-abs)" % (rf.proposal_metadata.hashref()))) vote = act_open_vote.apply(None, None) if stopper == "open-proposal-vote": return vote vdeps = vote.dependencies() assert len(vdeps) == 4 assert rf in vdeps assert rf.proposal_metadata in vdeps assert act_open_vote in vdeps assert vote.result in vdeps for i, x in enumerate("abcdefghijklmnopqrstu"): if i < 10: answer = "accept" else: answer = "reject" act_cast_vote = makeTestAction( author=Member.by_name("member_%s" % x), apart=(ml.hashref() + " cast-proposal-ballot vote %s by member_%s answer (%s)" % (vote.hashref(), x, answer))) act_cast_vote.apply(None, None) if stopper == "votes-cast": return act_close_vote = makeTestAction( author=Member.by_name("member_v"), apart=(ml.hashref() + " close-proposal-vote result %s by member_v" % (vote.result.hashref()))) act_close_vote.apply(None, None) act_new_member = makeTestAction( author=Member.by_name("member_v"), apart=(ml.hashref() + " propose-member name newmember1 address %s by member_v" % (makeTestKey("newmember1")[1]))) act_new_member.apply(None, None) act_new_member = makeTestAction( author=Member.by_name("member_v"), apart=(ml.hashref() + " propose-member name newmember2 address %s by member_v" % (makeTestKey("newmember2")[1]))) act_new_member.apply(None, None) act_new_member = makeTestAction( author=Member.by_name("member_v"), apart=(ml.hashref() + " propose-member name newmember3 address %s by member_v" % (makeTestKey("newmember3")[1]))) act_new_member.apply(None, None) if stopper == "new-applicants": return for i, x in enumerate("abcdefghijklmnopq"): ans = ["accept", "reject"][i & 1] act_new_member_cast = makeTestAction( author=Member.by_name("member_%s" % x), apart= (ml.hashref() + " cast-member-ballot name newmember1 address %s by member_%s answer %s" % ((makeTestKey("newmember1")[1], x, ans)))) act_new_member_cast.apply(None, None) if stopper == "votes-on-applicant": return act_close_member_elections = makeTestAction( author=Member.by_name("member_v"), apart= (ml.hashref() + " close-member-elections all [newmember1 newmember2 newmember3] by member_v" )) act_close_member_elections.apply(None, None) assert Global.current_member_list() != ml assert Member.by_name("newmember1") in Global.current_member_list().members