コード例 #1
0
    def test_parse_city(self):

        response = '''
            {"response":[
                {"cid":1,"title":"Москва","region":"Regione Abruzzo область"},
                {"cid":1074996,"title":"Москва","area":"Порховский район","region":"Псковская область"},
                {"cid":1102561,"title":"Москва","area":"Пеновский район","region":"Тверская область"},
                {"cid":1130701,"title":"Москва","area":"Верхошижемский район","region":"Кировская область"}
            ]}
            '''
        country = CountryFactory.create(remote_id=1)
        instance = City(country=country)
        instance.parse(json.loads(response)['response'][0])
        instance.save()

        self.assertEqual(instance.remote_id, 1)
        self.assertEqual(instance.name, u'Москва')

        instance = City(country=country)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, 1074996)
        self.assertEqual(instance.name, u'Москва')
        self.assertEqual(instance.area, u"Порховский район")
        self.assertEqual(instance.region, u"Псковская область")
コード例 #2
0
    def test_parse_city(self):

        response = '''
            {"response":[
                {"cid":1,"title":"Москва","region":"Regione Abruzzo область"},
                {"cid":1074996,"title":"Москва","area":"Порховский район","region":"Псковская область"},
                {"cid":1102561,"title":"Москва","area":"Пеновский район","region":"Тверская область"},
                {"cid":1130701,"title":"Москва","area":"Верхошижемский район","region":"Кировская область"}
            ]}
            '''
        country = CountryFactory.create(remote_id=1)
        instance = City(country=country)
        instance.parse(json.loads(response)['response'][0])
        instance.save()

        self.assertEqual(instance.remote_id, 1)
        self.assertEqual(instance.name, u'Москва')

        instance = City(country=country)
        instance.parse(json.loads(response)['response'][1])
        instance.save()

        self.assertEqual(instance.remote_id, 1074996)
        self.assertEqual(instance.name, u'Москва')
        self.assertEqual(instance.area, u"Порховский район")
        self.assertEqual(instance.region, u"Псковская область")
コード例 #3
0
    def setUp(self):
        super(TestProfileUpdates, self).setUp()

        self.afghanistan = CountryFactory(country='Afghanistan', code='AF')
        self.myanmar = CountryFactory(country='Myanmar', code='MM')
        self.usa = CountryFactory(country='United States', code='US')

        self.user = UserFactory(first_name="FN",
                                last_name="LN",
                                username="******")
        self.user.set_password('password')
        self.user.save()
        self.tola_user = TolaUserFactory(user=self.user, country=self.usa)
        self.tola_user.countries.add(self.afghanistan, self.usa)
        self.tola_user.save()

        self.countries_assigned = {self.afghanistan.id, self.usa.id}
コード例 #4
0
    def setUp(self):
        super(TestProjectCountryUserAccess, self).setUp()

        # create and login user
        self.user = UserFactory(first_name="FN",
                                last_name="LN",
                                username="******")
        self.user.set_password('password')
        self.user.save()

        self.tola_user = TolaUserFactory(user=self.user)

        self.client.login(username="******", password='******')

        self.afghanistan = CountryFactory(country='Afghanistan', code='AF')
コード例 #5
0
    def test_fetch_cities(self):

        self.assertEqual(City.objects.count(), 0)

        country = CountryFactory.create(remote_id=1)

        City.remote.fetch(country=country.remote_id)
        self.assertEqual(City.objects.count(), 18)
        self.assertEqual(City.objects.all()[0].country, country)

        City.remote.fetch(country=country)
        self.assertEqual(City.objects.count(), 18)

        City.objects.all().delete()
        City.remote.fetch(country=country, q=u'Москва')
        self.assertTrue(City.objects.count() > 1)
コード例 #6
0
    def test_fetch_cities(self):

        self.assertEqual(City.objects.count(), 0)

        country = CountryFactory.create(remote_id=1)

        City.remote.fetch(country=country.remote_id)
        self.assertEqual(City.objects.count(), 18)
        self.assertEqual(City.objects.all()[0].country, country)

        City.remote.fetch(country=country)
        self.assertEqual(City.objects.count(), 18)

        City.objects.all().delete()
        City.remote.fetch(country=country, q=u'Москва')
        self.assertTrue(City.objects.count() > 1)