def test_get_action_range_invalid_enum_options_fails(self):

        activity = ActivityFactory.create()

        create_date = activity.created_at.date()
        create_date_ahead = activity.created_at.date() + datetime.timedelta(
            days=3)

        first_date = str(create_date.year) + "-" + \
                     str(create_date.month).zfill(2) + \
                     "-" + str(create_date.day).zfill(2)

        second_date = str(create_date_ahead.year) + "-"\
                      + str(create_date_ahead.month).zfill(2) + "-" + \
                      str(create_date_ahead.day).zfill(2)

        response = self.client().get(
            self.make_url("/activities/action_range"),
            query_string={
                'date_range': first_date + ":" + second_date,
                'action_type': 'insert'  # an invalid enum option
            },
            headers=self.headers())

        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assert400(response)
        self.assertIn("can only have options:", response_json['msg'])
    def test_get_range_with_wrong_date_range_order_fails(self):

        activity = ActivityFactory.create()

        create_date = activity.created_at.date()
        create_date_ahead = activity.created_at.date() + datetime.timedelta(
            days=3)

        first_date = str(create_date.year) + "-" + \
                     str(create_date.month).zfill(2) + \
                     "-" + str(create_date.day).zfill(2)

        second_date = str(create_date_ahead.year) + "-"\
                      + str(create_date_ahead.month).zfill(2) + "-" + \
                      str(create_date_ahead.day).zfill(2)

        response = self.client().get(
            self.make_url("/activities/range"),
            query_string={'date_range': second_date + ":" + first_date},
            headers=self.headers())

        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assert400(response)
        self.assertIn("Bad Request - Start Date", response_json['msg'])
Beispiel #3
0
    def test_new_activity_method_returns_new_activity_object(self):
        activity = ActivityFactory.build()
        new_activity = self.repo.new_activity(
            activity.module_name, activity.ip_address, activity.user_id,
            activity.action_type, activity.action_details, activity.channel)

        self.assertIsInstance(new_activity, Activity)
        self.assertEqual(new_activity.module_name, activity.module_name)
        self.assertEqual(new_activity.ip_address, activity.ip_address)
        self.assertEqual(new_activity.user_id, activity.user_id)
Beispiel #4
0
    def test_get_range_paginated_options_method_return_paginated_results(self):
        activity = ActivityFactory.build()
        new_activity = self.repo.new_activity(
            activity.module_name, activity.ip_address, activity.user_id,
            activity.action_type, activity.action_details, activity.channel)

        paginated_result = self.repo.get_range_paginated_options(
            new_activity.created_at, new_activity.created_at)

        self.assertIsInstance(paginated_result.items[0], Activity)
        self.assertEqual(paginated_result.items[0], new_activity)
    def test_get_action_range_correct_values_succeeds(self):

        activity = ActivityFactory.create()

        create_date = activity.created_at.date()
        create_date_ahead = activity.created_at.date() + datetime.timedelta(
            days=3)

        first_date = str(create_date.year) + "-" + \
                     str(create_date.month).zfill(2) + \
                     "-" + str(create_date.day).zfill(2)

        second_date = str(create_date_ahead.year) + "-"\
                      + str(create_date_ahead.month).zfill(2) + "-" + \
                      str(create_date_ahead.day).zfill(2)

        response = self.client().get(self.make_url("/activities/action_range"),
                                     query_string={
                                         'date_range':
                                         first_date + ":" + second_date,
                                         'action_type': 'create'
                                     },
                                     headers=self.headers())

        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assert200(response)
        self.assertEqual(response_json['msg'], 'OK')
        self.assertEqual(response_json['payload']['activities'][0]['id'],
                         activity.id)
        self.assertEqual(
            response_json['payload']['activities'][0]['isDeleted'],
            activity.is_deleted)
        self.assertEqual(
            response_json['payload']['activities'][0]['ipAddress'],
            activity.ip_address)
        self.assertEqual(
            response_json['payload']['activities'][0]['actionType'],
            activity.action_type)
        self.assertEqual(
            response_json['payload']['activities'][0]['actionDetails'],
            activity.action_details)
        self.assertEqual(response_json['payload']['activities'][0]['channel'],
                         activity.channel)