コード例 #1
0
    def test_plural_or_not(self):
        """Test convert_amount()."""
        expected = "sales"

        rl = ResultsLanguage(standard_data)
        actual = rl.plural_or_not()

        self.assertEqual(actual, expected)
コード例 #2
0
    def test_plural_or_not(self):
        """Test convert_amount()."""
        expected = "sales"

        rl = ResultsLanguage(standard_data)
        actual = rl.plural_or_not()

        self.assertEqual(actual, expected)
コード例 #3
0
    def test_add_nbhd_zip_language_nbhd_and_zip(self):
        """Test add_nbhd_zip_language() with zip and neighborhood."""
        input = "Current sentence"
        expected = "Current sentence in the Gert Town neighborhood and 70125"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_nbhd_zip_language(input)

        self.assertEqual(actual, expected)
コード例 #4
0
    def test_add_final_sentence_language_no_quotes(self):
        """Test add_final_sentence_language() without quotes."""
        input = "Current sentence"
        expected = "Current sentence."

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #5
0
    def test_add_keyword_language_keyword(self):
        """Test add_keyword_language() for single word."""
        input = "Current language"
        expected = 'Current language for keyword "Keyword"'

        rl = ResultsLanguage(standard_data)
        actual = rl.add_keyword_language(input)

        self.assertEqual(actual, expected)
コード例 #6
0
    def test_add_final_sentence_language_double_quotes(self):
        """Test add_final_sentence_language() with double quotes at end."""
        input = 'Current "sentence"'
        expected = 'Current "sentence."'

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #7
0
    def test_add_final_sentence_language_end_on_date(self):
        """Test add_final_sentence_language() ending on a date."""
        input = "Current sentence Dec. 31, 2016,"
        expected = "Current sentence Dec. 31, 2016."

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #8
0
    def test_add_final_sentence_language_single_quotes(self):
        """Test add_final_sentence_language() with single quotes at end."""
        input = "Current 'sentence'"
        expected = "Current 'sentence.'"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #9
0
    def test_add_final_sentence_language_double_quotes(self):
        """Test add_final_sentence_language() with double quotes at end."""
        input = 'Current "sentence"'
        expected = 'Current "sentence."'

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #10
0
    def test_add_final_sentence_language_no_quotes(self):
        """Test add_final_sentence_language() without quotes."""
        input = "Current sentence"
        expected = "Current sentence."

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #11
0
    def test_add_final_sentence_language_end_on_date(self):
        """Test add_final_sentence_language() ending on a date."""
        input = "Current sentence Dec. 31, 2016,"
        expected = "Current sentence Dec. 31, 2016."

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #12
0
    def test_add_final_sentence_language_single_quotes(self):
        """Test add_final_sentence_language() with single quotes at end."""
        input = "Current 'sentence'"
        expected = "Current 'sentence.'"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_final_sentence_language(input)

        self.assertEqual(actual, expected)
コード例 #13
0
    def test_add_map_filtering_language(self):
        """Test add_map_filtering_language()."""
        input = "Current sentence"
        expected = "Current sentence in the current map view"

        rl = ResultsLanguage(standard_data)  # True
        actual = rl.add_map_filtering_language(input)

        self.assertEqual(actual, expected)
コード例 #14
0
    def test_add_date_language_both(self):
        """Test add_date_language() with both dates."""
        input = "Current sentence"
        expected = "Current sentence between May 1, 2016, and Dec. 31, 2016,"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_date_language(input)

        self.assertEqual(actual, expected)
コード例 #15
0
    def test_add_date_language_both(self):
        """Test add_date_language() with both dates."""
        input = "Current sentence"
        expected = "Current sentence between May 1, 2016, and Dec. 31, 2016,"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_date_language(input)

        self.assertEqual(actual, expected)
コード例 #16
0
    def test_add_map_filtering_language(self):
        """Test add_map_filtering_language()."""
        input = "Current sentence"
        expected = "Current sentence in the current map view"

        rl = ResultsLanguage(standard_data)  # True
        actual = rl.add_map_filtering_language(input)

        self.assertEqual(actual, expected)
