<commit_before>#! /usr/bin/env python3

import config

config.import_libs()

import unittest
import json

from rest import GET, POST, DELETE, PUT

class TestLocationGetUpdate(unittest.TestCase):
	"""
	Create a session for testing.
	"""
	def setUp(self):
		req = POST(config.ui_host, config.ui_port, "/auth")
		req.body(config.PERMIT_LOGIN)
		response, content = req()

		self.assertEqual(200, response.status)

		result = json.loads(content)
		self.assertEqual("success", result["status"])

		self.session = result["data"]["id"]

		req = POST(config.ui_host, config.ui_port, "/gateways")
		req.authorize(self.session)
		req.body(json.dumps(
			{"id": config.gateway_id, "name": "Testing Gateway"}
		))
		response, _ = req()

		if response.status != 403:
			self.assertEqual(201, response.status)

	"""
	Update existing location
	"""
	def test2_get_and_update(self):
		req = GET(config.ui_host, config.ui_port, "/gateways/" + config.gateway_id + "/locations")
		req.authorize(self.session)
		response, content = req()

		result = json.loads(content)
<commit_msg>t: restui: fix missing tearDown() for locations<commit_after>#! /usr/bin/env python3

import config

config.import_libs()

import unittest
import json

from rest import GET, POST, DELETE, PUT

class TestLocationGetUpdate(unittest.TestCase):
	"""
	Create a session for testing.
	"""
	def setUp(self):
		req = POST(config.ui_host, config.ui_port, "/auth")
		req.body(config.PERMIT_LOGIN)
		response, content = req()

		self.assertEqual(200, response.status)

		result = json.loads(content)
		self.assertEqual("success", result["status"])

		self.session = result["data"]["id"]

		req = POST(config.ui_host, config.ui_port, "/gateways")
		req.authorize(self.session)
		req.body(json.dumps(
			{"id": config.gateway_id, "name": "Testing Gateway"}
		))
		response, _ = req()

		if response.status != 403:
			self.assertEqual(201, response.status)

	def tearDown(self):
		req = DELETE(config.ui_host, config.ui_port, "/gateways/" + config.gateway_id)
		req.authorize(self.session)
		response, content = req()

		self.assertEqual(204, response.status)

		req = DELETE(config.ui_host, config.ui_port, "/auth")
		req.authorize(self.session)
		response, content = req()

		self.assertEqual(204, response.status)

	"""
	Update existing location
	"""
	def test2_get_and_update(self):
		req = GET(config.ui_host, config.ui_port, "/gateways/" + config.gateway_id + "/locations")
		req.authorize(self.session)
		response, content = req()

		result = json.loads(content)

{'fraction_non_alphanumeric': 0.1478537360890302, 'fraction_numerical': 0.011128775834658187, 'mean_word_length': 4.544052863436123, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6805856', 'n_tokens_mistral': 951, 'n_tokens_neox': 860, 'n_words': 183}