Beispiel #1
0
	def setup_sites(self):
		self.clear_db()

		app = App.q.get_by(name="_test")
		try: site = Site.q.get_by(domain='test.example.com')
		except NoData: site = Site.new(name='root', domain='test.example.com', app=app)
		try: site2 = Site.q.get_by(domain='foo.example.com')
		except NoData: site2 = Site.new(name='foo', domain='foo.example.com', parent=site, app=app)
		try: site3 = Site.q.get_by(domain='bar.example.com')
		except NoData: site3 = Site.new(name='bar', domain='bar.example.com', parent=site, app=app)
		try: site21 = Site.q.get_by(domain='foo.foo.example.com')
		except NoData: site21 = Site.new(name='foofoo', domain='foo.foo.example.com', parent=site2, app=app)
		db.session.commit()

		with pytest.raises(ManyData):
			site21a = Site.new(name='foofoo', domain='foo2.foo.example.com', parent=site2)
		db.session.rollback()
		with pytest.raises(ManyData):
			site21a = Site.new(name='foofoo3', domain='foo.foo.example.com', parent=site2)
		db.session.rollback()

		ConfigVar.exists(site,"test1","Test One",-1)
		ConfigVar.exists(site,"test2","Test Two",-2)
		db.session.commit()

		app = create_app(site="root", testing=True)
		app1 = create_app(site="foo", testing=True)
		app2 = create_app(site="bar", testing=True)
		app11 = create_app(site="foofoo", testing=True)

		self.assertEqual(app11.config["test1"],-1)
		self.assertEqual(app11.config["test2"],-2)

		return (app,app1,app2,app11)
Beispiel #2
0
	def test_config(self):
		site = Site.new(name='s2root', domain='test.site2.example.com', app="_test")
		site1 = Site.new(name='s2foo', domain='foo.site2.example.com', parent=site, app="_test")

		n = ConfigVar.q.count()
		v1 = ConfigVar.exists(site,"TEST","testing 123",123)
		v2 = ConfigVar.exists(site,"TEST2","testing 234","234")
		self.assertEqual(ConfigVar.q.count(), n+2)
		v1a = ConfigVar.exists(site,"TEST","testing 123",123)
		assert v1 is v1a
		self.assertEqual(ConfigVar.q.count(), n+2)

		cf = ConfigVar.get(site,"TEST")
		cf2 = ConfigVar.get(site,"TEST2")
		self.assertEquals(cf.value,123)
		self.assertEquals(cf2.value,u"234")
		self.assertEquals(site.config.TEST,123)
		self.assertEquals(site.config.TEST2,"234")

		assert SiteConfigVar.q.filter_by(parent=site.config).count() == 0
		site.config["TEST"] = [12,34]
		assert SiteConfigVar.q.filter_by(parent=site.config).count() == 1
		assert site.config["TEST"] == [12,34]
		assert site1.config["TEST"] == [12,34]
		site1.config["TEST"] = [56,67]
		assert site.config["TEST"] == [12,34]
		assert site1.config["TEST"] == [56,67]
		del site.config["TEST"]
		assert site.config["TEST"] == 123
		assert site1.config["TEST"] == [56,67]

		site1.config["TEST2"] = 987
		assert site1.config["TEST2"] == 987
		assert site.config["TEST2"] == u"234"
		site.config["TEST2"] = u"345"
		assert site1.config["TEST2"] == 987
		assert site.config["TEST2"] == u"345"
		del site1.config["TEST2"]
		assert site1.config["TEST2"] == u"345"
		assert site.config["TEST2"] == u"345"
		del site.config["TEST2"]
		assert site1.config["TEST2"] == u"234"
		assert site.config["TEST2"] == u"234"
		assert site1.config.TEST == [56,67]