Esempio n. 1
0
 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)
Esempio n. 2
0
 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))
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
    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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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)
Esempio n. 12
0
    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')
Esempio n. 13
0
    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')
Esempio n. 14
0
 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))
Esempio n. 15
0
 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)