コード例 #17
0
    def test_add_nbhd_zip_language_nbhd_and_zip(self):
        """Test add_nbhd_zip_language() with zip and neighborhood."""
        input = "Current sentence"
        expected = "Current sentence in the Gert Town neighborhood and 70125"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_nbhd_zip_language(input)

        self.assertEqual(actual, expected)
コード例 #18
0
    def test_add_keyword_language_keyword(self):
        """Test add_keyword_language() for single word."""
        input = "Current language"
        expected = 'Current language for keyword "Keyword"'

        rl = ResultsLanguage(standard_data)
        actual = rl.add_keyword_language(input)

        self.assertEqual(actual, expected)
コード例 #19
0
    def test_add_amount_language_both(self):
        """Test add_amount_language() with both."""
        input = "Current sentence"
        expected = "Current sentence where the price was between " + \
            "$10 and $1,000"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_amount_language(input)

        self.assertEqual(actual, expected)
コード例 #20
0
    def test_add_amount_language_both(self):
        """Test add_amount_language() with both."""
        input = "Current sentence"
        expected = "Current sentence where the price was between " + \
            "$10 and $1,000"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_amount_language(input)

        self.assertEqual(actual, expected)
コード例 #21
0
    def test_plural_or_not_single(self):
        """Test convert_amount() for a single sale."""
        expected = "sale"

        new_data = copy.deepcopy(standard_data)
        new_data["number_of_records"] = 1
        rl = ResultsLanguage(new_data)

        actual = rl.plural_or_not()

        self.assertEqual(actual, expected)
コード例 #22
0
    def test_plural_or_not_single(self):
        """Test convert_amount() for a single sale."""
        expected = "sale"

        new_data = copy.deepcopy(standard_data)
        new_data["number_of_records"] = 1
        rl = ResultsLanguage(new_data)

        actual = rl.plural_or_not()

        self.assertEqual(actual, expected)
コード例 #23
0
    def test_add_initial_language(self, mock_commas):
        """Test add_initial_language()."""
        mock_commas.return_value = "One"

        input = "sale"
        expected = "One sale found"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_initial_language(input)

        self.assertEqual(actual, expected)
コード例 #24
0
    def test_add_initial_language(self, mock_commas):
        """Test add_initial_language()."""
        mock_commas.return_value = "One"

        input = "sale"
        expected = "One sale found"

        rl = ResultsLanguage(standard_data)
        actual = rl.add_initial_language(input)

        self.assertEqual(actual, expected)
