Пример #1
0
    def process(self, commit, *args, **kwargs):
        data = commit.data

        try:
            erc20d = ERC20D.objects.get(id=data["contractAddress"])

            claimFrom = erc20d.claimers.get(id=data["from"])
            claimTo = erc20d.claimers.get(id=data["to"])

            new_claimedFrom = int(claimFrom.claimedAmount) - int(
                data.get("value"))
            new_claimedTo = int(claimTo.claimedAmount) + int(data.get("value"))

            claimFrom.claimedAmount = str(new_claimedFrom)
            claimFrom.claimedAmount = str(new_claimedTo)

            commit.save()
            erc20d.save()
        except ERC20D.DoesNotExist:
            self.logger.warning("ERC20D with address {} does not exist".format(
                data["contractAddress"]))
        except Claim.DoesNotExist:
            claimer = Claim()
            claimer.lender = data["to"]
            claimer.claimed_amount = data["value"]
            erc20d.claimers.append(claimer)

            commit.save()
            erc20d.save()
Пример #2
0
def add_claim(claimant_information, employee_record):
    with contextlib.closing(make_session()) as session:
        claim = Claim()
        claim.employer_id = employee_record.get('employer_id', None)
        claim.claimant_information = json_encode(claimant_information)
        claim.employee_record = json_encode(employee_record)
        session.add(claim)
        session.commit()
        return claim.claim_id
Пример #3
0
    def post(self):
        x = int(self.request.get('x'))
        y = int(self.request.get('y'))
        currentdaytime = datetime.today()

        query = Claim.gql("WHERE x = :1 AND y = :2", x, y)
        Claim_itterator = query.iter(produce_cursors=True)

        for claim in Claim_itterator:
            query2 = UserData.gql("WHERE user = :1", claim.user)
            thisUser = query2.get()
            if thisUser.lastemail < currentdaytime - timedelta(1):
                message = mail.EmailMessage()
                message.sender = ("http://infinitegraffitiwall.appspot.com/ " +
                    "Tile Claim Service <*****@*****.**>")
                message.to = claim.user.email()
                message.subject = ("A Tile that you have claimed " +
                    "has been changed today.")
                message.body = ("""
A Tile that you have claimed has been changed today.
Tile coordinates """ + str(x) + "," + str(y) + """.
Link to location: http://infinitegraffitiwall.appspot.com/@""" +
                    str(x) + "," + str(y))
                message.send()
                thisUser.lastemail = currentdaytime
                thisUser.put()
Пример #4
0
    def post(self):
        user = users.get_current_user()
        x = int(self.request.get('x'))
        y = int(self.request.get('y'))

        if user is not None:
            #Check if tile is already claimed by this user
            query = Claim.gql("WHERE user = :1 AND x = :2 AND y = :3",
                user, x, y)
            thisClaim = query.get()
            if thisClaim is None:
                thisClaim = Claim(user=user, x=x, y=y)
                query2 = UserData.gql("WHERE user = :1", user)
                thisUser = query2.get()
                thisUser.Number_Tiles = thisUser.Number_Tiles + 1
                thisUser.put()
                thisClaim.put()
Пример #5
0
    def get(self):
        user = users.get_current_user()
        x = int(self.request.get('x'))
        y = int(self.request.get('y'))

        query = Claim.gql("WHERE user = :1 AND x = :2 AND y = :3", user, x, y)
        HasClaimOnTile = query.get()
        if HasClaimOnTile is None:
            HasClaim = 0
        else:
            HasClaim = 1
        self.response.write(HasClaim)
Пример #6
0
    def post(self):
        user = users.get_current_user()
        x = int(self.request.get('x'))
        y = int(self.request.get('y'))

        if user is not None:
            #Get the tile claim for this user
            query = Claim.gql("WHERE user = :1 AND x = :2 AND y = :3",
                user, x, y)
            thisClaim = query.get()
            if thisClaim is not None:
                thisClaim.key.delete()
                query2 = UserData.gql("WHERE user = :1", user)
                thisUser = query2.get()
                thisUser.Number_Tiles = thisUser.Number_Tiles - 1
                thisUser.put()
