Esempio n. 1
0
def test_flag_all_as_deleted(subst1, deleted_subst):
    # When
    Substance.flag_all_as_deleted()
    substances = Substance.all()

    # Then
    assert substances[0]['name'] == 'Deleted Subst'
    assert substances[0]['deleted_at'] == '2015-10-10'
    assert substances[1]['name'] == 'Subst1'
    assert substances[1]['deleted_at'] == '2016-12-12T00:00:00'
Esempio n. 2
0
 def execute(self):
     substances = {}
     # Flag every substance as deleted to update others and flag the non-updated as deleted in the end
     Substance.flag_all_as_deleted()
     # Then read the update file
     req = requests.get(SUBSTANCE_URI, stream=True)
     for line in req.iter_lines():
         line = line.decode('ISO-8859-1').encode('UTF8').split('\t')
         if not line or len(line) < 4:
             continue
         subst_id = line[2]
         if subst_id not in substances:
             substances[subst_id] = self.create_substance(line)
         substances[subst_id].add_speciality_from_cis(line[0])
     map(lambda x: self.save_if_has_specialities(substances[x]), substances)
Esempio n. 3
0
def test_update_subst(subst1, subst2, spec1, spec2):
    with requests_mock.mock() as mock:
        # Given
        mock.get(requests_mock.ANY,
                 text=SUBST_STREAM,
                 headers={
                     'Content-Type': 'text/html',
                     'Charset': 'ISO-8859-1'
                 })
        subst_updater = SubstanceUpdater()

        # When
        subst_updater.execute()
        subst_list = Substance.all()

        # Then
        assert len(subst_list) == 3
        assert not subst_list[0]['deleted_at']
        assert not subst_list[1]['deleted_at']
        assert subst_list[0]['_id'] == '42215'
        assert subst_list[1]['_id'] == '49632'
        assert subst_list[2]['_id'] == '86571'
        assert subst_list[1]['created_at'] == '2016-12-15T00:00:00'
        assert subst_list[2]['deleted_at'] == '2016-12-15T00:00:00'
Esempio n. 4
0
    links = list(
        map(lambda l: (l.text.capitalize(), base_url + l.attrs["href"]),
            links))
    print(f"Substance: {e_number}: {name}")
    print(f"More info: {links}")
    print("Sub categories:")
    for i, s in enumerate(sub_categories):
        print(f"- {i}: {s.name}")
    sub_category = None
    while sub_category is None:
        try:
            category = input("Select sub category:")
            if category == "s":
                break
            sub_category = sub_categories[int(category)]
        except ValueError:
            continue
    if sub_category is None:
        continue
    substance = Substance()
    substance.name = name
    substance.e_number = e_number
    substance.sub_category = sub_category
    substance.save()
    for l in links:
        more_info = SubstanceMoreInfo()
        more_info.substance = substance
        more_info.name = l[0]
        more_info.more_info = l[1]
        more_info.save()
Esempio n. 5
0
 def create_substance(line):
     return Substance(_id=line[2], name=line[3], status=None)
Esempio n. 6
0
def substance():
    return Substance(name='Substance', _id=1)
Esempio n. 7
0
def substance_g():
    return Substance(name='SubstanceG', _id=2, status='G')