コード例 #25
0
    def test_add_nbhd_zip_language_nbhd_only(self):
        """Test add_nbhd_zip_language() with neighborhood only."""
        input = "Current sentence"
        expected = "Current sentence in the Gert Town neighborhood"

        new_data = copy.deepcopy(standard_data)
        new_data["zip_code"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_nbhd_zip_language(input)

        self.assertEqual(actual, expected)
コード例 #26
0
    def test_add_date_language_end_only(self):
        """Test add_date_language() with end date only."""
        input = "Current sentence"
        expected = "Current sentence before Dec. 31, 2016,"

        new_data = copy.deepcopy(standard_data)
        new_data["begin_date"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_date_language(input)

        self.assertEqual(actual, expected)
コード例 #27
0
    def test_add_date_language_end_only(self):
        """Test add_date_language() with end date only."""
        input = "Current sentence"
        expected = "Current sentence before Dec. 31, 2016,"

        new_data = copy.deepcopy(standard_data)
        new_data["begin_date"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_date_language(input)

        self.assertEqual(actual, expected)
コード例 #28
0
    def test_add_amount_language_high_only(self):
        """Test add_amount_language() with high amount only."""
        input = "Current sentence"
        expected = "Current sentence where the price was less than $1,000"

        new_data = copy.deepcopy(standard_data)
        new_data["amount_low"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_amount_language(input)

        self.assertEqual(actual, expected)
コード例 #29
0
    def test_main_all(self):
        """Test main() with all components."""
        expected = (
            '4,344 sales found for keyword "Keyword" in the Gert Town ' +
            "neighborhood and 70125 where the price was between $10 and " +
            "$1,000 between May 1, 2016, and Dec. 31, 2016, in the " +
            "current map view.")

        rl = ResultsLanguage(standard_data)
        actual = rl.main()

        self.assertEqual(actual, expected)
コード例 #30
0
    def test_add_nbhd_zip_language_nbhd_only(self):
        """Test add_nbhd_zip_language() with neighborhood only."""
        input = "Current sentence"
        expected = "Current sentence in the Gert Town neighborhood"

        new_data = copy.deepcopy(standard_data)
        new_data["zip_code"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_nbhd_zip_language(input)

        self.assertEqual(actual, expected)
コード例 #31
0
    def test_add_keyword_language_key_empty(self):
        """Test add_keyword_language() for empty search."""
        input = "Current language"
        expected = 'Current language'

        new_data = copy.deepcopy(standard_data)
        new_data["name_address"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_keyword_language(input)

        self.assertEqual(actual, expected)
コード例 #32
0
    def test_add_keyword_language_key_empty(self):
        """Test add_keyword_language() for empty search."""
        input = "Current language"
        expected = 'Current language'

        new_data = copy.deepcopy(standard_data)
        new_data["name_address"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_keyword_language(input)

        self.assertEqual(actual, expected)
コード例 #33
0
    def test_add_keyword_language_key_phrase(self):
        """Test add_keyword_language() for multiple words."""
        input = "Current language"
        expected = 'Current language for key phrase "Key phrase"'

        new_data = copy.deepcopy(standard_data)
        new_data["name_address"] = "Key phrase"
        rl = ResultsLanguage(new_data)

        actual = rl.add_keyword_language(input)

        self.assertEqual(actual, expected)
コード例 #34
0
    def test_add_amount_language_high_only(self):
        """Test add_amount_language() with high amount only."""
        input = "Current sentence"
        expected = "Current sentence where the price was less than $1,000"

        new_data = copy.deepcopy(standard_data)
        new_data["amount_low"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_amount_language(input)

        self.assertEqual(actual, expected)
コード例 #35
0
    def test_add_keyword_language_key_phrase(self):
        """Test add_keyword_language() for multiple words."""
        input = "Current language"
        expected = 'Current language for key phrase "Key phrase"'

        new_data = copy.deepcopy(standard_data)
        new_data["name_address"] = "Key phrase"
        rl = ResultsLanguage(new_data)

        actual = rl.add_keyword_language(input)

        self.assertEqual(actual, expected)
コード例 #36
0
    def test_main_all(self):
        """Test main() with all components."""
        expected = (
            '4,344 sales found for keyword "Keyword" in the Gert Town ' +
            "neighborhood and 70125 where the price was between $10 and " +
            "$1,000 between May 1, 2016, and Dec. 31, 2016, in the " +
            "current map view.")

        rl = ResultsLanguage(standard_data)
        actual = rl.main()

        self.assertEqual(actual, expected)
コード例 #37
0
    def test_add_nbhd_zip_language_nothing_new(self):
        """Test add_nbhd_zip_language() nothing new."""
        input = "Current sentence"
        expected = "Current sentence"

        new_data = copy.deepcopy(standard_data)
        new_data["neighborhood"] = ""
        new_data["zip_code"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_nbhd_zip_language(input)

        self.assertEqual(actual, expected)
コード例 #38
0
    def test_add_amount_language_none(self):
        """Test add_amount_language() without anything new."""
        input = "Current sentence"
        expected = "Current sentence"

        new_data = copy.deepcopy(standard_data)
        new_data["amount_low"] = ""
        new_data["amount_high"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_amount_language(input)

        self.assertEqual(actual, expected)
コード例 #39
0
    def test_add_date_language_none(self):
        """Test add_date_language() without any new data."""
        input = "Current sentence"
        expected = "Current sentence"

        new_data = copy.deepcopy(standard_data)
        new_data["begin_date"] = ""
        new_data["end_date"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_date_language(input)

        self.assertEqual(actual, expected)
コード例 #40
0
    def test_add_amount_language_none(self):
        """Test add_amount_language() without anything new."""
        input = "Current sentence"
        expected = "Current sentence"

        new_data = copy.deepcopy(standard_data)
        new_data["amount_low"] = ""
        new_data["amount_high"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_amount_language(input)

        self.assertEqual(actual, expected)
コード例 #41
0
    def test_add_date_language_none(self):
        """Test add_date_language() without any new data."""
        input = "Current sentence"
        expected = "Current sentence"

        new_data = copy.deepcopy(standard_data)
        new_data["begin_date"] = ""
        new_data["end_date"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_date_language(input)

        self.assertEqual(actual, expected)
コード例 #42
0
    def test_add_nbhd_zip_language_nothing_new(self):
        """Test add_nbhd_zip_language() nothing new."""
        input = "Current sentence"
        expected = "Current sentence"

        new_data = copy.deepcopy(standard_data)
        new_data["neighborhood"] = ""
        new_data["zip_code"] = ""
        rl = ResultsLanguage(new_data)

        actual = rl.add_nbhd_zip_language(input)

        self.assertEqual(actual, expected)
コード例 #43
0
ファイル: models.py プロジェクト: TheLens/realestate
    def get_search(self, request):
        """
        GET call for /realestate/search.

        :param request: The request object(?).
        :returns: A data dict, SQL query result and JS data.
        """
        data = self.parse_query_string(request)
        data = self.decode_data(data)
        data = self.convert_entries_to_db_friendly(data)

        data['update_date'] = self.get_last_updated_date()
        data['neighborhoods'] = self.get_neighborhoods()

        data = self.determine_pages(data)

        query = self.find_page_of_publishable_rows_fitting_criteria(data)

        for row in query:
            row.amount = get_num_with_curr_sign(row.amount)
            row.document_date = ymd_to_full_date(
                (row.document_date).strftime('%Y-%m-%d'), no_day=True)

        features = self.build_features_json(query)

        jsdata = {"type": "FeatureCollection", "features": features}

        data['results_css_display'] = 'none'

        if data['number_of_records'] == 0:
            data['current_page'] = 0
            data['results_css_display'] = 'block'

        data = self.revert_entries(data)

        data['map_button_state'] = False

        data['results_language'] = ResultsLanguage(data).main()

        log.debug('data')

        return data, query, jsdata
コード例 #44
0
ファイル: models.py プロジェクト: TheLens/realestate
    def mapquery_db(self, data):
        """TODO."""
        data['bounds'] = [
            data['bounds']['_northEast']['lat'],
            data['bounds']['_northEast']['lng'],
            data['bounds']['_southWest']['lat'],
            data['bounds']['_southWest']['lng']
        ]

        data['update_date'] = self.get_last_updated_date()

        log.debug('map_button_state')

        if data['map_button_state']:  # map filtering is on
            query = self.filter_by_map(data)  # TODO: was defined elsewhere
        else:  # map filtering is off
            query = self.do_not_filter_by_map(data)

        for row in query:
            row.amount = get_num_with_curr_sign(row.amount)
            row.document_date = ymd_to_full_date(
                (row.document_date).strftime('%Y-%m-%d'), no_day=True)

        features = self.build_features_json(query)

        jsdata = {"type": "FeatureCollection", "features": features}

        if data['number_of_records'] == 0:
            data['current_page'] = 0
            data['results_css_display'] = 'block'
        else:
            data['results_css_display'] = 'none'

        data = self.revert_entries(data)

        data['results_language'] = ResultsLanguage(data).main()

        log.debug('data returned:')
        log.debug(data)

        return data, query, jsdata