<commit_before>import unittest
import six

from . import settings
from .data import valid_data
from .data import invalid_data
from craftai.client import CraftAIClient
from craftai import errors as craft_err


class TestCreateAgentSuccess(unittest.TestCase):
    """Checks that the client succeeds when creating an agent with OK input"""

    @classmethod
    def setUpClass(self):
        self.client = CraftAIClient(settings.CRAFT_CFG)

    def setUp(self):
        # Makes sure that no agent with the same ID already exists
        self.client.delete_agent(valid_data.VALID_ID)

    def test_create_agent_with_generated_agent_id(self):
        """create_agent should succeed when given an empty `id` field

        It should give a proper JSON response with `id` and
        `model` fields being strings.
        """
        resp = self.client.create_agent(valid_data.VALID_MODEL)
        self.assertIsInstance(resp.get("id"), six.string_types)

    def test_create_agent_given_agent_id(self):
        """create_agent should succeed when given a string ID

        It should give a proper JSON response with `id` and
        `model` fields being strings and `id` being the same as the one
        given as a parameter.
        """
        resp = self.client.create_agent(
            valid_data.VALID_MODEL,
            valid_data.VALID_ID)
        self.assertEqual(resp.get("id"), valid_data.VALID_ID)


class TestCreateAgentFailure(unittest.TestCase):
    """Checks that the client fails when creating an agent with bad input"""

    @classmethod
    def setUpClass(self):
        self.client = CraftAIClient(settings.CRAFT_CFG)

    def setUp(self):
        # Makes sure that no agent with the same ID already exists
        self.client.delete_agent(valid_data.VALID_ID)

    def test_create_agent_with_invalid_given_agent_id(self):
        """create_agent should fail when given a non-string/empty string ID

        It should raise an error upon request for creation of
        an agent with an ID that is not of type string, since agent IDs
        should always be strings.
        """
        for inv_id in invalid_data.INVALID_IDS:
            self.assertRaises(
                craft_err.CraftAIBadRequestError,
                self.client.create_agent,
                valid_data.VALID_MODEL,
                invalid_data.INVALID_IDS[inv_id])<commit_msg>Added cleanUp for create_agent() test to make sure no test agent remains<commit_after>import unittest
import six

from . import settings
from .data import valid_data
from .data import invalid_data
from craftai.client import CraftAIClient
from craftai import errors as craft_err


class TestCreateAgentSuccess(unittest.TestCase):
    """Checks that the client succeeds when creating an agent with OK input"""

    @classmethod
    def setUpClass(self):
        self.client = CraftAIClient(settings.CRAFT_CFG)

    def setUp(self):
        # Makes sure that no agent with the same ID already exists
        self.client.delete_agent(valid_data.VALID_ID)

    def clean_up_agent(self, aid):
        # Makes sure that no agent with the standard ID remains
        self.client.delete_agent(aid)

    def test_create_agent_with_generated_agent_id(self):
        """create_agent should succeed when given an empty `id` field

        It should give a proper JSON response with `id` and
        `model` fields being strings.
        """
        resp = self.client.create_agent(valid_data.VALID_MODEL)
        self.assertIsInstance(resp.get("id"), six.string_types)
        self.addCleanup(self.clean_up_agent, resp.get("id"))

    def test_create_agent_given_agent_id(self):
        """create_agent should succeed when given a string ID

        It should give a proper JSON response with `id` and
        `model` fields being strings and `id` being the same as the one
        given as a parameter.
        """
        resp = self.client.create_agent(
            valid_data.VALID_MODEL,
            valid_data.VALID_ID)
        self.assertEqual(resp.get("id"), valid_data.VALID_ID)
        self.addCleanup(self.clean_up_agent, valid_data.VALID_ID)


class TestCreateAgentFailure(unittest.TestCase):
    """Checks that the client fails when creating an agent with bad input"""

    @classmethod
    def setUpClass(self):
        self.client = CraftAIClient(settings.CRAFT_CFG)

    def setUp(self):
        # Makes sure that no agent with the same ID already exists
        self.client.delete_agent(valid_data.VALID_ID)

    def test_create_agent_with_invalid_given_agent_id(self):
        """create_agent should fail when given a non-string/empty string ID

        It should raise an error upon request for creation of
        an agent with an ID that is not of type string, since agent IDs
        should always be strings.
        """
        for inv_id in invalid_data.INVALID_IDS:
            self.assertRaises(
                craft_err.CraftAIBadRequestError,
                self.client.create_agent,
                valid_data.VALID_MODEL,
                invalid_data.INVALID_IDS[inv_id])
{'fraction_non_alphanumeric': 0.06741795175958877, 'fraction_numerical': 0.0, 'mean_word_length': 2.850076103500761, 'pattern_counts': {'":': 0, '<': 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': '4862540', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1381, 'n_words': 448}