def test_query_filtered_key(self): _clear_records() Record(id='match', tags=['match_tag']).put() response = self.test_app.get('/query', params={ 'key': 'match', 'tags': 'match_tag' }) self.assertEquals( { 'more': False, 'results': [{ 'key': 'match', 'tags': ['match_tag'], 'fields': {}, }], }, _parse_body(response)) Record(id='mismatched', tags=['mismatched_tag']).put() response = self.test_app.get('/query', params={ 'key': 'mismatched', 'tags': 'match_tag' }) self.assertEquals({ 'more': False, 'results': [], }, _parse_body(response))
def test_query_tags(self): _clear_records() Record(id='match', tags=['match_tag_a', 'match_tag_b']).put() Record(id='match_extra', tags=['match_tag_a', 'match_tag_b', 'extra_tag']).put() Record(id='missing_tag', tags=['match_tag_a']).put() Record(id='wrong_tags', tags=['tag_mismatch_a', 'tag_mismatch_b']).put() Record(id='no_tags').put() response = self.test_app.get( '/query', params={'tags': 'match_tag_a,match_tag_b'}) self.assertEquals( { 'more': False, 'results': [{ 'key': 'match', 'tags': ['match_tag_a', 'match_tag_b'], 'fields': {}, }, { 'key': 'match_extra', 'tags': ['extra_tag', 'match_tag_a', 'match_tag_b'], 'fields': {}, }], }, _parse_body(response))
def test_missing_intervals_records_only(self): self.mock_now(datetime(2000, 1, 2, 0)) Record().put() self.mock_now(datetime(2000, 1, 3, 0)) Record().put() self.assertEqual([ (datetime(2000, 1, 1, 8), datetime(2000, 1, 2, 8)), (datetime(2000, 1, 2, 8), datetime(2000, 1, 3, 8)), ], missing_intervals(1440, datetime(2000, 1, 4, 0)))
def test_query_fields(self): _clear_records() Record(id='match', fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }).put() Record(id='match_extra', fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', 'extra_key': 'extra_value', }).put() Record(id='missing_key', fields={ 'match_key_a': 'match_value_a', 'extra_key': 'extra_value', }).put() Record(id='wrong_value', fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'mismatched_value_b', }).put() Record(id='empty_fields').put() response = self.test_app.get('/query', params={ 'fields': json.dumps({ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }) }) self.assertEquals( { 'more': False, 'results': [{ 'key': 'match', 'tags': [], 'fields': { 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, }, { 'key': 'match_extra', 'tags': [], 'fields': { 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', 'extra_key': 'extra_value', }, }], }, _parse_body(response))
def get_record_list(self, extended=False): record_list = [] cursor = self.connection.cursor() try: if not extended: cursor.execute( 'select id, firstname, lastname from addressbook where deprecated="0000-00-00 00:00:00"' ) for row in cursor: (id, firstname, lastname) = row record_list.append( Record(id=str(id), firstname=firstname, lastname=lastname)) elif extended: cursor.execute('select id, firstname, lastname, \ address, home, mobile, work, phone2, email, email2, email3 \ from addressbook \ where deprecated="0000-00-00 00:00:00"') for row in cursor: ( id, firstname, lastname, address, home, mobile, work, phone2, email, email2, email3, ) = row record_list.append( Record(id=str(id), firstname=firstname, lastname=lastname, address=address, home=home, mobile=mobile, work=work, phone2=phone2, email=email, email2=email2, email3=email3)) finally: cursor.close() return record_list
def main(event, context): user_id = event.get("pathParameters", {}).get("user_id") record = Record(**json.loads(event["body"])) RecordRepository().save(user_id, record) return {"statusCode": 200, "body": json.dumps({"status": "Created"})}
def get(self, user_id: str, record_date: str) -> Record: if not record_date: raise MissingInputException("record_date") if not user_id: raise MissingInputException("user_id") key = {"user": {"S": user_id}, "record_date": {"S": record_date}} item = self.dynamo.get_item(table=self.records_table_name, key=key) if not item: raise RecordNotExistsException() return Record( record_date=item["record_date"]["S"], perimeter_arm=item["perimeter_arm"]["N"], perimeter_cut=item["perimeter_cut"]["N"], perimeter_belly=item["perimeter_belly"]["N"], perimeter_leg=item["perimeter_leg"]["N"], perimeter_hips=item["perimeter_hips"]["N"], intakes=list( map( lambda i: Intake(description=i["description"]["S"], calories=i["calories"]["N"]), item["intakes"]["L"])), intake_score=item["intake_score"]["N"], sports=list( map(lambda i: Sport(description=i["description"]["S"]), item["intakes"]["L"])), sports_score=item["sports_score"]["N"])
def get_list(self): wd = self.app.wd self.app.open_home_page() self.rec_cash = [] for element in wd.find_elements_by_xpath( '//*[@id="maintable"]/tbody/tr[@name="entry"]'): # dummy record to append cash record_to_cash = Record() setattr( record_to_cash, 'id', element.find_element_by_name('selected[]').get_attribute( 'value')) setattr(record_to_cash, 'firstname', self.record_cell_value(element, 3)) setattr(record_to_cash, 'lastname', self.record_cell_value(element, 2)) setattr(record_to_cash, 'address', self.record_cell_value(element, 4)) # synthetic properties for phones and emails record_to_cash._emails_from_home = self.record_cell_value( element, 5) record_to_cash._phones_from_home = self.record_cell_value( element, 6) self.rec_cash.append(record_to_cash) return list(self.rec_cash)
def test_compare_homepage_properties_with_edit_page_values_for_random_record( app): # provide record if there is no record on the page app.record.provide(record=Record( firstname='John', # i use one word for names lastname='Smith', address='111 Jeegurda street apt 234 Another YE 00000 DFR', home='+11111111111', # mobile has been intentionally not set work='1 333 333 3333', phone2='1-444-444-4444', email='*****@*****.**', # email 2 has been intentionally not set email3='*****@*****.**')) # set random index to take record from list of existing records record_index = randrange(app.record.count()) # get text properties from home page table for random record record_from_home = app.record.get_list()[record_index] # get all the fields from edit page for the record selected (names and phones included as requested) record_from_edit = app.record.get_info_from_edit(record_index, htmlized=True) # assert names assert record_from_home.firstname == record_from_edit.firstname assert record_from_home.lastname == record_from_edit.lastname # assert address assert record_from_home.address == record_from_edit.address # assert phones (backward check here) assert record_from_home._phones_from_home == homepage_like_set( record_from_edit, set_to_arrange=record_from_edit._phones) # assert emails (backward check here) assert record_from_home._emails_from_home == homepage_like_set( record_from_edit, set_to_arrange=record_from_edit._emails)
def test_query_empty(self): _clear_records() response = self.test_app.get('/query') self.assertEquals({ 'more': False, 'results': [], 'cursor': '', }, json.loads(response.body)) Record(id='test_key', tags=['a', 'b', 'c'], fields={ 'test': 'field' }).put() response = self.test_app.get('/query') self.assertEquals( { 'more': False, 'results': [{ 'key': 'test_key', 'tags': ['a', 'b', 'c'], 'fields': { 'test': 'field' }, }], }, _parse_body(response))
def test_compare_entire_home_page_with_db_data(app, db): # provide 3 records app.record.provide( requested=3, record=Record( firstname='John', # i use one word for names lastname='Smith', address='111 Jeegurda street apt 234 Another YE 00000 DFR', home='+11111111111', # mobile has been intentionally not set work='1 333 333 3333', phone2='1-444-444-4444', email='*****@*****.**', # email 2 has been intentionally not set email3='*****@*****.**')) # get whole list from home page hp_list = sorted(app.record.get_list(), key=Record.id_or_max) # get whole not deprecated list from db db_list = db.get_record_list(extended=True) # compare lists record by record (sort by id) starting from lists lengths assert len(hp_list) == len(db_list) # if equal - continue: for each in list for i in range(len(hp_list)): # compare ids and names just comparing records representations assert hp_list[i] == db_list[i] # compare address assert hp_list[i].address == db_list[i].address # compare phones in homepage format assert hp_list[i]._phones_from_home == homepage_like_set( db_list[i], set_to_arrange=db_list[i]._phones) # verify emails as well assert hp_list[i]._emails_from_home == homepage_like_set( db_list[i], set_to_arrange=db_list[i]._emails)
def test_query_end(self): _clear_records() self.mock_now(datetime.utcfromtimestamp(0)) Record(id='match').put() self.mock_now(datetime.utcfromtimestamp(10)) Record(id='too_late').put() response = self.test_app.get('/query', params={'end': 5}) self.assertEquals( { 'more': False, 'results': [{ 'key': 'match', 'tags': [], 'fields': {}, }], }, _parse_body(response))
def get_info_from_edit(self, index, htmlized=False): # wd = self.app.wd self.app.open_home_page() # create dummy record as source of fields - any property is None record = Record() self.open_edit_by_index(index=index) # read the form and return the 'Record' object updated return self.read_form(record, htmlized)
def _load_records(self, filename): assert Record.query().count() == 0 records = _load_json(filename) for record in records: self.mock_now(datetime.utcfromtimestamp(record['timestamp'])) Record( id=record['key'], tags=record['tags'], fields=record['fields'], ).put()
def test_query_cursor(self): _clear_records() for _ in range(10): Record().put() response = self.test_app.get('/query', params={'count': 4}) packet = _parse_body(response, preserve_cursor=True) cursor = packet['cursor'] self.assertEquals( { 'more': True, 'cursor': cursor, 'results': [{ 'key': None, 'tags': [], 'fields': {} }] * 4, }, packet) response = self.test_app.get('/query', params={ 'cursor': cursor, 'count': 4 }) packet = _parse_body(response, preserve_cursor=True) cursor = packet['cursor'] self.assertEquals( { 'more': True, 'cursor': cursor, 'results': [{ 'key': None, 'tags': [], 'fields': {} }] * 4, }, packet) response = self.test_app.get('/query', params={ 'cursor': cursor, 'count': 4 }) packet = _parse_body(response, preserve_cursor=True) cursor = packet['cursor'] self.assertEquals( { 'more': False, 'cursor': cursor, 'results': [{ 'key': None, 'tags': [], 'fields': {} }] * 2, }, packet)
def test_missing_intervals_mismatched_cq_stats(self): CQStats(project='', interval_minutes=60, begin=datetime(2000, 1, 3, 7), end=datetime(2000, 1, 3, 8)).put() self.mock_now(datetime(2000, 1, 2, 0)) Record().put() self.assertEqual([ (datetime(2000, 1, 1, 8), datetime(2000, 1, 2, 8)), (datetime(2000, 1, 2, 8), datetime(2000, 1, 3, 8)), ], missing_intervals(1440, datetime(2000, 1, 4, 0)))
def add_record(self, hours_from_start, tagged_fields): tagged_fields.setdefault('project', 'test') if tagged_fields.get('action', '').startswith('verifier_'): tagged_fields.setdefault('verifier', TRYJOBVERIFIER) self.mock_now( datetime.utcfromtimestamp(STATS_START_TIMESTAMP) + timedelta(hours=hours_from_start)) Record( tags=['%s=%s' % (k, v) for k, v in tagged_fields.items()], fields=tagged_fields, ).put()
def test_modify_first_record(app): app.record.provide() old_rec = app.record.get_list() record = Record(firstname='modified_again', lastname='modified') record.id = old_rec[0].id app.record.modify_first(record) assert len(old_rec) == app.record.count() new_rec = app.record.get_list() old_rec[0] = record assert sorted(old_rec, key=Record.id_or_max) == sorted(new_rec, key=Record.id_or_max)
def get_phones_from_view(self, index): wd = self.app.wd self.app.open_home_page() self.open_view_by_index(index) record = Record() full_info = wd.find_element_by_id('content').text # get phones info todo: refactor to support backward checks (the only _phones_from_view Record property here) setattr(record, 'home', re.search('H: (.*)', full_info).group(1)) setattr(record, 'mobile', re.search('M: (.*)', full_info).group(1)) setattr(record, 'work', re.search('W: (.*)', full_info).group(1)) setattr(record, 'phone2', re.search('P: (.*)', full_info).group(1)) return record
def update_record(key=None, tags=None, fields=None): # pragma: no cover tags = tags or [] fields = fields or {} if not key and len(tags) == 0 and len(fields) == 0: raise ValueError('Empty record entries disallowed') if not 'project' in fields: raise ValueError('"Project" field missing') for item in fields: if item in AUTO_TAGGED_FIELDS: tags.append('%s=%s' % (item, fields[item])) record = Record(id=key) record.tags = list(set(tags)) record.fields = fields record.put()
def load_into_records(dataframe): """ Iterates over the data and loads it into a list of Record objects. Parameters: dataframe (pandas.core.frame.DataFrame): data from the csv file Returns: list: A list of Record objects """ records = list() for i, j in dataframe.iterrows(): records.append( Record(j['_id'], j['id'], j['date'], j['cases'], j['deaths'], j['name_fr'], j['name_en'])) return records
def add_new_record_into_memory(_id, id, date, cases, deaths, name_fr, name_en): """ Adds a new record to the dataset Parameters: _id (string): _id of the new record id (string): id of the new record date (string): date of the new record cases (string): cases of the new record deaths (string): deaths of the new record name_fr (string): name_fr of the new record name_en (string): name_en of the new record """ DATASET.in_memory_records_list.append( Record(_id, id, date, cases, deaths, name_fr, name_en))
def test_modify_random_record(app, db, check_ui): app.record.provide() old_rec = db.get_record_list() record = choice(old_rec) donor = Record(firstname='modified_again', lastname='modified') donor.id = record.id app.record.modify_by_id(upd_record=donor, rec_id=record.id) new_rec = db.get_record_list() assert len(old_rec) == len(new_rec) old_rec[old_rec.index(record)] = donor assert old_rec == new_rec if check_ui: assert sorted(app.record.get_list(), key=Record.id_or_max) == sorted(new_rec, key=Record.id_or_max)
def provide(self, requested=1, record=Record(firstname='dummy'), where='db'): records_delta = 0 if where == 'web': self.app.open_home_page() records_delta = requested - self.count() elif where == 'db': records_delta = requested - len(self.db.get_record_list()) if records_delta > 0: for item in range(records_delta): self.create(record) print('No enough records found so ' + str(records_delta) + ' new dummy record(-s) created') else: print( 'Enough records for the test, nothing to create here, (Check: ' + str(records_delta) + ').')
def start_check(self, user_id, stu_class): # 检查现在是否处于签到时期 faces = FaceDao.get_by_class_user_id2(stu_class, user_id, Open_Check.NO) if not faces: raise Exception("该班已处于签到状态") try: for face in faces: face.open_check = Open_Check.YES # 生成一条签到记录 record = Record() record.user_id = user_id record.pro_class = stu_class record.unchecked = json.dumps({'data': []}) record.record = json.dumps({'data': []}) db.session.add(record) db.session.commit() except Exception as e: db.session.rollback() FaceAuthUtils.save_exception(traceback.format_exc()) raise Exception(e.message)
def _parse_row(self, row_element: Tag): """ This method will retrieve all the data from the row. However, if there are more than one grantee or grantor then we will need to call seperate URL to retrieve the complete list of grantees and grantors. We will do this in seperate method after we have retrieved all data for a lot. :param row_element: :return: """ cell_elements: ResultSet = row_element.findChildren("td") county_record_key = cell_elements[23].get_text() instrument_num: str = cell_elements[4].get_text() date_recorded: datetime.date = datetime.datetime.strptime( cell_elements[8].get_text(), '%m/%d/%Y').date() book: str = cell_elements[5].get_text() page: str = cell_elements[6].get_text() record_type: str = cell_elements[9].get_text() if record_type in VALID_RECORD_TYPES: record_type: str = cell_elements[9].get_text() else: print("record_type [" + record_type + "] not in valid list") description: str = cell_elements[18].get_text() # get Grantors grantor_tag = cell_elements[13] grantee_tag = cell_elements[16] grantors, grantees = self._retrieve_grantors_and_grantees( grantor_tag, grantee_tag, county_record_key) record = Record(county_record_key, instrument_num, date_recorded, record_type, book, page, grantors, grantees, description) return record
def test_phones_on_home_page(app): """ preconditions: 1. delete all the records as first record (previous tests leftover) could have no phones at all 2. create new record with all the four phones defined steps 1. read record attributes from its row on home page table 2. read record attributes from its edit page 3. compare two records by phones expectations phones must be identical """ # according to task we work with the first record in list for ths test record_index = 0 # preconditions # delete all the records # app.record.delete_all() # provide record with all the phones inside app.record.provide(record=Record( firstname='dummyfirstname', # i use one word for names lastname='dummylastname', home='+11111111111', mobile='1(222)2222222', work='1 333 333 3333', phone2='1-444-444-4444')) # test starts here # get fields from home page record_from_home = app.record.get_list()[record_index] # get all the fields from edit page for the record selected (names and phones included as requested) record_from_edit = app.record.get_info_from_edit(record_index) # print('final TEST out') # debug print # print(record_from_edit) # debug print assert record_from_home._phones_from_home == homepage_like_set( record_from_edit, record_from_edit._phones)
def test_query_count(self): _clear_records() for _ in range(10): Record().put() response = self.test_app.get('/query', params={'count': 1}) self.assertEquals( { 'more': True, 'results': [{ 'key': None, 'tags': [], 'fields': {} }], }, _parse_body(response)) response = self.test_app.get('/query', params={'count': 10}) self.assertEquals( { 'more': False, 'results': [{ 'key': None, 'tags': [], 'fields': {} }] * 10, }, _parse_body(response)) response = self.test_app.get('/query', params={'count': 100}) self.assertEquals( { 'more': False, 'results': [{ 'key': None, 'tags': [], 'fields': {} }] * 10, }, _parse_body(response))
def edit_in_memory(r_id, field, new_val): c = CovidController.model.find_one_record("_id", int(r_id)) r = Record() r.load_from_cursor(c) r.__dict__[str(field)] = str(new_val) return r
def test_query_full_keyless(self): _clear_records() self.mock_now(datetime.utcfromtimestamp(5)) Record( id='match', tags=['match_tag_a', 'match_tag_b'], fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, ).put() Record( id='match_extra', tags=['match_tag_a', 'match_tag_b', 'extra_tag'], fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', 'extra_key': 'extra_value', }, ).put() self.mock_now(datetime.utcfromtimestamp(0)) Record( id='too_early', tags=['match_tag_a', 'match_tag_b'], fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, ).put() self.mock_now(datetime.utcfromtimestamp(10)) Record( id='too_late', tags=['match_tag_a', 'match_tag_b'], fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, ).put() self.mock_now(datetime.utcfromtimestamp(5)) Record( id='missing_tag', tags=['match_tag_a'], fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, ).put() Record( id='empty_tags', fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, ).put() Record( id='missing_field', tags=['match_tag_a', 'match_tag_b'], fields={ 'match_key_a': 'match_value_a', }, ).put() Record( id='wrong_field', tags=['match_tag_a', 'match_tag_b'], fields={ 'match_key_a': 'match_value_a', 'match_key_b': 'mismatched_value_b', }, ).put() Record( id='empty_fields', tags=['match_tag_a', 'match_tag_b'], ).put() response = self.test_app.get( '/query', params={ 'begin': 4, 'end': 6, 'tags': 'match_tag_a,match_tag_b', 'fields': json.dumps( { 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, ) }) self.maxDiff = None self.assertEquals( { 'more': False, 'results': [{ 'key': 'match', 'tags': ['match_tag_a', 'match_tag_b'], 'fields': { 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', }, }, { 'key': 'match_extra', 'tags': ['extra_tag', 'match_tag_a', 'match_tag_b'], 'fields': { 'match_key_a': 'match_value_a', 'match_key_b': 'match_value_b', 'extra_key': 'extra_value', }, }], }, _parse_body(response))