Пример #1
0
    def test_addOperation3(self):
        ''' tests add Operation with full data'''

        lat = 48.856613
        lng = 2.352222

        # the user who make this operation
        userPublicId = Users.query.filter_by(name='admin').first().public_id

        # the object this operation point to
        age = getAge()
        addPerson(name='mustafa', ageId=age[0].id, gender='male')
        person = Person.query.first()

        type = Type_operation.query.filter_by(name='lost').first()
        status = Status_operation.query.filter_by(name='active').first()
        country = Country.query.first()

        # this long details string
        details = 'this long details string about the person'

        result = addOperation(type=type, status=status, country=country, object=person,\
              userPublicId= userPublicId, date=datetime.datetime.now(), lat=lat, lng=lng,
              details=details, city='cairo', state='ciro')

        operation = Operations.query.first()

        self.assertTrue(operation)
        self.assertEqual(operation.details, details, 'not the same details')
        self.assertEqual(float(operation.lat), lat, 'not the same lat')
        self.assertEqual(float(operation.lng), lng, 'not the same lng')
        self.assertEqual(operation.object.name, person.name,
                         'not the same person name')
Пример #2
0
    def test_updateOperation(self):
        ''' tests the update operation func'''

        # first add new operation

        # the user who make this operation
        userPublicId = Users.query.filter_by(name='admin').first().public_id
        age = getAge()[0]

        # the object this operation point to
        addPerson(name='mustafa', gender='male', ageId=age.id)
        person = Person.query.first()

        type = Type_operation.query.filter_by(name='lost').first()
        status = Status_operation.query.filter_by(name='active').first()
        country = Country.query.first()

        result = addOperation(type=type, status=status, country=country, object=person,\
              userPublicId= userPublicId, date=datetime.datetime.now())

        operation = Operations.query.first()
        self.assertTrue(operation, 'add new operation Failed')

        # now change operation status
        newStatus = Status_operation.query.filter_by(name='closed').first()

        result = updateOperationStatus(operationId=operation.id,
                                       newStatus=newStatus.name)

        self.assertTrue(result, 'change not success')

        # now check the opration status
        self.assertEqual(operation.status.name, newStatus.name,
                         'operatuin status not changed')
Пример #3
0
    def test_addComment(self):
        ''' add operation then add comments to it'''

        # first add the operation
        #

        userPublicId = Users.query.filter_by(name='admin').first().public_id
        age = getAge()[0]

        # the object this operation point to
        addPerson(name='mustafa', gender='male', ageId=age.id)
        person = Person.query.first()

        type = Type_operation.query.filter_by(name='lost').first()
        status = Status_operation.query.filter_by(name='active').first()
        country = Country.query.first()

        import datetime
        result = addOperation(type=type, status=status, country=country, object=person,\
              userPublicId= userPublicId, date=datetime.datetime.now())

        operation = Operations.query.first()
        self.assertTrue(operation, 'add new operation Failed')

        # now add comment to the operation
        #

        comment = addComment(operationId=operation.id,
                             userPublicId=userPublicId,
                             text='this test comment')
        self.assertTrue(comment, 'add new comment Failed')

        # check the comment in the database

        newComment = Comment.query.first()
        self.assertTrue(newComment, 'add new comment in the database Failed')

        comments = operation.comments.all()
        self.assertEqual(len(comments), 1, 'not same number of comments')

        # try get the comments
        allComments = getComment()
        self.assertTrue(allComments, 'no comments returned')
        self.assertEqual(len(allComments), 1, 'not same number of comments')

        # filter with operation
        operationComments = getComment(operationId=operation.id)
        self.assertTrue(operationComments, 'no comments returned')
        self.assertEqual(len(operationComments), 1,
                         'not same number of comments')

        # now delete the comment
        result = deleteComment(operationId=operation.id)

        self.assertTrue(result)

        # check the comments in the database
        comments = Comment.query.all()
        self.assertFalse(comments, 'the comments didn\'t deleted')
