Exemple #1
0
	def test_friendship_status_false(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		with app.test_request_context('/xukahecru'):
			request.environ['webid.valid'] = True
			request.environ['webid.uri'] = webid
			app.preprocess_request()
			response = jongau.flask.friends.check_friendship()
			self.assertEqual(403, response[1])
Exemple #2
0
	def test_invalid_friendship_request(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		with app.test_request_context('/cpecru'):
			app.preprocess_request()
			resp = jongau.flask.friends.request_friend()
			self.assertEqual(401, resp[1])
			for rel in ['friends', 'following', 'pending_friends',
				    'pending_following']:
				self.assertEqual([], getattr(jongau.settings, rel))
Exemple #3
0
	def test_friendship_loading_valid(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		with app.test_request_context('/crunoi'):
			request.environ['webid.valid'] = True
			request.environ['webid.uri'] = webid
			app.preprocess_request()
			self.assertTrue(hasattr(g, 'webid'))
			self.assertEqual(webid, g.webid)
			for rel in ['friends', 'following', 'pending_friends',
			            'pending_following']:
				self.assertTrue(hasattr(g, rel))
				self.assertFalse(getattr(g, rel))
Exemple #4
0
	def test_singlekey(self):
		jongau.identity.create_new_key()
		self.assertEqual(1, len(jongau.settings.keys))
		with app.test_request_context('/webid/sevzi'):
			response = jongau.flask.webid.webid_self()
			data = response.get_data()
			graph = rdflib.Graph()
			graph.parse(data=data, format='xml')
			modulus = jongau.settings.keys[0]['modulus']
			self.assertTrue(modulus in data)
			query = 'SELECT ?user WHERE { ?user cert:key ?key . ?key cert:modulus "%s"^^xsd:hexBinary . }' % modulus
			res = graph.query(query, initNs=namespaces)
			self.assertEqual(1, len(res))
Exemple #5
0
	def test_friendship_request(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		with app.test_request_context('/cpecru'):
			request.environ['webid.valid'] = True
			request.environ['webid.uri'] = webid
			app.preprocess_request()
			resp = jongau.flask.friends.request_friend()
			self.assertEqual(200, resp[1])

			for rel in ['friends', 'following', 'pending_friends',
				    'pending_following']:
				if rel == 'pending_friends':
					self.assertEqual([webid], getattr(jongau.settings, rel))
				else:
					self.assertEqual([], getattr(jongau.settings, rel))
Exemple #6
0
	def test_multiplekeys(self):
		jongau.identity.create_new_key()
		jongau.identity.create_new_key()
		self.assertEqual(2, len(jongau.settings.keys))
		with app.test_request_context('/webid/sevzi', headers=[('Accept', 'text/turtle')]):
			response = jongau.flask.webid.webid_self()
			data = response.get_data()
			graph = rdflib.Graph()
			graph.parse(data=data, format='turtle')
			for key in jongau.settings.keys:
				modulus = key['modulus']
				self.assertTrue(modulus in data)
				query = 'SELECT ?user WHERE { ?user cert:key ?key . ?key cert:modulus "%s"^^xsd:hexBinary . }' % modulus
				res = graph.query(query, initNs=namespaces)
				self.assertEqual(1, len(res))
Exemple #7
0
	def test_friendship_status_true(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		jongau.friends.approve_friend(webid)
		self.assertEqual([webid], jongau.settings.friends)
		ping_url = 'http://remote.com/crunoi'
		self.assertEqual(1, len(self.remote_requests))
		self.assertEqual(ping_url, self.remote_requests[0].url)
		with app.test_request_context('/xukahecru'):
			request.environ['webid.valid'] = True
			request.environ['webid.uri'] = webid
			app.preprocess_request()
			response = jongau.flask.friends.check_friendship()
			self.assertEqual(200, response[1])
		jongau.friends.delete_friend(webid)
		self.assertEqual(2, len(self.remote_requests))
		self.assertEqual(ping_url, self.remote_requests[1].url)
		jongau.friends.delete_friend(webid)
		self.assertEqual(3, len(self.remote_requests))
		self.assertEqual(ping_url, self.remote_requests[2].url)
Exemple #8
0
	def test_friendship_loading_statuses(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		for mainrel in ['friends', 'following', 'pending_friends',
		                'pending_following']:
			setattr(jongau.settings, mainrel, [webid])
			if mainrel == 'friends':
				self.assertTrue(jongau.friends.is_friend(webid))
			else:
				self.assertFalse(jongau.friends.is_friend(webid))
			with app.test_request_context('/crunoi'):
				request.environ['webid.valid'] = True
				request.environ['webid.uri'] = webid
				app.preprocess_request()
				self.assertTrue(hasattr(g, 'webid'))
				self.assertEqual(webid, g.webid)
				for rel in ['friends', 'following', 'pending_friends',
					    'pending_following']:
					self.assertTrue(hasattr(g, rel))
					if mainrel == rel:
						self.assertTrue(getattr(g, rel))
					else:
						self.assertFalse(getattr(g, rel))
			setattr(jongau.settings, mainrel, [])
Exemple #9
0
	def test_invalid_friendship_status(self):
		webid = 'http://remote.com/webid/sevzi#subject'
		with app.test_request_context('/xukahecru'):
			app.preprocess_request()
			response = jongau.flask.friends.check_friendship()
			self.assertEqual(401, response[1])
Exemple #10
0
	def test_friendship_loading_invalid(self):
		with app.test_request_context('/crunoi'):
			request.environ['webid.valid'] = False
			app.preprocess_request()
			self.assertFalse(hasattr(g, 'webid'))