Esempio n. 1
0
 def test_SearchNotFound(self):
     searchTerm = "asdfasdflkj324;l1kjasd13214aasdf341l324"
     self.req = getRequestHandleCookie(iPediaFields.search, searchTerm)
     self.getResponse([
         iPediaFields.transactionId, iPediaFields.cookie,
         iPediaFields.notFound
     ])
Esempio n. 2
0
 def test_GetArticleCount(self):
     self.req = getRequestHandleCookie(iPediaFields.getArticleCount, None)
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.articleCount])
     count = int(self.rsp.getField(iPediaFields.articleCount))
     # hard to guarantee to always have 100.000 but should be true given that
     # on 7-7-2004 it was 300.000+
     self.assertEqual(count>100000,True)
Esempio n. 3
0
 def test_VerifyInvalidRegCode(self):
     self.req = getRequestHandleCookie(iPediaFields.verifyRegCode,
                                       invalidRegCodeNumber)
     self.getResponse([
         iPediaFields.cookie, iPediaFields.transactionId,
         iPediaFields.regCodeValid
     ])
     self.assertFieldEqual(self.rsp, iPediaFields.regCodeValid, 0)
Esempio n. 4
0
 def test_NotFound(self):
     # Ok, so I can't really guarantee that a article with this title doesn't exist
     # but this is a really good guess
     self.req = getRequestHandleCookie(
         iPediaFields.getArticle, "asdfasdflkj324;l1kjasd13214aasdf341l324")
     self.getResponse([
         iPediaFields.transactionId, iPediaFields.cookie,
         iPediaFields.notFound
     ])
Esempio n. 5
0
 def test_GetDatabaseTime(self):
     self.req = getRequestHandleCookie(iPediaFields.getDatabaseTime, None)
     self.getResponse([
         iPediaFields.transactionId, iPediaFields.cookie,
         iPediaFields.databaseTime
     ])
     # date is in format YYYYMMDD
     date = self.rsp.getField(iPediaFields.databaseTime)
     assert 8 == len(date)
Esempio n. 6
0
 def test_SearchSeattle(self):
     searchTerm = "seattle"
     self.req = getRequestHandleCookie(iPediaFields.search, searchTerm)
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.articleTitle,iPediaFields.searchResults])
     self.assertFieldEqual(self.rsp,iPediaFields.articleTitle,searchTerm)
     count = searchResultsCount(self.rsp.getField(iPediaFields.searchResults))
     #print "search result count: '%d'" % count
     # hard to establish the exact number but 100 should be good (when checked
     # for 7-7-2004 database, it was 201
     self.assertEqual(count > 100,True)
Esempio n. 7
0
 def test_GetArticleCount(self):
     self.req = getRequestHandleCookie(iPediaFields.getArticleCount, None)
     self.getResponse([
         iPediaFields.transactionId, iPediaFields.cookie,
         iPediaFields.articleCount
     ])
     count = int(self.rsp.getField(iPediaFields.articleCount))
     # hard to guarantee to always have 100.000 but should be true given that
     # on 7-7-2004 it was 300.000+
     self.assertEqual(count > 100000, True)
Esempio n. 8
0
 def test_GetSeattle(self):
     title = "seattle"
     self.req = getRequestHandleCookie(iPediaFields.getArticle, title)
     self.getResponse([
         iPediaFields.transactionId, iPediaFields.cookie,
         iPediaFields.formatVersion, iPediaFields.articleBody,
         iPediaFields.articleTitle, iPediaFields.reverseLinks
     ])
     self.assertFieldEqual(self.rsp, iPediaFields.formatVersion,
                           DEFINITION_FORMAT_VERSION)
