コード例 #1
0
    def test_need_manager_for_location(self):
        """
            checks that get_days_with_needs() returns only dates later than datetime.now()
        """
        now = datetime.now()
        yesterday_start = now - timedelta(1)
        yesterday_end = yesterday_start + timedelta(hours=1)
        tomorrow_start = now + timedelta(1)
        tomorrow_end = tomorrow_start + timedelta(hours=1)

        location = LocationFactory.create()

        yesterday_need = NeedFactory.create(location=location,
                                            starting_time=yesterday_start,
                                            ending_time=yesterday_end)
        tomorrow_need = NeedFactory.create(location=location,
                                           starting_time=tomorrow_start,
                                           ending_time=tomorrow_end)

        assert Location.objects.count(
        ) == 1, "test case assumes that needs have been created for the same location, as the NeedFactory indeed does at the time of writing of this test case"
        assert Location.objects.all()[0] == location

        needs = Need.open_needs.at_location(location=location)

        assert needs.count(
        ) == 1, "only 1 need should be found with Need.open_needs"
        assert needs[0] == tomorrow_need, "wrong shift was found"
        assert needs[0].ending_time > now, "the time has to be in the future"
コード例 #2
0
ファイル: test_factories.py プロジェクト: olzhasar/covidmap
def test_factories(use_db):
    location = LocationFactory(id=4)

    CaseDataFactory(location=location, confirmed=100, recovered=50, fatal=0)

    record = CaseData.query.first()

    assert record
    assert record.confirmed == 100
    assert record.recovered == 50
    assert record.fatal == 0
    assert record.location_id == 4
コード例 #3
0
def simple_db(db):
    """a set of ca, location, mh, and vendor for tests."""
    mini_db = {}

    # create vendor
    v = VendorFactory()
    mini_db['vendor'] = v
    db.session.commit() # need the vendor.id to create ca

    # create a bunch of capture agents
    mini_db['ca'] = []
    for i in range(5):
        mini_db['ca'].append(CaFactory(vendor_id=mini_db['vendor'].id))

    # create a bunch of rooms
    mini_db['room'] = []
    for i in range(5):
        mini_db['room'].append(LocationFactory())

    # create a bunch of clusters
    mini_db['cluster'] = []
    for i in range(3):
        mini_db['cluster'].append(MhClusterFactory())

    db.session.commit()

    role_p1 = Role.create(location=mini_db['room'][0],
            ca=mini_db['ca'][0],
            cluster=mini_db['cluster'][0],
            name='experimental')
    role_p2 = Role.create(location=mini_db['room'][0],
            ca=mini_db['ca'][1],
            cluster=mini_db['cluster'][0],
            name='experimental')
    role_p3 = Role.create(location=mini_db['room'][0],
            ca=mini_db['ca'][2],
            cluster=mini_db['cluster'][0],
            name='primary')

    db.session.commit()

    return mini_db
コード例 #4
0
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()
            Need.objects.all().delete()
            Location.objects.all().delete()
            Topics.objects.all().delete()

            # delete geographic information
            Country.objects.all().delete()
            Region.objects.all().delete()
            Area.objects.all().delete()
            Place.objects.all().delete()

            User.objects.filter().exclude(is_superuser=True).delete()

        # create regional data
        places = list()
        for i in range(0, 10):
            places.append(PlaceFactory.create())

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                topic = TopicFactory.create(title=random.choice(HELPTOPICS))
                location = LocationFactory.create(
                    name="Shelter" + str(random.randint(0, 9)),
                    place=places[random.randint(0,
                                                len(places) - 1)],
                    additional_info=LOREM)
                need = NeedFactory.create(starting_time=self.gen_date(hour=i -
                                                                      1,
                                                                      day=day),
                                          ending_time=self.gen_date(hour=i,
                                                                    day=day),
                                          topic=topic,
                                          location=location)
                # assign random volunteer for each need
                reg_user = ShiftHelperFactory.create(need=need)
                reg_user.save()
コード例 #5
0
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()
            Need.objects.all().delete()
            Location.objects.all().delete()
            Topics.objects.all().delete()

            # delete geographic information
            Country.objects.all().delete()
            Region.objects.all().delete()
            Area.objects.all().delete()
            Place.objects.all().delete()

            User.objects.filter().exclude(is_superuser=True).delete()

        # create regional data
        places = list()
        for i in range(0,10):
            places.append(PlaceFactory.create())

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                topic = TopicFactory.create(title=random.choice(HELPTOPICS))
                location = LocationFactory.create(
                    name="Shelter" + str(random.randint(0,9)),
                    place=places[random.randint(0,len(places)-1)],
                    additional_info=LOREM
                )
                need = NeedFactory.create(
                    starting_time=self.gen_date(hour=i-1, day=day),
                    ending_time=self.gen_date(hour=i, day=day),
                    topic=topic,
                    location=location
                )
                # assign random volunteer for each need
                reg_user = ShiftHelperFactory.create(need=need)
                reg_user.save()
コード例 #6
0
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()
            Need.objects.all().delete()
            Location.objects.all().delete()
            Topics.objects.all().delete()
            User.objects.filter().exclude(is_superuser=True).delete()

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                topic = TopicFactory.create(title=random.choice(HELPTOPICS))
                location = LocationFactory.create(name="Shelter" + str(random.randint(0,9)), additional_info=LOREM)
                need = NeedFactory.create(
                    starting_time=self.gen_date(hour=i-1, day=day),
                    ending_time=self.gen_date(hour=i, day=day),
                    topic=topic,
                    location=location
                )
                # assign random volunteer for each need
                reg_user = RegistrationProfileFactory.create()
                reg_user.needs.add(need)
                reg_user.save()
コード例 #7
0
ファイル: test_update.py プロジェクト: olzhasar/covidmap
 def locations(self):
     return [
         LocationFactory(id=1, minzdrav_name="Алматы"),
         LocationFactory(id=2, minzdrav_name="Астана"),
         LocationFactory(id=3, minzdrav_name="Шымкент"),
     ]