Esempio n. 1
0
 def create_countries():
     """Populate the DB with countries."""
     for iso_code, _ in ISO_3166_COUNTRIES:
         Country.objects.get_or_create(
             iso_code=iso_code,
             defaults=Country.fields_from_iso_code(iso_code)
         )
 def location_data(location_tree):
     if location_tree is None:
         return []
     iso_code = find_text(location_tree, 'iso_code').lower()
     country, created = Country.objects.get_or_create(**Country.fields_from_iso_code(iso_code))
     country = country.id
     latitude = find_text(location_tree, 'latitude') or 0
     longitude = find_text(location_tree, 'longitude') or 0
     primary = True
     return [dict(latitude=latitude, longitude=longitude, country=country, primary=primary)]
Esempio n. 3
0
 def location_data(location_tree):
     if location_tree is None:
         return []
     iso_code = find_text(location_tree, 'iso_code').lower()
     country, created = Country.objects.get_or_create(**Country.fields_from_iso_code(iso_code))
     country = country.id
     latitude = find_text(location_tree, 'latitude') or 0
     longitude = find_text(location_tree, 'longitude') or 0
     primary = True
     return [dict(latitude=latitude, longitude=longitude, country=country, primary=primary)]
    def test_should_create_organisation_location(self):
        # Given
        country, _ = Country.objects.get_or_create(
            **Country.fields_from_iso_code('ng'))
        url = '/rest/v1/organisation_location/?format=json'
        data = {
            "latitude": 6.275766,
            "longitude": 7.006839,
            "city": "Ukpo",
            "location_target": self.org.id,
            "iati_country": "NG",
            "country": country.pk,
            "postcode": "101010"
        }

        # When
        response = self.c.post(url, data)

        # Then
        self.assertEqual(response.status_code, 201)
        for key in data:
            self.assertEqual(data[key], response.data[key],
                             '{} has diefferent values'.format(key))
Esempio n. 5
0
def populate_test_data(seed=42):
    """Populate the DB for tests using the factories defined."""

    reseed_random(seed)
    random.seed(seed)

    check_auth_groups(settings.REQUIRED_AUTH_GROUPS)

    UserFactory.create(is_admin=True, is_superuser=True, is_staff=True)
    UserFactory.create_batch(4)
    OrganisationFactory.create_batch(3)
    OrganisationCustomFieldFactory.create_batch(9)

    ProjectFactory.create_batch(10)
    RecipientCountryFactory.create_batch(10)
    CrsAddFactory.create_batch(10)
    FssFactory.create_batch(10)
    PartnershipFactory.create_batch(10)

    ProjectCustomFieldFactory.create_batch(20)
    ProjectCommentFactory.create_batch(20)
    RelatedProjectFactory.create_batch(10)

    ProjectUpdateFactory.create_batch(100)
    ResultFactory.create_batch(40)
    IndicatorFactory.create_batch(80)
    IndicatorReferenceFactory.create_batch(80)
    IndicatorPeriodFactory.create_batch(240)
    IndicatorPeriodActualDimensionFactory.create_batch(240)
    IndicatorPeriodTargetDimensionFactory.create_batch(240)
    IndicatorPeriodActualLocationFactory.create_batch(240)
    IndicatorPeriodTargetLocationFactory.create_batch(240)
    IndicatorPeriodDataFactory.create_batch(1200)
    IndicatorPeriodDataCommentFactory.create_batch(1200)

    IatiExportFactory.create_batch(3)
    IatiImportFactory.create_batch(3)

    for _ in range(10):
        created = False
        while not created:
            country_code = random.choice(ISO_3166_COUNTRIES)[0]
            country_info = Country.fields_from_iso_code(country_code)
            country, created = Country.objects.get_or_create(**country_info)

    EmploymentFactory.create_batch(30)

    KeywordFactory.create_batch(20)
    for keyword in Keyword.objects.all():
        for project in Project.objects.all():
            if keyword.id % project.id != 0:
                continue
            project.keywords.add(keyword)

    ProjectEditorValidationSetFactory.create_batch(2)
    ProjectEditorValidationFactory.create_batch(20)

    ReportFormatFactory.create_batch(4)
    ReportFactory.create_batch(4)

    # FIXME: Enforce this!
    verify_model_instances()
Esempio n. 6
0
def populate_test_data(seed=42):
    """Populate the DB for tests using the factories defined."""

    reseed_random(seed)
    random.seed(seed)

    check_auth_groups(settings.REQUIRED_AUTH_GROUPS)

    UserFactory.create(is_admin=True, is_superuser=True, is_staff=True)
    UserFactory.create_batch(4)
    OrganisationFactory.create_batch(3)
    OrganisationCustomFieldFactory.create_batch(9)

    ProjectFactory.create_batch(10)
    RecipientCountryFactory.create_batch(10)
    CrsAddFactory.create_batch(10)
    FssFactory.create_batch(10)
    PartnershipFactory.create_batch(10)

    ProjectCustomFieldFactory.create_batch(20)
    ProjectCommentFactory.create_batch(20)
    RelatedProjectFactory.create_batch(10)

    ProjectUpdateFactory.create_batch(100)
    ResultFactory.create_batch(40)
    IndicatorFactory.create_batch(80)
    IndicatorReferenceFactory.create_batch(80)
    IndicatorPeriodFactory.create_batch(240)
    IndicatorPeriodActualDimensionFactory.create_batch(240)
    IndicatorPeriodTargetDimensionFactory.create_batch(240)
    IndicatorPeriodActualLocationFactory.create_batch(240)
    IndicatorPeriodTargetLocationFactory.create_batch(240)
    IndicatorPeriodDataFactory.create_batch(1200)
    IndicatorPeriodDataCommentFactory.create_batch(1200)

    IatiExportFactory.create_batch(3)
    IatiImportFactory.create_batch(3)

    for _ in range(10):
        created = False
        while not created:
            country_code = random.choice(ISO_3166_COUNTRIES)[0]
            country_info = Country.fields_from_iso_code(country_code)
            country, created = Country.objects.get_or_create(**country_info)

    EmploymentFactory.create_batch(30)

    KeywordFactory.create_batch(20)
    for keyword in Keyword.objects.all():
        for project in Project.objects.all():
            if keyword.id % project.id != 0:
                continue
            project.keywords.add(keyword)

    ProjectEditorValidationSetFactory.create_batch(2)
    ProjectEditorValidationFactory.create_batch(20)

    ReportFormatFactory.create_batch(4)
    ReportFactory.create_batch(4)

    # FIXME: Enforce this!
    verify_model_instances()
Esempio n. 7
0
 def create_countries():
     """Populate the DB with countries."""
     for iso_code, _ in ISO_3166_COUNTRIES:
         Country.objects.get_or_create(
             iso_code=iso_code,
             defaults=Country.fields_from_iso_code(iso_code))