Esempio n. 1
0
    def test_get_by_idx(self):
        """Get idol by Mnet index."""
        idol = Idol(1, 'foo', 18)
        idol.save()

        retrieved = Idol.get_by_id(idol.idx)
        assert retrieved == idol
Esempio n. 2
0
    def test_get_by_idx(self):
        """Get idol by Mnet index."""
        idol = Idol(1, 'foo', 18)
        idol.save()

        retrieved = Idol.get_by_id(idol.idx)
        assert retrieved == idol
Esempio n. 3
0
def update_idols():
    """Update db entries for all p101 idols."""
    for i in range(1, 102):
        idol = Idol.query.filter_by(idx=i).first()
        idol_data = fetch_idol(i)
        if idol_data:
            if idol:
                idol.update(vote_percentage=float(idol_data['per']), last_updated=datetime.utcnow())
                print('Updated existing idol {}'.format(idol.name_kr))
            else:
                Idol.create(idx=i, name_kr=idol_data['name'], age=int(idol_data['age']),
                            agency=idol_data['agency'], comment=idol_data['comment'],
                            vote_percentage=float(idol_data['per']))
                print('Created new idol {}'.format(idol.name_kr))
        elif idol:
            print('Could not fetch data for idol {}'.format(idol.name_kr), sys.stderr)
        else:
            print('Could not fetch data for index {}'.format(idx), sys.stderr)
    for i, idol in enumerate(Idol.query.order_by(desc(Idol.vote_percentage)).all()):
        # we don't update previous rank here, this should only be done daily
        # (see update_dailies)
        idol.update(rank=i + 1)
    print('Successfully fetched p101 idol data.')
Esempio n. 4
0
 def test_agency_is_nullable(self):
     """Test null agency."""
     idol = Idol(1, 'foo', 18)
     idol.save()
     assert idol.agency is None
Esempio n. 5
0
 def test_last_name_en_is_nullable(self):
     """Test null name."""
     idol = Idol(1, 'foo', 18)
     idol.save()
     assert idol.last_name_en is None
Esempio n. 6
0
 def test_last_updated_defaults_to_datetime(self):
     """Test update date."""
     idol = Idol(1, 'foo', 18)
     idol.save()
     assert bool(idol.last_updated)
     assert isinstance(idol.last_updated, dt.datetime)
Esempio n. 7
0
 def test_agency_is_nullable(self):
     """Test null agency."""
     idol = Idol(1, 'foo', 18)
     idol.save()
     assert idol.agency is None
Esempio n. 8
0
 def test_last_name_en_is_nullable(self):
     """Test null name."""
     idol = Idol(1, 'foo', 18)
     idol.save()
     assert idol.last_name_en is None
Esempio n. 9
0
 def test_last_updated_defaults_to_datetime(self):
     """Test update date."""
     idol = Idol(1, 'foo', 18)
     idol.save()
     assert bool(idol.last_updated)
     assert isinstance(idol.last_updated, dt.datetime)