Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ciudadanointeligente/write-it int…
Browse files Browse the repository at this point in the history
…o subdomains_second_approach
  • Loading branch information
Felipe Álvarez committed Jul 23, 2013
2 parents 4ca08df + d854321 commit 833af97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nuntium/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ class Meta:

def hydrate(self, bundle):
persons = []
for popit_url in bundle.data['persons']:
persons.append(Person.objects.get(popit_url=popit_url))
if bundle.data['persons'] == 'all':
instance = WriteItInstanceResource().get_via_uri(bundle.data["writeitinstance"])
for person in instance.persons.all():
persons.append(person)
else:
for popit_url in bundle.data['persons']:
persons.append(Person.objects.get(popit_url=popit_url))
bundle.obj.persons = persons
bundle.obj.confirmated = True
return bundle
Expand Down
22 changes: 22 additions & 0 deletions nuntium/tests/api_messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ def test_create_a_new_message_confirmated(self):
self.assertTrue(the_message.confirmated)


def test_create_a_new_message_to_all_persons_in_the_instance(self):
#here it is the thing I don't know yet how to do this and I'll go for
#saying all in the persons array instead of having an array or an empty
writeitinstance = WriteItInstance.objects.all()[0]
message_data = {
'author_name' : 'Felipipoo',
'subject': 'new message',
'content': 'the content thing',
'writeitinstance': '/api/v1/instance/{0}/'.format(writeitinstance.id),
'persons': "all"
}
url = '/api/v1/message/'
response = self.api_client.post(url, data = message_data, format='json', authentication=self.get_credentials())

the_message = Message.objects.get(author_name='Felipipoo')

self.assertEquals(len(the_message.people), writeitinstance.persons.count())
self.assertEquals(the_message.people,list(writeitinstance.persons.all()))




# def test_get_message_detail_that_was_created_using_the_api(self):
# writeitinstance = WriteItInstance.objects.all()[0]
# message_data = {
Expand Down

0 comments on commit 833af97

Please sign in to comment.