def test_merge_basic_model(self):
        primary_object = PlaceFactory.create(address=None)
        alias_object = PlaceFactory.create()

        merged_object = MergedModelInstance.create(primary_object,
                                                   [alias_object])

        assert merged_object.address == alias_object.address
    def test_dedupe_basic_model_no_merge(self):
        primary_object = PlaceFactory.create(address=None)
        alias_object = PlaceFactory.create()

        merged_object = MergedModelInstance.create(primary_object,
                                                   [alias_object],
                                                   merge_field_values=False)

        assert merged_object.address == primary_object.address
    def test_merge_deletes_alias_objects(self):
        primary_object = PlaceFactory.create(address=None)
        alias_object = PlaceFactory.create()

        assert primary_object.address is None
        assert PlaceFactory._meta.model.objects.filter(
            pk=alias_object.pk).exists()

        merged_object = MergedModelInstance.create(primary_object,
                                                   [alias_object],
                                                   keep_old=False)

        assert merged_object.address == alias_object.address
        assert not PlaceFactory._meta.model.objects.filter(
            pk=alias_object.pk).exists()
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()

            Shift.objects.all().delete()
            Task.objects.all().delete()
            Workplace.objects.all().delete()
            Facility.objects.all().delete()

            UserAccount.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())

        organizations = list()
        for i in range(0, 4):
            organizations.append(OrganizationFactory.create())

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                place = places[random.randint(0, len(places) - 1)]
                organization = organizations[random.randint(0, len(organizations) - 1)]
                facility = FacilityFactory.create(
                    description=LOREM,
                    place=place,
                    organization=organization
                )
                shift = ShiftFactory.create(
                    starting_time=gen_date(hour=i - 1, day=day),
                    ending_time=gen_date(hour=i, day=day),
                    facility=facility
                )
                # assign random volunteer for each shift
                reg_user = ShiftHelperFactory.create(shift=shift)
                reg_user.save()
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()

            Shift.objects.all().delete()
            Task.objects.all().delete()
            Workplace.objects.all().delete()
            Facility.objects.all().delete()

            UserAccount.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())

        organizations = list()
        for i in range(0, 4):
            organizations.append(OrganizationFactory.create())

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                place = places[random.randint(0, len(places) - 1)]
                organization = organizations[random.randint(
                    0,
                    len(organizations) - 1)]
                facility = FacilityFactory.create(description=LOREM,
                                                  place=place,
                                                  organization=organization)
                shift = ShiftFactory.create(starting_time=gen_date(hour=i - 1,
                                                                   day=day),
                                            ending_time=gen_date(hour=i,
                                                                 day=day),
                                            facility=facility)
                # assign random volunteer for each shift
                reg_user = ShiftHelperFactory.create(shift=shift)
                reg_user.save()
Example #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()

            # 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()
    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()
    def test_prevent_self_merge(self):
        primary_object = PlaceFactory.create(address=None)
        alias_object = primary_object

        with pytest.raises(ValueError):
            MergedModelInstance.create(primary_object, [alias_object])