Пример #1
0
 def run_lookup(self, files=None):
    """
    Create a new sqlite db filled with a lookup table, useful for client applications
    to not overload the API server and to provide a better UX.
    """
    task = LookupTableTask()
    task.perform_update()
Пример #2
0
 def run_lookup(self, files=None):
     """
   Create a new sqlite db filled with a lookup table, useful for client applications
   to not overload the API server and to provide a better UX.
   """
     task = LookupTableTask()
     task.perform_update()
Пример #3
0
def api_get_lookup_table():
   """
      <h3>/client-lookup-table/?local_update=date</h3>
      <p>Rooms lookup table</p>
      <p><em>date[string]</em> : a date with format yyy/mm/dd</p>
      <p>Return an object with a boolean <em>update</em> attribute and the URL of the sqlite database.</p>
      <p>If the <em>update</em> attribute is true, the client should update its local db.</p>
   """
   date = request.args.get('local_update') or ""
   print(date)

   try:
      date_obj = datetime.strptime(date,"%Y/%m/%d")
   except ValueError:
      abort(400)

   task              = LookupTableTask()
   to_update         = task.client_should_update_db(date_obj.timestamp())

   return jsonify({ 'update': to_update , 'url':lookup_table_url(task.db_name()) })
Пример #4
0
class LookupTableTaskTest(unittest.TestCase):
    def setUp(self):
        self.ltt = LookupTableTask()

    def test_db_name(self):
        self.assertEqual(self.ltt.db_name(), "rooms_lookup.sqlite")

    def test_path(self):
        self.assertEqual(self.ltt.db_path(),
                         os.path.join("data", "sqlite", "rooms_lookup.sqlite"))

    def test_old_db_was_removed(self):
        self.ltt._delete_old_db()

        with self.assertRaises(IOError):
            open(self.ltt.db_path())

    def test_if_db_should_update_db_true(self):
        client_date = datetime.datetime(2015, 7, 29).timestamp()
        db_date = datetime.datetime(2015, 8, 5).timestamp()
        self.assertTrue(
            self.ltt.client_should_update_db(client_date,
                                             db_updated_at=db_date))

    def test_if_db_should_update_db_true_day_before(self):
        client_date = datetime.datetime(2015, 8, 4).timestamp()
        db_date = datetime.datetime(2015, 8, 5).timestamp()
        self.assertTrue(
            self.ltt.client_should_update_db(client_date,
                                             db_updated_at=db_date))

    def test_if_db_should_update_db_false(self):
        client_date = datetime.datetime(2015, 8, 5).timestamp()
        db_date = datetime.datetime(2015, 8, 5).timestamp()
        self.assertFalse(
            self.ltt.client_should_update_db(client_date,
                                             db_updated_at=db_date))

    def test_if_db_should_update_db_false_future(self):
        client_date = datetime.datetime(2020, 8, 5).timestamp()
        db_date = datetime.datetime(2015, 8, 5).timestamp()
        self.assertFalse(
            self.ltt.client_should_update_db(client_date,
                                             db_updated_at=db_date))
Пример #5
0
class LookupTableTaskTest(unittest.TestCase):

   def setUp(self):
      self.ltt = LookupTableTask()

   def test_db_name(self):
      self.assertEqual( self.ltt.db_name() , "rooms_lookup.sqlite" )

   def test_path(self):
      self.assertEqual( self.ltt.db_path() , os.path.join("data","sqlite","rooms_lookup.sqlite") )

   def test_old_db_was_removed(self):
      self.ltt._delete_old_db()

      with self.assertRaises(IOError):
         open(self.ltt.db_path())

   def test_if_db_should_update_db_true(self):
      client_date = datetime.datetime(2015,7,29).timestamp()
      db_date     = datetime.datetime(2015,8,5).timestamp()
      self.assertTrue(self.ltt.client_should_update_db(client_date,db_updated_at=db_date))


   def test_if_db_should_update_db_true_day_before(self):
      client_date = datetime.datetime(2015,8,4).timestamp()
      db_date     = datetime.datetime(2015,8,5).timestamp()
      self.assertTrue(self.ltt.client_should_update_db(client_date,db_updated_at=db_date))


   def test_if_db_should_update_db_false(self):
      client_date = datetime.datetime(2015,8,5).timestamp()
      db_date     = datetime.datetime(2015,8,5).timestamp()
      self.assertFalse(self.ltt.client_should_update_db(client_date,db_updated_at=db_date))

   def test_if_db_should_update_db_false_future(self):
      client_date = datetime.datetime(2020,8,5).timestamp()
      db_date     = datetime.datetime(2015,8,5).timestamp()
      self.assertFalse(self.ltt.client_should_update_db(client_date,db_updated_at=db_date))
Пример #6
0
 def setUp(self):
    self.ltt = LookupTableTask()
Пример #7
0
 def setUp(self):
     self.ltt = LookupTableTask()