Skip to content

Commit

Permalink
Merge pull request #4 from csparpa/dev
Browse files Browse the repository at this point in the history
Release 0.2
  • Loading branch information
csparpa committed Feb 4, 2017
2 parents c7801a3 + abdeed8 commit c86df22
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 42 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ A Django ORM interface for PyOWM domain entities
Python 2.7 is supported.


** Please notice that the API can be unstable as this project is still in beta testing **

## Install

Install the library with `pip`:
Expand Down Expand Up @@ -73,4 +75,4 @@ original_obs = m.to_entity()
```

## Testing
All details in file [docs/testing.md](docs/testing.md)
All details about testing are [here](https://github.com/csparpa/django-pyowm/wiki/Testing)
34 changes: 21 additions & 13 deletions django_pyowm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ def save_all(self):
Saves this model along with all related ones.
:return: None
"""
self.location.save()
self.weather.save()
location = self.location
weather = self.weather
location.save()
weather.save()
self.location = location
self.weather = weather
self.save()

class Meta:
Expand Down Expand Up @@ -265,13 +269,9 @@ def save_all(self):
Saves this model along with all related ones.
:return: None
"""
self.location.save()
weats = self.weathers
self.weathers = []
self.save()
for w in weats:
w.save()
self.weathers = weats
location = self.location
location.save()
self.location = location
self.save()

class Meta:
Expand Down Expand Up @@ -353,7 +353,9 @@ def save_all(self):
Saves this model along with all related ones.
:return: None
"""
self.last_weather.save()
last_weather = self.last_weather
last_weather.save()
self.last_weather = last_weather
self.save()

class Meta:
Expand Down Expand Up @@ -489,7 +491,9 @@ def save_all(self):
Saves this model along with all related ones.
:return: None
"""
self.location.save()
location = self.location
location.save()
self.location = location
self.save()

class Meta:
Expand Down Expand Up @@ -564,7 +568,9 @@ def save_all(self):
Saves this model along with all related ones.
:return: None
"""
self.location.save()
location = self.location
location.save()
self.location = location
self.save()

class Meta:
Expand Down Expand Up @@ -639,7 +645,9 @@ def save_all(self):
Saves this model along with all related ones.
:return: None
"""
self.location.save()
location = self.location
location.save()
self.location = location
self.save()

class Meta:
Expand Down
95 changes: 94 additions & 1 deletion django_pyowm/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pyowm.webapi25.uvindex import UVIndex as UVIndexEntity
from pyowm.webapi25.coindex import COIndex as COIndexEntity
from pyowm.webapi25.ozone import Ozone as OzoneEntity
from .models import Location, Weather, Observation, Forecast, Station, \
from django_pyowm.models import Location, Weather, Observation, Forecast, Station, \
StationHistory, UVIndex, COIndex, Ozone


Expand Down Expand Up @@ -305,6 +305,21 @@ def test_to_entity(self):
Asserter.assertWeatherEntitiesEqual(self, expected.get_weather(),
result.get_weather())

def test_save_all(self):
location = Location.from_entity(Databox.location)
weather = Weather.from_entity(Databox.weather)
observation = Observation(reception_time=Databox.reception_time,
location=location,
weather=weather)
self.assertIsNone(location.pk)
self.assertIsNone(weather.pk)
self.assertIsNone(observation.pk)

observation.save_all()
self.assertIsNotNone(location.pk)
self.assertIsNotNone(weather.pk)
self.assertIsNotNone(observation.pk)


class TestForecastModel(TestCase):

Expand Down Expand Up @@ -339,6 +354,23 @@ def test_to_entity(self):
for ex_w, res_w in zip(expected.get_weathers(), result.get_weathers()):
Asserter.assertWeatherEntitiesEqual(self, ex_w, res_w)

def test_save_all(self):
weathers = [Weather.from_entity(w) for w in Databox.weathers]
location = Location.from_entity(Databox.location)
forecast = Forecast(interval=Databox.interval,
reception_time=Databox.reception_time,
location=location)
self.assertIsNone(location.pk)
for w in weathers:
self.assertIsNone(w.pk)
self.assertIsNone(forecast.pk)

for w in weathers:
w.save()
forecast.save_all()
self.assertIsNotNone(location.pk)
self.assertIsNotNone(forecast.pk)


class TestStationModel(TestCase):

Expand Down Expand Up @@ -381,6 +413,22 @@ def test_to_entity(self):
Asserter.assertWeatherEntitiesEqual(self, expected.get_last_weather(),
result.get_last_weather())

def test_save_all(self):
last_weather = Weather.from_entity(Databox.weather)
station = Station(name=Databox.station_name,
station_id=Databox.station_id,
station_type=Databox.station_type,
station_status=Databox.station_status,
lat=Databox.lat, lon=Databox.lon,
distance=Databox.station_distance,
last_weather=last_weather)
self.assertIsNone(last_weather.pk)
self.assertIsNone(station.pk)

station.save_all()
self.assertIsNotNone(last_weather.pk)
self.assertIsNotNone(station.pk)


class TestStationHistoryModel(TestCase):

Expand Down Expand Up @@ -442,6 +490,21 @@ def test_to_entity(self):
Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
result.get_location())

def test_save_all(self):
location = Location.from_entity(Databox.location)
uvindex = UVIndex(
reference_time=Databox.reference_time,
location=location,
value=Databox.uvindex_intensity,
interval=Databox.uvindex_interval,
reception_time=Databox.reception_time)
self.assertIsNone(location.pk)
self.assertIsNone(uvindex.pk)

uvindex.save_all()
self.assertIsNotNone(location.pk)
self.assertIsNotNone(uvindex.pk)


class TestCOIndexModel(TestCase):

Expand Down Expand Up @@ -475,6 +538,21 @@ def test_to_entity(self):
Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
result.get_location())

def test_save_all(self):
location = Location.from_entity(Databox.location)
coindex = COIndex(
reference_time=Databox.reference_time,
location=location,
interval=Databox.coindex_interval,
reception_time=Databox.reception_time,
co_samples=json.dumps(Databox.co_samples))
self.assertIsNone(location.pk)
self.assertIsNone(coindex.pk)

coindex.save_all()
self.assertIsNotNone(location.pk)
self.assertIsNotNone(coindex.pk)


class TestOzoneModel(TestCase):

Expand Down Expand Up @@ -507,3 +585,18 @@ def test_to_entity(self):
self.assertEquals(expected.get_reception_time(), result.get_reception_time())
Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
result.get_location())

def test_save_all(self):
location = Location.from_entity(Databox.location)
ozone = Ozone(
reference_time=Databox.reference_time,
location=location,
du_value=Databox.du_value,
interval=Databox.ozone_interval,
reception_time=Databox.reception_time)
self.assertIsNone(location.pk)
self.assertIsNone(ozone.pk)

ozone.save_all()
self.assertIsNotNone(location.pk)
self.assertIsNotNone(ozone.pk)
12 changes: 12 additions & 0 deletions docs/releasing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
https://github.com/csparpa/django-pyowm

Checklist:

- write new models / patch existing ones
- write / patch tests
-
- update setup.py
- merge develop branch into master branch (no feature/hotfix branches left open)
- handle github stuff (issues, PRs, etc..)
- tag release on github
- generate and upload release on pypi
43 changes: 43 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Testing

## How to run tests

As `django_pyowm` is a Django app, it must be tested against a Django project, so we will create one.

First of all you need to have the app installed in your `PYTHONPATH`.
Then create a test Django project and a test Django app with:

```shell
$ django-admin startproject testproject
$ cd testproject
$ django-admin startapp testapp
```

Then edit your `INSTALLED_APPS` in file `testproject/testproject/settings.py`

```python
INSTALLED_APPS = [
...
'testapp',
'django_pyowm'
]
```

Now copy the content of file `django_pyowm/django_pyowm/tests.py` into file `testproject/testapp/tests.py`

Apply migrations with:

```
$ cd testproject
$ python manage.py makemigrations django_pyowm
$ python manage.py migrate
```

Finally launch the tests with:

```
$ python manage.py test
```

## Good reads
http://joebergantine.com/blog/2015/dec/03/test-reusable-django-application-support-multiple-/
26 changes: 0 additions & 26 deletions runtests.py

This file was deleted.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
author='Claudio Sparpaglione',
author_email='csparpa@gmail.com',
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.10',
Expand All @@ -37,5 +38,5 @@
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
]
)

0 comments on commit c86df22

Please sign in to comment.