Esempio n. 1
0
    def test_date_timestamp(self):
        api = prismic.get('https://lesbonneschoses.prismic.io/api')
        response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbl"))\
            .ref(api.get_master()).submit()
        doc = response.documents[0]
        # startgist:d0df1672e30871ab6517:prismic-dateTimestamp.py
        # Date and Timestamp predicates
        date_before = predicates.date_before("my.product.releaseDate", datetime.datetime(2014, 6, 1))
        date_after = predicates.date_after("my.product.releaseDate", datetime.datetime(2014, 1, 1))
        date_Between = predicates.date_between("my.product.releaseDate", datetime.datetime(2014, 1, 1), datetime.datetime(2014, 6, 1))
        day_of_month = predicates.day_of_month("my.product.releaseDate", 14)
        day_of_month_after = predicates.day_of_month_after("my.product.releaseDate", 14)
        day_of_month_before = predicates.day_of_month_before("my.product.releaseDate", 14)
        day_of_week = predicates.day_of_week("my.product.releaseDate", "Tuesday")
        day_of_week_after = predicates.day_of_week_after("my.product.releaseDate", "Wednesday")
        day_of_week_before = predicates.day_of_month_before("my.product.releaseDate", "Wednesday")
        month = predicates.month("my.product.releaseDate", "June")
        month_before = predicates.month_before("my.product.releaseDate", "June")
        month_after = predicates.month_after("my.product.releaseDate", "June")
        year = predicates.year("my.product.releaseDate", 2014)
        hour = predicates.hour("my.product.releaseDate", 12)
        hour_before = predicates.hour_before("my.product.releaseDate", 12)
        hour_after = predicates.hour_after("my.product.releaseDate", 12)

        # Accessing Date and Timestamp fields
        date = doc.get_date("blog-post.date")
        date_year = date and date.as_datetime.year
        update_time = doc.get_timestamp("blog-post.update")
        update_hour = update_time and update_time.as_datetime.hours
        # endgist
        self.assertEqual(date_year, 2013)
Esempio n. 2
0
 def test_predicates(self):
     # startgist:771a09b9d88e0fb53705:prismic-predicates.py
     api = prismic.get("http://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master()) \
         .query(predicates.at("document.type", "product"),
                predicates.date_after("my.blog-post.date", 1401580800000))\
         .submit()
     # endgist
     self.assertEqual(response.results_size, 0)
Esempio n. 3
0
 def test_predicates(self):
     # startgist:771a09b9d88e0fb53705:prismic-predicates.py
     api = prismic.get("http://lesbonneschoses.prismic.io/api")
     response = api.form("everything").ref(api.get_master()) \
         .query(predicates.at("document.type", "product"),
                predicates.date_after("my.blog-post.date", 1401580800000))\
         .submit()
     # endgist
     self.assertEqual(response.results_size, 0)
Esempio n. 4
0
    def test_date_timestamp(self):
        api = prismic.get('https://lesbonneschoses.prismic.io/api')
        response = api.form('everything').query(predicates.at("document.id", "UlfoxUnM0wkXYXbl"))\
            .ref(api.get_master()).submit()
        doc = response.documents[0]
        # startgist:d0df1672e30871ab6517:prismic-dateTimestamp.py
        # Date and Timestamp predicates
        date_before = predicates.date_before("my.product.releaseDate",
                                             datetime.datetime(2014, 6, 1))
        date_after = predicates.date_after("my.product.releaseDate",
                                           datetime.datetime(2014, 1, 1))
        date_Between = predicates.date_between("my.product.releaseDate",
                                               datetime.datetime(2014, 1, 1),
                                               datetime.datetime(2014, 6, 1))
        day_of_month = predicates.day_of_month("my.product.releaseDate", 14)
        day_of_month_after = predicates.day_of_month_after(
            "my.product.releaseDate", 14)
        day_of_month_before = predicates.day_of_month_before(
            "my.product.releaseDate", 14)
        day_of_week = predicates.day_of_week("my.product.releaseDate",
                                             "Tuesday")
        day_of_week_after = predicates.day_of_week_after(
            "my.product.releaseDate", "Wednesday")
        day_of_week_before = predicates.day_of_month_before(
            "my.product.releaseDate", "Wednesday")
        month = predicates.month("my.product.releaseDate", "June")
        month_before = predicates.month_before("my.product.releaseDate",
                                               "June")
        month_after = predicates.month_after("my.product.releaseDate", "June")
        year = predicates.year("my.product.releaseDate", 2014)
        hour = predicates.hour("my.product.releaseDate", 12)
        hour_before = predicates.hour_before("my.product.releaseDate", 12)
        hour_after = predicates.hour_after("my.product.releaseDate", 12)

        # Accessing Date and Timestamp fields
        date = doc.get_date("blog-post.date")
        date_year = date and date.as_datetime.year
        update_time = doc.get_timestamp("blog-post.update")
        update_hour = update_time and update_time.as_datetime.hours
        # endgist
        self.assertEqual(date_year, 2013)