Esempio n. 9
0
def fValidTestOk(test):
    global g_errors, g_testNumbers

    testNo = test[0]
    if g_testNumbers.has_key(testNo):
        print "Duplicate test number: %d" % testNo
        sys.exit(0)
    else:
        g_testNumbers[
            testNo] = 1  # can be anything, we only use it to test if the entry exists

    fieldsToSend = test[1]
    assert isinstance(fieldsToSend, list)
    expectedResultFields = test[2]
    assert 0 == len(fieldsToSend) % 2
    req = getRequestHandleCookie()
    fieldsCount = len(fieldsToSend) / 2
    for fieldNo in range(fieldsCount):
        fieldName = fieldsToSend[fieldNo * 2]
        fieldValue = fieldsToSend[fieldNo * 2 + 1]
        req.addField(fieldName, fieldValue)
    rsp = Response(req)
    client.handleCookie(rsp)
    errorsTxt = []

    if not rsp.hasField(Fields.transactionId):
        errorsTxt.append("Field %s missing" % Fields.transactionId)
    else:
        tridGot = rsp.getFieldShort(Fields.transactionId)
        tridSent = req.transactionId
        if tridGot != tridSent:
            errorsTxt.append("Sent transactionId %s but got %s" %
                             (tridSent, tridGot))
    for fieldName in expectedResultFields:
        if isinstance(fieldName, list):
            assert 2 == len(fieldName)
            fieldValue = fieldName[1]
            fieldName = fieldName[0]
            if not rsp.hasField(fieldName):
                errorsTxt.append("Field %s missing" % fieldName)
            else:
                if fieldValue != rsp.getFieldShort(fieldName):
                    errorsTxt.append(
                        "Field %s value is different, expected: %s, got: %s" %
                        (fieldName, fieldValue, rsp.getFieldShort(fieldName)))
        else:
            if not rsp.hasField(fieldName):
                errorsTxt.append("Field %s missing" % fieldName)
    if len(errorsTxt) > 0:
        errorsTxt.append("Full request:\n'%s'" % req.getText())
        errorsTxt.append("Full response:\n'%s'" % rsp.getShortText())
        g_errors[testNo] = errorsTxt
        return False
    else:
        return True
Esempio n. 10
0
 def verifyArgument(self, field, fRequiresArguments):
     self.req = getRequestHandleCookie()
     # do the exact opposite of what's expected
     if fRequiresArguments:
         self.req.addField(field, None)
     else:
         self.req.addField(field, "not needed argument")
     self.getResponse([Fields.error, Fields.transactionId])
     if fRequiresArguments:
         self.assertError(ServerErrors.requestArgumentMissing)
     else:
         self.assertError(ServerErrors.unexpectedRequestArgument)
Esempio n. 11
0
 def verifyArgument(self, field, fRequiresArguments):
     self.req = getRequestHandleCookie()
     # do the exact opposite of what's expected
     if fRequiresArguments:
         self.req.addField(field, None)
     else:
         self.req.addField(field, "not needed argument")
     self.getResponse([iPediaFields.error,iPediaFields.transactionId])
     if fRequiresArguments:
         self.assertError(ServerErrors.requestArgumentMissing)
     else:
         self.assertError(ServerErrors.unexpectedRequestArgument)
Esempio n. 12
0
 def test_SearchSeattle(self):
     searchTerm = "seattle"
     self.req = getRequestHandleCookie(iPediaFields.search, searchTerm)
     self.getResponse([
         iPediaFields.transactionId, iPediaFields.cookie,
         iPediaFields.articleTitle, iPediaFields.searchResults
     ])
     self.assertFieldEqual(self.rsp, iPediaFields.articleTitle, searchTerm)
     count = searchResultsCount(
         self.rsp.getField(iPediaFields.searchResults))
     #print "search result count: '%d'" % count
     # hard to establish the exact number but 100 should be good (when checked
     # for 7-7-2004 database, it was 201
     self.assertEqual(count > 100, True)
Esempio n. 13
0
 def test_ExtraArgument(self):
     self.req = getRequestHandleCookie()
     # Get-Random-Article doesn't require an argument, but we're sending it
     self.req.addField(iPediaFields.getRandom, "not needed")
     self.getResponse([iPediaFields.error, iPediaFields.transactionId])
     self.assertError(ServerErrors.unexpectedRequestArgument)
Esempio n. 14
0
 def prepareTvListingsProviders(self, zipCode):
     self.req = getRequestHandleCookie(Fields.getTvListingsProviders,
                                       zipCode)
