def test_voteForProposal(self):
        _domain = Domain(
            title = self._testDomainName,
            description = self._testDomainName,
        ).put()

        domain = Domain.get_by_id(_domain.id())

        self.assertTrue(domain.key().id() is not None, 'Domain ID is None')

        _proposal = Proposal(
            name = self._testProposalName,
            description = 'DESCRIPTION OF ' + self._testProposalName,
            technologiesUsed = 'TECHNOLOGIES USER IN ' + self._testProposalName,
            status = 'OPEN',
            domain = _domain
        )

        self.getProposalService().saveProposal(_proposal)

        self.assertIsNotNone(_proposal, 'Proposal is None')

        self.getVoteService().VoteForProposal(_proposal.key().id(), self._voteTypeLabelG, self._backerEmail)

        self.assertTrue(_proposal.votes.count() > 0, 'Proposal has no votes')

        _voteFound = False
        for v in _proposal.votes:
            if v.voteType.label == VoteTypeEnum.GOLD:
                _voteFound = True

        self.assertTrue(_voteFound, 'Failed to vote for proposal')

        self.reportResult(message='PASS')
    def test_createNewProposal(self):
        _domain = Domain(
            title = self._testDomainName,
            description = self._testDomainName,
        ).put()

        domain = Domain.get_by_id(_domain.id())

        self.assertIsNotNone(domain.key().id(), 'Domain ID is None')

        _proposal = Proposal(
            name = self._testProposalName,
            description = 'DESCRIPTION OF ' + self._testProposalName,
            technologiesUsed = 'TECHNOLOGIES USER IN ' + self._testProposalName,
            status = 'OPEN',
            domain = _domain
        )

        self.getProposalService().saveProposal(_proposal)

        self.assertIsNotNone(_proposal.key().id(), 'Proposal ID is None')
        self.assertIsNotNone(_proposal.domain, 'Proposal\'s Domain is None')

        self.assertTrue(_proposal.name == self._testProposalName, 'Fetched Proposal not matching the expected value')

        self.reportResult(message='PASS')
Example #3
0
    def updateDomain(self, domainId, domainTitle, domainDescription, domainStatus):
        _domain = Domain.get_by_id(domainId)

        if domainTitle is not None:
            _domain.title = domainTitle

        if domainDescription is not None:
            _domain.description = domainDescription

        if domainStatus is not None:
            _domain.status = domainStatus

        Domain.save(_domain)
    def GetProposalsByDomainAndStatus(self, domainId, status):
        result = db.Model()
        try:
            domain = Domain.get_by_id(int(domainId))
            result = Proposal.gql("WHERE status = :pStatus AND domain=:pDomain", pStatus=status, pDomain=domain)
        except Exception as e:
            exception = e

        return result
    def test_withdrawVote(self):
        self.reportResult(message='Starting test_withdrawVote')

        _domain = Domain(
            title = self._testDomainName,
            description = self._testDomainName,
        ).put()

        domain = Domain.get_by_id(_domain.id())

        self.assertTrue(domain.key().id() is not None, 'Domain ID is None')

        _proposal = Proposal(
            name = self._testProposalName,
            description = 'DESCRIPTION OF ' + self._testProposalName,
            technologiesUsed = 'TECHNOLOGIES USER IN ' + self._testProposalName,
            status = 'OPEN',
            domain = _domain
        )

        _backer = self._backerService.GetBackerByEmail(self._backerEmail)

        self.getProposalService().saveProposal(_proposal)

        self.assertIsNotNone(_proposal, 'Proposal is None')

        self.getVoteService().VoteForProposal(_proposal.key().id(), self._voteTypeLabelS, self._backerEmail)

        self.assertTrue(_proposal.votes.count() > 0, 'Proposal has no votes')

        _voteId = db.GqlQuery("SELECT __key__ FROM Vote WHERE proposal = :pProposal AND backer = :pBacker AND voteType = :pVoteType",
            pProposal = _proposal,
            pBacker   = _backer,
            pVoteType = VoteTypeUtil.GetVoteTypeByLabel(self._voteTypeLabelS)
        ).get().id()

        self.assertIsNotNone(_voteId, 'Vote is None')

        self.getVoteService().WithdrawVote(_voteId, self._backerEmail)

        self.assertTrue(_proposal.votes.count() == 0, 'Failed to withdraw vote')

        self.reportResult(message='PASS')
    def test_getProposalsByStatusClosed(self):
        _domain = Domain(
            title = self._testDomainName,
            description = self._testDomainName,
        ).put()

        domain = Domain.get_by_id(_domain.id())

        Proposal(
            name = self._testProposalName,
            description = 'DESCRIPTION OF ' + self._testProposalName,
            technologiesUsed = 'TECHNOLOGIES USER IN ' + self._testProposalName,
            status = 'OPEN',
            domain = domain
        ).put()

        _proposals = self.getProposalService().GetProposalsByDomainAndStatus(domain.key().id(), 'CLOSED')

        self.assertIsNotNone(_proposals, 'No Proposals found')

        self.assertTrue(_proposals.count() == 0, 'Found 1 or more proposals (expected 0)')

        self.reportResult(message='PASS')
Example #7
0
def toProposal(jsonStr):
    jsonDict = json.loads(jsonStr)

    proposal = None

    if jsonDict.has_key('domain') and jsonDict['domain'].has_key('id'):
        domainId = jsonDict['domain']['id']

        if domainId:
            # Construct a proposal object, giving it the required domain
            domain = Domain.get_by_id(int(domainId))
            proposal = Proposal(domain = domain)

            # Delete the domain attribute, as we have already set the domain to the proposal
            jsonDict.pop('domain')

            # Set basic values
            for name, value in jsonDict.iteritems():
                setattr(proposal, name, value)

    return proposal
Example #8
0
 def GetDomainsByStatus(self, domainStatus):
     result = Domain.gql("WHERE status = '" + domainStatus +"'")
     return result