Пример #4
0
    def test_addAccident2(self):
        ''' test add Accident functionality'''

        # first add 2 car object
        car1 = addCar(type=1,
                      plateNumberLetters='dfg',
                      plateNumberNumbers='234',
                      brand='test',
                      model='test')
        car2 = addCar(type=3,
                      plateNumberLetters='fgg',
                      plateNumberNumbers='254',
                      brand='test',
                      model='test')
        self.assertTrue(car1, 'add car failed')
        self.assertTrue(car2, 'add car failed')

        # now add 1 persons object
        person = addPerson(name='test', gender='male', ageId=2, skin=3)

        self.assertTrue(person, 'add person failed')

        # now add the Accident
        accident = addAccident(cars=[car1, car2], persons=[person])
        self.assertTrue(accident, 'add accident failed')

        # check the new object in the databas
        result = Accident.query.all()

        self.assertTrue(result)
        self.assertEqual(len(result), 1, 'wrong length of accident objects')
        self.assertEqual(len(result[0].cars), 2,
                         'wrong length of cars objects')
        self.assertEqual(len(result[0].persons), 1,
                         'wrong length of person objects')
Пример #5
0
    def test_addOperation2(self):
        '''add new operation'''

        lat = 48.856613
        lng = 2.352222

        # the user who make this operation
        userPublicId = Users.query.filter_by(name='admin').first().public_id
        age = getAge()[0]

        # the object this operation point to
        addPerson(name='mustafa', gender='male', ageId=age.id)
        person = Person.query.first()

        type = Type_operation.query.filter_by(name='found').first()
        status = Status_operation.query.filter_by(name='closed').first()
        country = Country.query.first()

        result = addOperation(type=type, status=status, country=country, object=person,\
              userPublicId= userPublicId, date=datetime.datetime.now(), lat=lat, lng=lng)

        operation = Operations.query.first()

        self.assertTrue(userPublicId)
        self.assertTrue(type)
        self.assertTrue(status)
        self.assertTrue(country)
        self.assertTrue(operation)

        # make sure the operation get right data
        self.assertEqual(operation.country.id, country.id,
                         "operation don't have the right country")
        self.assertEqual(operation.type.id, type.id,
                         "operation don't have the right type")
        self.assertEqual(operation.status.id, status.id,
                         "operation don't have the right status")
        self.assertEqual(operation.user.public_id, userPublicId,
                         "operation don't have the right user")
        self.assertEqual(operation.object_id, person.id,
                         "operation don't have the right object")
        self.assertEqual(float(operation.lat), lat,
                         "operation don't have the right lat")
        self.assertEqual(float(operation.lng), lng,
                         "operation don't have the right lng")
Пример #6
0
    def test_deleteAccident(self):
        ''' add Accident then delete it'''

        # first add car object
        car = addCar(type=1,
                     plateNumberLetters='dfg',
                     plateNumberNumbers='234',
                     brand='test',
                     model='test')
        self.assertTrue(car, 'add car failed')

        # now add 1 persons object
        person = addPerson(name='test', gender='male', ageId=2, skin=3)

        # now add the Accident
        accident = addAccident(cars=[car], persons=[person])
        self.assertTrue(accident, 'add accident failed')

        # check the new object in the databas
        result = Accident.query.all()

        self.assertTrue(result)
        self.assertEqual(len(result), 1, 'wrong length of accident objects')

        # now delete it
        result = deleteAccident(object=accident)
        self.assertTrue(result)

        # check the database again
        result = Accident.query.all()
        self.assertFalse(result)

        # check the persons and the cars associated with it(must be deleted)
        result = Car.query.all()
        self.assertFalse(result, 'car object did not get deleted')

        result = Person.query.all()
        self.assertFalse(result, 'person object did not get deleted')
