def test_urchin(self): """ When an Urchin API key is present, the code for enabling Google Analytics tracking should be inserted into the shell template. """ keyString = u"UA-99018-11" APIKey.setKeyForAPI(self.siteStore, APIKey.URCHIN, keyString) page = self.createPage(None) t = div() result = page.render_urchin(context.WebContext(tag=t), None) self.assertEqual(result.slotData['urchin-key'], keyString)
def test_getKeyForAPIExisting(self): """ If there is an existing key for the named API, L{APIKey.getKeyForAPI} should return it. """ theAPIName = u'this is an API name.' existingAPIKey = APIKey(store=self.store, apiName=theAPIName, apiKey=u'this is an API key.') self.assertIdentical(existingAPIKey, APIKey.getKeyForAPI(self.store, theAPIName))
def test_urchin(self): """ When an Urchin API key is present, the code for enabling Google Analytics tracking should be inserted into the shell template. """ keyString = u"UA-99018-11" APIKey.setKeyForAPI(self.siteStore, APIKey.URCHIN, keyString) page = self.createPage(None) t = div() result = page.render_urchin(context.WebContext(tag=t), None) self.assertEqual(result.slotData["urchin-key"], keyString)
def test_setKeyForAPIExisting(self): """ If there is an existing for the named API, L{APIKey.setKeyForAPI} should update its I{apiKey} attribute. """ theAPIKey = u'this is an API key.' theAPIName = u'this is an API name.' existingAPIKey = APIKey(store=self.store, apiName=theAPIName, apiKey=theAPIKey) newAPIKey = u'this is a new API key' returnedAPIKey = APIKey.setKeyForAPI(self.store, theAPIName, newAPIKey) self.assertIdentical(existingAPIKey, returnedAPIKey) self.assertEqual(existingAPIKey.apiName, theAPIName) self.assertEqual(existingAPIKey.apiKey, newAPIKey)
def test_getKeyForAPINone(self): """ If there is no existing key for the named API, L{APIKey.getKeyForAPI} should return C{None}. """ self.assertIdentical( APIKey.getKeyForAPI(self.store, u'this is an API name.'), None)
def postOptions(self): siteStore = self.parent.getStore() # Make sure the base mantissa offering is installed. offeringTech = ixmantissa.IOfferingTechnician(siteStore) offerings = offeringTech.getInstalledOfferingNames() if baseOffering.name not in offerings: raise UsageError( "This command can only be used on Mantissa databases.") # It is, we can make some simplifying assumptions. Specifically, # there is exactly one SiteConfiguration installed. site = siteStore.findUnique(SiteConfiguration) if self['http-log'] is not None: if self['http-log']: site.httpLog = siteStore.filesdir.preauthChild( self['http-log']) else: site.httpLog = None if self['hostname'] is not None: if self['hostname']: site.hostname = self.decodeCommandLine(self['hostname']) else: raise UsageError("Hostname may not be empty.") if self['urchin-key'] is not None: # Install the API key for Google Analytics, to enable tracking for # this site. APIKey.setKeyForAPI( siteStore, APIKey.URCHIN, self['urchin-key'].decode('ascii')) # Set up whatever static content was requested. for webPath, filePath in self.staticPaths: staticSite = siteStore.findFirst( StaticSite, StaticSite.prefixURL == webPath) if staticSite is not None: staticSite.staticContentPath = filePath else: staticSite = StaticSite( store=siteStore, staticContentPath=filePath, prefixURL=webPath, sessionless=True) onlyInstallPowerups(staticSite, siteStore)
def render_urchin(self, ctx, data): """ Render the code for recording Google Analytics statistics, if so configured. """ key = APIKey.getKeyForAPI(self._siteStore(), APIKey.URCHIN) if key is None: return '' return ctx.tag.fillSlots('urchin-key', key.apiKey)
def test_setKeyForAPINew(self): """ If there is no existing key for the named API, L{APIKey.setKeyForAPI} should create a new L{APIKey} item. """ theAPIKey = u'this is an API key.' theAPIName = u'this is an API name.' apiKey = APIKey.setKeyForAPI(self.store, theAPIName, theAPIKey) self.assertIdentical(apiKey, self.store.findUnique(APIKey)) self.assertEqual(theAPIKey, apiKey.apiKey) self.assertEqual(theAPIName, apiKey.apiName)
def test_setKeyForAPINew(self): """ If there is no existing key for the named API, L{APIKey.setKeyForAPI} should create a new L{APIKey} item. """ theAPIKey = u'this is an API key.' theAPIName = u'this is an API name.' apiKey = APIKey.setKeyForAPI( self.store, theAPIName, theAPIKey) self.assertIdentical(apiKey, self.store.findUnique(APIKey)) self.assertEqual(theAPIKey, apiKey.apiKey) self.assertEqual(theAPIName, apiKey.apiName)
def test_urchinKey(self): """ Specifying a Google Analytics key inserts an item into the database recording it. """ opt = webcmd.WebConfiguration() opt.parent = self opt['urchin-key'] = 'A123' opt.postOptions() self.assertEquals(APIKey.getKeyForAPI(self.store, APIKey.URCHIN).apiKey, u'A123')
def test_urchinKey(self): """ Specifying a Google Analytics key inserts an item into the database recording it. """ opt = webcmd.WebConfiguration() opt.parent = self opt['urchin-key'] = 'A123' opt.postOptions() self.assertEquals( APIKey.getKeyForAPI(self.store, APIKey.URCHIN).apiKey, u'A123')
def test_getKeyForAPIExisting(self): """ If there is an existing key for the named API, L{APIKey.getKeyForAPI} should return it. """ theAPIName = u'this is an API name.' existingAPIKey = APIKey( store=self.store, apiName=theAPIName, apiKey=u'this is an API key.') self.assertIdentical( existingAPIKey, APIKey.getKeyForAPI(self.store, theAPIName))
def test_setKeyForAPIExisting(self): """ If there is an existing for the named API, L{APIKey.setKeyForAPI} should update its I{apiKey} attribute. """ theAPIKey = u'this is an API key.' theAPIName = u'this is an API name.' existingAPIKey = APIKey( store=self.store, apiName=theAPIName, apiKey=theAPIKey) newAPIKey = u'this is a new API key' returnedAPIKey = APIKey.setKeyForAPI( self.store, theAPIName, newAPIKey) self.assertIdentical(existingAPIKey, returnedAPIKey) self.assertEqual(existingAPIKey.apiName, theAPIName) self.assertEqual(existingAPIKey.apiKey, newAPIKey)