Beispiel #1
0
    def get(self, request_args):
        """
        Get user by id
        :param filter: Query string with filter[date] = timestamp of a date without hours
        """
        if 'date' in request_args.filters:
            ticket_timestamp = TryParse.to_int(None,
                                               request_args.filters['date'])
            date_filter = TryParse.from_timestamp_to_datetime(
                None, ticket_timestamp)
        else:
            date_filter = datetime(2018, 3, 25)

        tickets = Ticket.find_by_date(date_filter)

        result = self.tickets_schema.dump(tickets)
        return jsonify_response(result.data, 200)
    def test_try_parse_timestamp_invalid_str_value_return_default_value(self):
        # arrange
        valid_float_value = "abcde"
        expected_value = None

        # act
        result = TryParse.from_timestamp_to_datetime(None, valid_float_value)

        # assert
        self.assertEqual(expected_value, result)
    def test_try_parse_int_valid_value_return_correct_value(self):
        # arrange
        valid_int_value = "123456789"
        expected_value = 123456789

        # act
        result = TryParse.to_int(None, valid_int_value)

        # assert
        self.assertEqual(expected_value, result)
    def test_try_parse_float_invalid_value_return_default_value(self):
        # arrange
        valid_float_value = "140.abc"
        expected_value = 0

        # act
        result = TryParse.to_float(0, valid_float_value)

        # assert
        self.assertEqual(expected_value, result)
    def test_try_parse_float_valid_value_return_correct_value(self):
        # arrange
        valid_float_value = "140.45"
        expected_value = 140.45

        # act
        result = TryParse.to_float(None, valid_float_value)

        # assert
        self.assertEqual(expected_value, result)
    def test_try_parse_int_invalid_value_return_default_value(self):
        # arrange
        invalid_int_value = "abcdef"
        expected_value = None

        # act
        result = TryParse.to_int(None, invalid_int_value)

        # assert
        self.assertEqual(expected_value, result)
    def test_try_parse_timestamp_valid_str_value_return_correct_datetime_value(
            self):
        # arrange
        valid_float_value = "1522537200"
        expected_value = datetime(2018, 4, 1)

        # act
        result = TryParse.from_timestamp_to_datetime(None, valid_float_value)

        # assert
        self.assertEqual(str(expected_value), str(result))