def test_clean_up_old_data(self): ''' Tests cleaning up old data from the global data table. ''' timestamp = datetime.datetime.now() + datetime.timedelta(hours=5) - datetime.timedelta(days=2) self.data_factory.create_data('content', 'id1', (0, 0), 'global', timestamp.timetuple(), 'type') timestamp = datetime.datetime.now() + datetime.timedelta(hours=5) - datetime.timedelta(days=4) self.data_factory.create_data('content', 'id2', (0, 0), 'global', timestamp.timetuple(), 'type') timestamp = datetime.datetime.now() + datetime.timedelta(hours=5) self.data_factory.create_data('content', 'id3', (0, 0), 'global', timestamp.timetuple(), 'type') timestamp = datetime.datetime.now() + datetime.timedelta(hours=5) - datetime.timedelta(hours=3) self.data_factory.create_data('content', 'id4', (0, 0), 'global', timestamp.timetuple(), 'type') # Launch the sub-process process = subprocess.Popen( './bin/global_data_janitor ./config/test_smcity.conf', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) # Spin up the logging threads out_thread = Thread(target=self._dump_out_pipe, kwargs={'process' : process}) out_thread.start() err_thread = Thread(target=self._dump_err_pipe, kwargs={'process' : process}) err_thread.start() # Wait for the process to finish out_thread.join() err_thread.join() # Verify the correct records were deleted for raw_record in self.global_table.scan(): record = AwsData(raw_record) assert (record.get_datum_id() == 'id3') or (record.get_datum_id() == 'id4'), \ record.get_datum_id()
def test_create_set_data(self): ''' Tests creating non-global data. ''' content = 'content' datum_id = 'id' lat = 5.5 lon = 6.6 set_id = 'my_set' timestamp = strptime('2014-01-02 01:02:03', '%Y-%m-%d %H:%M:%S') type = 'type' self.data_factory.create_data(content, datum_id, (lon, lat), set_id, timestamp, type) # Check the created set data record raw_record = self.set_table.get_item(set_id=set_id, datum_id=datum_id) assert raw_record is not None record = AwsData(raw_record) assert record.get_content() == content, record.get_content() assert record.get_datum_id() == datum_id, record.get_datum_id() assert record.get_location() == (lon, lat), record.get_location() assert record.get_set_id() == set_id, record.get_set_id() assert record.get_timestamp() == timestamp, record.get_timestamp() assert record.get_type() == 'type', record.get_type() for record in self.global_table.scan(): # Make sure there weren't any global data records created assert False, "Should not have record in set table!"