<commit_before>import unittest
import random

from gremlinpy import Gremlin
from gizmo import Mapper, Request, Collection, Vertex, Edge
from gizmo.mapper import _GenericMapper


class BaseTests(unittest.TestCase):

    def setUp(self):
        self.request = Request('localhost', 'gizmo_testing', port=8182)
        self.gremlin = Gremlin('gizmo_testing')
        self.mapper = Mapper(self.request, self.gremlin, logger=False)

        super(BaseTests, self).setUp()

    def tearDown(self):
        script = "%s.V().map{it.get().remove()}" % self.gremlin.gv
        self.mapper.query(script=script)
        super(BaseTests, self).tearDown()


class ConnectionTests(BaseTests):

    def test_can_establish_mapper(self):
        c = '%s.V()' % self.gremlin.gv
        r = self.mapper.query(script=c)

        self.assertEqual(0, len(r))

    def test_can_send_request_and_retrieve_collection_objec(self):
        script = 'a = 1'
        r = self.mapper.query(script=script)

        self.assertIsInstance(r, Collection)
        self.assertIsInstance(r[0], Vertex)

    def test_can_get_database_time(self):
        script = 'def x = new Date(); x'
        r = self.mapper.query(script=script)

        self.assertTrue(r[0]['response'] != '')
        self.assertIsInstance(r[0]['response'], int)

    def test_can_send_math_equation_to_server_and_retrieve_genderic_vertex_with_respnose_to_result(self):
        script = 'b = 1 + 1;'
        r = self.mapper.query(script=script)
        r1 = r[0]

        self.assertIsInstance(r1, Vertex)
        self.assertIn('response', r1.data)
        self.assertEqual(2, r1['response'])


class EntityTests(BaseTests):

    def entity_save_assertions(self, entity):
        from gizmo import GIZMO_MODEL, GIZMO_CREATED, GIZMO_MODIFIED, \
            GIZMO_ID, GIZMO_LABEL

        empty = ['', None]
        fields = [GIZMO_MODEL, GIZMO_CREATED, GIZMO_MODIFIED, \
            GIZMO_ID, GIZMO_LABEL]

        for f in fields:
            self.assertIsNotNone(entity[f])
            self.assertNotIn(entity[f], empty)

    def test_can_save_generic_vertex_and_update_its_id(self):
        data = {'name': 'mark', 'sex': 'male'}
        v = self.mapper.create_model(data=data)

        self.mapper.save(v).send()
        self.entity_save_assertions(v)

    def test_can_save_generic_vertex_and_get_response_entity_with_id(self):<commit_msg>updated zero checking during testing<commit_after>import unittest
import random

from gremlinpy import Gremlin
from gizmo import Mapper, Request, Collection, Vertex, Edge
from gizmo.mapper import _GenericMapper


class BaseTests(unittest.TestCase):

    def setUp(self):
        self.request = Request('localhost', 'gizmo_testing', port=8182)
        self.gremlin = Gremlin('gizmo_testing')
        self.mapper = Mapper(self.request, self.gremlin, logger=False)

        super(BaseTests, self).setUp()

    def tearDown(self):
        script = "%s.V().map{it.get().remove()}" % self.gremlin.gv
        self.mapper.query(script=script)
        super(BaseTests, self).tearDown()


class ConnectionTests(BaseTests):

    def test_can_establish_mapper(self):
        c = '%s.V()' % self.gremlin.gv
        r = self.mapper.query(script=c)

        self.assertEqual(0, len(r))

    def test_can_send_request_and_retrieve_collection_objec(self):
        script = 'a = 1'
        r = self.mapper.query(script=script)

        self.assertIsInstance(r, Collection)
        self.assertIsInstance(r[0], Vertex)

    def test_can_get_database_time(self):
        script = 'def x = new Date(); x'
        r = self.mapper.query(script=script)

        self.assertTrue(r[0]['response'] != '')
        self.assertIsInstance(r[0]['response'], int)

    def test_can_send_math_equation_to_server_and_retrieve_genderic_vertex_with_respnose_to_result(self):
        script = 'b = 1 + 1;'
        r = self.mapper.query(script=script)
        r1 = r[0]

        self.assertIsInstance(r1, Vertex)
        self.assertIn('response', r1.data)
        self.assertEqual(2, r1['response'])


class EntityTests(BaseTests):

    def entity_save_assertions(self, entity):
        from gizmo import GIZMO_MODEL, GIZMO_CREATED, GIZMO_MODIFIED, \
            GIZMO_ID, GIZMO_LABEL

        empty = ['', 0, None]
        non_zero = ['', None]
        fields = [GIZMO_MODEL, GIZMO_CREATED, GIZMO_MODIFIED, \
            GIZMO_ID, GIZMO_LABEL]

        for f in fields:
            if f is GIZMO_ID:
                check = non_zero
            else:
                check = empty

            self.assertIsNotNone(entity[f])
            self.assertNotIn(entity[f], check)

    def test_can_save_generic_vertex_and_update_its_id(self):
        data = {'name': 'mark', 'sex': 'male'}
        v = self.mapper.create_model(data=data)

        self.mapper.save(v).send()
        self.entity_save_assertions(v)

    def test_can_save_generic_vertex_and_get_response_entity_with_id(self):
{'fraction_non_alphanumeric': 0.1165107767385116, 'fraction_numerical': 0.0071167141114274095, 'mean_word_length': 2.9862236628849272, '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': '4535738', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1635, 'n_words': 287}