Пример #7
0
 def post(self, registry):
     viewer = self.registry_view_authorized(registry)
     if not viewer or viewer == 'anonymous_user':
         return self.redirect_to('registry-verify',
                                 registry_name=registry.registry_name)
     for id, num_claimed in self.request.POST.iteritems():
         try:
             parsed_id = int(id)
             parsed_num_claimed = int(num_claimed)
         except ValueError:
             continue
         entry = RegistryEntry.get_by_id(parsed_id, parent=registry.key)
         if entry and entry.num_claimed_by(viewer) != parsed_num_claimed:
             try:
                 claim = next(c for c in entry.claims if c.viewer == viewer)
                 claim.num = parsed_num_claimed
             except StopIteration:
                 entry.claims.append(
                     Claim(viewer=viewer, num=parsed_num_claimed))
             entry.put()
     return self.redirect_to('registry-view',
                             registry_name=registry.registry_name)
Пример #8
0
    def get(self):
        #Assure that the user is logged in
        #There is no way of mocking the user servise
        #As the system that google app engine provides deos not work
        user = users.get_current_user()
        if user:
            self.testbed = testbed.Testbed()
            self.testapp = webtest.TestApp(app)
            #activates the testbed (Used for creating face DB and blobstore)
            #Swaps the fake systems in for the real systems
            #Should make this only work offline
            self.testbed.activate()

            #Initializes the fake blobstore and datastore
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            ##########################
            # MainPage Unit Testing
            ##########################

            AllParts = 0

            #Unit test for MainPage (MainPage_test1)
            #Checks to assure that the main page can load
            try:
                response = self.testapp.get('/')
                MainPage_test1 = "<font color=green>Passed</font>"

                #Unit test for MainPage (MainPage_test3)
                #Checks to assure that the page has a section "wall"
                try:
                    response.mustcontain('<section id="wall">')
                    MainPage_test3 = "<font color=green>Passed</font>"
                    AllParts = AllParts + 1
                except:
                    MainPage_test3 = ("<font color=red>Failed, the main " +
                        "page did not contain a section with ID wall.</font>")

                #Unit test for MainPage (MainPage_test4)
                #Checks to assure that the page has the directional scrolling divs
                try:
                    response.mustcontain('<div id="left">')
                    response.mustcontain('<div id="right">')
                    response.mustcontain('<div id="top">')
                    response.mustcontain('<div id="bottom">')
                    response.mustcontain('<div id="top_left">')
                    response.mustcontain('<div id="top_right">')
                    response.mustcontain('<div id="bottom_left">')
                    response.mustcontain('<div id="bottom_right">')
                    MainPage_test4 = "<font color=green>Passed</font>"
                    AllParts = AllParts + 1
                except:
                    MainPage_test4 = ("<font color=red>Failed, the main page " +
                        "did not contain a section with ID wall.</font>")

                #Unit test for MainPage (MainPage_test2)
                #Checks to assure that the page has the specified sections
                if AllParts == 2:
                    MainPage_test2 = "<font color=green>Passed</font>"
                else:
                    MainPage_test2 = ("<font color=red>Failed, this is " +
                        "not the page as it was intended..</font>")

            except:
                MainPage_test1 = ("<font color=red>Failed, the main page " +
                    "did not respond at all.</font>")
                MainPage_test3 = ("<font color=red>Can't be run " +
                    "if test 1 fails.</font>")

            #Unit test for MainPage (MainPage_test4)
            #Check to assure that the random tile  is retrieved correctly
        
            #Creating fake tile to test tile reading
            with open("UnitTestTile.png", "rb") as image_file:
                imageFile = image_file.read()
        
            image_file.close()
        
            blob_key = 'TestBlobkey'

            self.testbed.get_stub('blobstore').CreateBlob(blob_key, imageFile)
        
            #rand_num=1 to be always selected in a random selection
            Tile(x=-12, y=-1, blob_key=blobstore.BlobKey(blob_key), rand_num=1).put()

            try:
                response = self.testapp.get('/')
                try:
                    response.mustcontain('<input id="locX" type="hidden" value="-12">')
                    response.mustcontain(
                        '<input id="locY" type="hidden" value="-1">')
                    MainPage_test5 = "<font color=green>Passed</font>"
                except:
                    MainPage_test5 = ("<font color=red> The start location " +
                        "was not correct. </font>")
            except:
                MainPage_test5 = ("<font color=red> The location based page " +
                    "failed to load. </font>")

            ##########################
            # GetTile Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            #Creating fake tile to test tile reading
            with open("UnitTestTile.png", "rb") as image_file:
                imageFile = image_file.read()

            image_file.close()

            with open("UnitTestTile2.png", "rb") as image_file2:
                imageFile2 = image_file2.read()
            image_file2.close()

            blob_key = 'TestBlobkey'

            self.testbed.get_stub('blobstore').CreateBlob(blob_key, imageFile)

            Tile(x=0, y=0, blob_key=blobstore.BlobKey(blob_key),
                rand_num=random.random()).put()

            params = {'x': 0, 'y': 0}

            #Unit test for get tile (GetTile_test1)
            #Checks to assure that the file can load at all
            try:
                response = self.testapp.get('/tile', params)
                GetTile_test1 = "<font color=green>Passed</font>"

                #Unit test for get tile (GetTile_test2)
                #Checks to assure that the file can load correctly
                try:
                    response.mustcontain(imageFile)
                    GetTile_test2 = "<font color=green>Passed</font>"
                except:
                    GetTile_test2 = ("<font color=red>Failed, the " +
                        "response did not contain the test image file</font>")

                #Unit test for get tile (GetTile_test3)
                #Checks to assure that the mach in test 1 is not erroneous
                try:
                    response.mustcontain(imageFile2)
                    GetTile_test3 = ("<font color=red>Failed, the tile " +
                        "retrieved does not correspond to the tile put in.</font>")
                except:
                    GetTile_test3 = "<font color=green>Passed</font>"
            except:
                GetTile_test1 = ("<font color=red>Failed, there was no " +
                    "response from the mock database.</font>")
                GetTile_test2 = ("<font color=red>Can't be run " +
                    "if test 1 fails.</font>")
                GetTile_test3 = GetTile_test2

            #Unit test for get tile (GetTile_test4)
            #Checks to assure that a tile that does not
            #exist in the database does not load
            params = {'x': 0, 'y': 1}

            try:
                self.testapp.get('/tile', params)
                GetTile_test4 = ("<font color=red>The load did not " +
                    "fail as it was intended to</font>")
            except:
                GetTile_test4 = "<font color=green>Passed</font>"

            ##########################
            # SaveTile Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            #We can't actualy create an object in the test bed Datastore
            with open("UnitTestTile.png", "rb") as image_file:
                imageFile = base64.b64encode(image_file.read())

            image_file.close()

            #The perameters to create a blob at x=0,y=0
            params = {'x': 0, 'y': 0, 'data': imageFile}

            #Test if there is even a responce from /save 
            try:
                response = self.testapp.post('/save', params)
                if response.status_int == 200:
                    #test to see if the created tile actualy exists
                    query = Tile.gql("WHERE x = :1 AND y = :2", 0, 0)
                    myTile = query.get()
                    if myTile is None:
                        SaveTile_test1 = ("<font color=red>The tile data could not be retrieved from the database.</font>")
                        SaveTile_test2 = ("<font color=red>Test 2 requires test 1 to succeed.</font>")
                    else:
                        SaveTile_test1 = ("<font color=green>Passed</font>")
                        oldblobkey = myTile.blob_key
                        try:
                            response = self.testapp.post('/save', params)
                            if response.status_int == 200:
                                query = Tile.gql("WHERE x = :1 AND y = :2", 0, 0)
                                myTile = query.get()
                                if myTile.blob_key == oldblobkey:
                                    SaveTile_test2 = ("<font color=red>The tile was not replaced.</font>")
                                else:
                                    SaveTile_test2 = ("<font color=green>Passed</font>")
                            else:
                                SaveTile_test2 = ("<font color=red>/save did not return a 200 responce.</font>")
                        except:
                            SaveTile_test1 = ("<font color=red>Failed, there was no " + "response from SaveTile.</font>")
                else:
                    SaveTile_test1 = ("<font color=red>/save did not return a 200 responce.</font>")
                    SaveTile_test2 = ("<font color=red>Test 2 requires test 1 to succeed.</font>")
            except:
                SaveTile_test1 = ("<font color=red>Failed, there was no " +
                "response from SaveTile.</font>")
                SaveTile_test2 = ("<font color=red>Test 2 requires test 1 to succeed.</font>")

            ##########################
            # UserTileClaimNumber Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            #Check if the system can handle a user who has not been entered yet
            try:
                response = self.testapp.get('/howmenytiles')
                query = UserData.gql("WHERE user = :1", user)
                thisUserData = query.get()
                if thisUserData is None:
                    UserTileClaimNumber_test1 = ("<font color=red>The new user information was not created in the database.</font>")
                else:
                    if thisUserData.Number_Tiles == 0:
                        UserTileClaimNumber_test1 = ("<font color=green>Passed</font>")
                    else:
                        UserTileClaimNumber_test1 = ("<font color=red>UserTileClaimNumber did not create a user information with 0 tiles claimed.</font>")
            except:
                UserTileClaimNumber_test1 = ("<font color=red>Failed, there was no response from UserTileClaimNumber.</font>")

            #Reinitializes the fake datastore for the next test
            self.testbed.init_datastore_v3_stub()
            
            #Assure data about users is retrieved correctly
            day_time = datetime.today() - timedelta(1)
            UserData(user=user, lastemail=day_time, Number_Tiles=6).put()
            try:
                response = self.testapp.get('/howmenytiles')
                try:
                    #Check if the correct number of tiles information was contianed in the resoponce
                    response.mustcontain(6)
                    UserTileClaimNumber_test2 = ("<font color=green>Passed</font>")
                except:
                    UserTileClaimNumber_test2 = ("<font color=red>The correct number of tiles was not returned.</font>")
            except:
                UserTileClaimNumber_test2 = ("<font color=red>Failed, there was no response from UserTileClaimNumber.</font>")

            ##########################
            # CreateClaim Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            params = {'x': 0, 'y': 0}
            day_time = datetime.today() - timedelta(1)
            UserData(user=user, lastemail=day_time, Number_Tiles=0).put()
            
            try:
                response = self.testapp.post('/claim', params)
                try:
                    query = Claim.gql("WHERE user = :1", user)
                    thisClaimData = query.get()
                    if thisClaimData is not None:
                        CreateClaim_test1 = ("<font color=green>Passed</font>")
                        query = Claim.gql("WHERE user = :1 AND x=:2 AND y=:3", user, 0, 0)
                        thisClaimData2 = query.get()
                        if thisClaimData2 is not None:
                            CreateClaim_test2 = ("<font color=green>Passed</font>")
                        else:
                            CreateClaim_test2 = ("<font color=red>The correct database claim did not exist.</font>")
                    else:
                        CreateClaim_test1 = ("<font color=red>Failed, no claim created for the given user.</font>")
                        CreateClaim_test2 = ("<font color=red>Test1 must succeed for test 2 to run.</font>")
                except:
                    CreateClaim_test1 = ("<font color=red>Failed, database error.</font>")
                    CreateClaim_test2 = ("<font color=red>Test1 must succeed for test 2 to run.</font>")
            except:
                CreateClaim_test1 = ("<font color=red>Failed, there was no response from CreateClaim.</font>")
                CreateClaim_test2 = ("<font color=red>Test1 must succeed for test 2 to run.</font>")

            ##########################
            # InformClaimOwner Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()
            #For this test we need to check if we are sending mail.
            self.testbed.init_mail_stub()
            self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)

            params = {'x': 0, 'y': 0}
            #Create a fake user with 1 tile claimed
            day_time = datetime.today() - timedelta(1)
            UserData(user=user, lastemail=day_time, Number_Tiles=1).put()
            Claim(user=user, x=0, y=0).put()
            
            try:
                response = self.testapp.post('/informclaim', params)
                
                messages = self.mail_stub.get_sent_messages(to=user.email())
                if len(messages) == 1:
                    InformClaimOwner_test1 = ("<font color=green>Passed</font>")
                    try:
                        response = self.testapp.post('/informclaim', params)
                        
                        messages = self.mail_stub.get_sent_messages(to=user.email())
                        if len(messages) == 1:
                            InformClaimOwner_test2 = ("<font color=green>Passed</font>")
                        else:
                            InformClaimOwner_test2 = ("<font color=red>Failed, a second message was sent on the same day.</font>")
                    except:
                        InformClaimOwner_test2 = ("<font color=red>Failed, there was no response from InformClaimOwner.</font>")
                else:
                    InformClaimOwner_test1 = ("<font color=red>Failed, the informing email was not sent to the target user.</font>")
                    InformClaimOwner_test2  = ("<font color=red>Test 2 requires test 1 to succeed.</font>")
                    
            except:
                InformClaimOwner_test1 = ("<font color=red>Failed, there was no response from InformClaimOwner.</font>")
                InformClaimOwner_test2  = ("<font color=red>Test 2 requires test 1 to succeed.</font>")

            ##########################
            # RemoveClaim Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            params = {'x': 0, 'y': 0}
            #Create a fake user with 1 tile claimed
            day_time = datetime.today() - timedelta(1)
            UserData(user=user, lastemail=day_time, Number_Tiles=1).put()
            Claim(user=user, x=0, y=0).put()

            try:
                response = self.testapp.post('/unclaim', params)
                query = Claim.gql("WHERE user = :1 AND x=:2 AND y=:3", user, 0, 0)
                thisClaimData = query.get()
                if thisClaimData is None:
                    RemoveClaim_test1 = ("<font color=green>Passed</font>")
                else:
                    RemoveClaim_test1 = ("<font color=red> The claim was not removed.</font>")
            except:
                RemoveClaim_test1 = ("<font color=red>Failed, there was no response from RemoveClaim.</font>")
            
            try:
                query = UserData.gql("WHERE user = :1", user)
                thisUserData = query.get()
                if thisUserData.Number_Tiles == 0:
                    RemoveClaim_test2 = ("<font color=green>Passed</font>")
                else:
                    RemoveClaim_test2 = ("<font color=red>Failed, The user's Number_Tiles was not decremented correctly.</font>")
            except:
                RemoveClaim_test2 = ("<font color=red>Failed, there was no response from the mock database.</font>")

            ##########################
            # TileClaimedByUser Unit Testing
            ##########################

            #Reinitializes the fake blobstore and datastore for the next test
            self.testbed.init_blobstore_stub()
            self.testbed.init_datastore_v3_stub()

            params = {'x': 0, 'y': 0}
            #Create a fake user with 1 tile claimed
            day_time = datetime.today() - timedelta(1)
            UserData(user=user, lastemail=day_time, Number_Tiles=1).put()
            Claim(user=user, x=0, y=0).put()

            try:
                response = self.testapp.get('/hasclaimontile', params)
                try:
                    response.mustcontain(1)
                    TileClaimedByUser_test1 = ("<font color=green>Passed</font>")
                except:
                    TileClaimedByUser_test1 = ("<font color=red>Failed, did not detect user's claim.</font>")
            except:
                TileClaimedByUser_test1 = ("<font color=red>Failed, there was no response from TileClaimedByUser.</font>")

            params = {'x': 1, 'y': 0}
            try:
                response = self.testapp.get('/hasclaimontile', params)
                try:
                    response.mustcontain(0)
                    TileClaimedByUser_test2 = ("<font color=green>Passed</font>")
                except:
                    TileClaimedByUser_test2 = ("<font color=red>Failed, did not detect user's claim.</font>")
            except:
                TileClaimedByUser_test2 = ("<font color=red>Failed, there was no response from TileClaimedByUser.</font>")

            #Swaps the real systems back in,
            #and deactivates the fake testing system.
            self.testbed.deactivate()

            template = jinja_environment.get_template('PYUnitTest.html')
            self.response.out.write(template.render(
                MainPage_test1=MainPage_test1,
                MainPage_test2=MainPage_test2,
                MainPage_test3=MainPage_test3,
                MainPage_test4=MainPage_test4,
                MainPage_test5=MainPage_test5,
                GetTile_test1=GetTile_test1,
                GetTile_test2=GetTile_test2,
                GetTile_test3=GetTile_test3,
                GetTile_test4=GetTile_test4,
                SaveTile_test1=SaveTile_test1,
                SaveTile_test2=SaveTile_test2,
                UserTileClaimNumber_test1=UserTileClaimNumber_test1,
                UserTileClaimNumber_test2=UserTileClaimNumber_test2,
                CreateClaim_test1=CreateClaim_test1,
                CreateClaim_test2=CreateClaim_test2,
                InformClaimOwner_test1=InformClaimOwner_test1,
                InformClaimOwner_test2=InformClaimOwner_test2,
                RemoveClaim_test1=RemoveClaim_test1,
                RemoveClaim_test2=RemoveClaim_test2,
                TileClaimedByUser_test1=TileClaimedByUser_test1,
                TileClaimedByUser_test2=TileClaimedByUser_test2
            ))
        else:
            #If not, show login button
            template = jinja_environment.get_template('PYUnitTestLogin.html')
            self.response.out.write(template.render())