Esempio n. 15
0
 def test_GetDatabaseTime(self):
     self.req = getRequestHandleCookie(iPediaFields.getDatabaseTime, None)
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.databaseTime])
     # date is in format YYYYMMDD
     date = self.rsp.getField(iPediaFields.databaseTime)
     assert 8==len(date)
Esempio n. 16
0
 def prepare411PersonSearch(self, query):
     self.req = getRequestHandleCookie(Fields.get411PersonSearch, query)
Esempio n. 17
0
 def test_Ping(self):
     # this is the simplest valid requests - only sends transaction id
     # in response server sends the same transaction id
     self.req = getRequestHandleCookie()
     self.getResponse([iPediaFields.cookie,iPediaFields.transactionId])
Esempio n. 18
0
 def prepareWeather(self, location):
     self.req = getRequestHandleCookie(Fields.getWeather, location)
Esempio n. 19
0
 def prepareJokesList(self, query):
     self.req = getRequestHandleCookie(Fields.getJokesList, query)
Esempio n. 20
0
 def test_GetCookieGivesRegCode(self):
     self.req = getRequestHandleCookie(iPediaFields.regCode, testValidRegCode)
     self.getResponse([iPediaFields.transactionId,iPediaFields.error])
     self.assertError(ServerErrors.malformedRequest)
Esempio n. 21
0
 def test_GetSeattle(self):
     title = "seattle"
     self.req = getRequestHandleCookie(iPediaFields.getArticle, title)
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.formatVersion,iPediaFields.articleBody,iPediaFields.articleTitle,iPediaFields.reverseLinks])
     self.assertFieldEqual(self.rsp, iPediaFields.formatVersion, DEFINITION_FORMAT_VERSION)
Esempio n. 22
0
 def reqWithCookie(self,fieldName,fieldValue):
     self.req = getRequestHandleCookie(fieldName,fieldValue)
Esempio n. 23
0
 def test_NotFound(self):
     # Ok, so I can't really guarantee that a article with this title doesn't exist
     # but this is a really good guess
     self.req = getRequestHandleCookie(iPediaFields.getArticle, "asdfasdflkj324;l1kjasd13214aasdf341l324")
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.notFound])
Esempio n. 24
0
 def test_ExtraArgument(self):
     self.req = getRequestHandleCookie()
     # Get-Random-Article doesn't require an argument, but we're sending it
     self.req.addField(iPediaFields.getRandom, "not needed")
     self.getResponse([iPediaFields.error,iPediaFields.transactionId])
     self.assertError(ServerErrors.unexpectedRequestArgument)
Esempio n. 25
0
 def test_MissingArgument(self):
     self.req = getRequestHandleCookie()
     # Get-Cookie requires an argument but we're not sending it
     self.req.addField(iPediaFields.getCookie, None)
     self.getResponse([iPediaFields.error,iPediaFields.transactionId])
     self.assertError(ServerErrors.requestArgumentMissing)
Esempio n. 26
0
 def test_MalformedRequest(self):
     self.req = getRequestHandleCookie()
     # malformed, because there is no ":"
     self.req.addLine("malformed\n")
     self.getResponse([iPediaFields.error,iPediaFields.transactionId])
     self.assertError(ServerErrors.malformedRequest)
Esempio n. 27
0
 def test_GetCookieGivesCookie(self):
     self.req = getRequestHandleCookie(iPediaFields.cookie, "I'm a cookie")
     self.getResponse([iPediaFields.transactionId,iPediaFields.error])
     self.assertError(ServerErrors.malformedRequest)
Esempio n. 28
0
 def prepare411International(self, query):
     self.req = getRequestHandleCookie(Fields.get411InternationalCodeSearch,
                                       query)
Esempio n. 29
0
 def prepareRecipe(self, query):
     self.req = getRequestHandleCookie(Fields.getRecipe, query)
Esempio n. 30
0
 def prepare411ReverseZip(self, query):
     self.req = getRequestHandleCookie(Fields.get411ReverseZip, query)