Пример #7
0
    def test_getOperation(self):
        """ add operation then get the operations with filters"""

        # the user who make this operation
        userPublicId = Users.query.filter_by(name='admin').first().public_id
        age = getAge()[0]

        # the object this operation point to
        addPerson(name='mustafa', gender='male', ageId=age.id)
        person = Person.query.first()

        type = Type_operation.query.filter_by(name='lost').first()
        status = Status_operation.query.filter_by(name='active').first()
        country = Country.query.first()

        lat = 48.856613
        lng = 2.352222

        result = addOperation(type=type, status=status, country=country, object=person,\
              userPublicId= userPublicId, date=datetime.date.today(), lat=lat, lng=lng)

        operation = Operations.query.first()

        self.assertTrue(operation, 'add new operation Failed')
        self.assertTrue(result, 'add new operation Failed')

        # get the operation with 'getoperation'

        # no filters
        result = getOperation()

        self.assertTrue(result, 'no operations')
        self.assertEqual(len(result), 1, 'no operations')

        # filter with object class type
        result = getOperation(object=person.__name__)

        self.assertTrue(result, 'no operations')
        self.assertEqual(result[0].object.name, 'mustafa')

        # filter with id
        previousOperationID = result[0].id
        result = getOperation(id=previousOperationID)

        self.assertTrue(result, 'no operations')
        self.assertEqual(result.id, previousOperationID)

        # filter with country id
        result = getOperation(country_id=country.id)

        self.assertTrue(result, 'no operations')
        self.assertEqual(result[0].object.name, 'mustafa')

        # filter with object class type and
        result = getOperation(object=person.__name__,
                              date=datetime.date.today())

        self.assertTrue(result, 'no operations')
        self.assertEqual(result[0].object.name, 'mustafa')

        # filter with object class type lat
        result = getOperation(object=person.__name__, lat=lat)

        self.assertTrue(result, 'no operations')
        self.assertEqual(float(result[0].lat), lat)
Пример #8
0
    def test_deleteComment(self):
        ''' try delete the comments with different filters'''

        # first add the operation
        #

        userPublicId = Users.query.filter_by(name='admin').first().public_id
        age = getAge()[0]

        # the object this operation point to
        addPerson(name='mustafa', gender='male', ageId=age.id)
        person = Person.query.first()

        type = Type_operation.query.filter_by(name='lost').first()
        status = Status_operation.query.filter_by(name='active').first()
        country = Country.query.first()

        import datetime
        result = addOperation(type=type, status=status, country=country, object=person,\
              userPublicId= userPublicId, date=datetime.datetime.now())

        operation = Operations.query.first()
        self.assertTrue(operation, 'add new operation Failed')

        # now add comment to the operation
        #

        comment = addComment(operationId=operation.id,
                             userPublicId=userPublicId,
                             text='this test comment')
        self.assertTrue(comment, 'add new comment Failed')

        # delete with operation id
        result = deleteComment(operationId=operation.id)
        self.assertTrue(result)

        # check the comments in the database
        comments = Comment.query.all()
        self.assertFalse(comments, 'the comments didn\'t deleted')

        # add comment again
        comment = addComment(operationId=operation.id,
                             userPublicId=userPublicId,
                             text='this test comment')
        self.assertTrue(comment, 'add new comment Failed')

        # delete with comment id
        result = deleteComment(id=comment.id)
        self.assertTrue(result)

        # check the comments in the database
        comments = Comment.query.all()
        self.assertFalse(comments, 'the comments didn\'t deleted')

        # add comment again
        comment = addComment(operationId=operation.id,
                             userPublicId=userPublicId,
                             text='this test comment')
        self.assertTrue(comment, 'add new comment Failed')

        # delete with comment object
        result = deleteComment(object=comment)
        self.assertTrue(result)

        # check the comments in the database
        comments = Comment.query.all()
        self.assertFalse(comments, 'the comments didn\'t deleted')