Esempio n. 31
0
 def prepareDream(self, dream):
     self.req = getRequestHandleCookie(Fields.getDream, dream)
Esempio n. 32
0
 def prepareStocksListValidateLast(self, query):
     self.req = getRequestHandleCookie(Fields.getStocksListValidateLast,
                                       query)
Esempio n. 33
0
 def prepareJoke(self, url):
     self.req = getRequestHandleCookie(Fields.getJoke, url)
Esempio n. 34
0
 def prepareAmazonBrowse(self, url):
     self.req = getRequestHandleCookie(Fields.getAmazonBrowse, url)
Esempio n. 35
0
 def prepare411BusinessSearch(self, query):
     self.req = getRequestHandleCookie(Fields.get411BusinessSearch, query)
Esempio n. 36
0
 def test_DuplicateField(self):
     self.req = getRequestHandleCookie(iPediaFields.getArticleCount, None)
     self.req.addField(iPediaFields.getArticleCount, None)
     self.getResponse([iPediaFields.transactionId])
     self.assertError(ServerErrors.malformedRequest)
Esempio n. 37
0
 def prepare411ZipByCity(self, query):
     self.req = getRequestHandleCookie(Fields.get411ZipByCity, query)
Esempio n. 38
0
 def test_Random(self):
     self.req = getRequestHandleCookie(iPediaFields.getRandom, None)
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.articleTitle,iPediaFields.formatVersion])
Esempio n. 39
0
 def prepareCurrencies(self):
     self.req = getRequestHandleCookie(Fields.getCurrencyConversion)
Esempio n. 40
0
 def test_Ping(self):
     # this is the simplest valid requests - only sends transaction id
     # in response server sends the same transaction id
     self.req = getRequestHandleCookie()
     self.getResponse([Fields.cookie, Fields.transactionId])
Esempio n. 41
0
 def prepareStock(self, url):
     self.req = getRequestHandleCookie(Fields.getStock, url)
Esempio n. 42
0
 def test_VerifyInvalidRegCode(self):
     self.req = getRequestHandleCookie(iPediaFields.verifyRegCode, invalidRegCodeNumber)
     self.getResponse([iPediaFields.cookie,iPediaFields.transactionId,iPediaFields.regCodeValid])
     self.assertFieldEqual(self.rsp,iPediaFields.regCodeValid,0)
Esempio n. 43
0
 def prepareHoroscope(self, query):
     self.req = getRequestHandleCookie(Fields.getHoroscope, query)
Esempio n. 44
0
 def test_DuplicateField(self):
     self.req = getRequestHandleCookie(iPediaFields.getArticleCount, None)
     self.req.addField(iPediaFields.getArticleCount, None)
     self.getResponse([iPediaFields.transactionId])
     self.assertError(ServerErrors.malformedRequest)
Esempio n. 45
0
 def test_MissingArgument(self):
     self.req = getRequestHandleCookie()
     # Get-Cookie requires an argument but we're not sending it
     self.req.addField(iPediaFields.getCookie, None)
     self.getResponse([iPediaFields.error, iPediaFields.transactionId])
     self.assertError(ServerErrors.requestArgumentMissing)
Esempio n. 46
0
 def test_SearchNotFound(self):
     searchTerm = "asdfasdflkj324;l1kjasd13214aasdf341l324"
     self.req = getRequestHandleCookie(iPediaFields.search, searchTerm)
     self.getResponse([iPediaFields.transactionId,iPediaFields.cookie,iPediaFields.notFound])
Esempio n. 47
0
 def test_MalformedRequest(self):
     self.req = getRequestHandleCookie()
     # malformed, because there is no ":"
     self.req.addLine("malformed\n")
     self.getResponse([Fields.error, Fields.transactionId])
     self.assertError(ServerErrors.malformedRequest)
Esempio n. 48
0
 def test_UnrecognizedField(self):
     self.req = getRequestHandleCookie("Foo", "blast")
     self.getResponse([iPediaFields.error,iPediaFields.transactionId])
     self.assertError(ServerErrors.invalidRequest)