-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
403f807
commit 8d03788
Showing
4 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
from django.test import Client, override_settings | ||
import factory | ||
from registration.forms import User | ||
|
||
from openra import content | ||
from openra.models import Reports | ||
from openra.tests.factories import MapsFactory, ReportsFactory, ScreenshotsFactory, UserFactory | ||
from openra.tests.routes.test_route_base import TestRouteBase | ||
|
||
|
||
class TestRouteMapsUpdateMapInfo(TestRouteBase): | ||
|
||
_route = '/maps/{}/update-map-info' | ||
|
||
def test_route_can_be_accessed_by_any_user(self): | ||
map = MapsFactory() | ||
response = self.get_authed( | ||
{}, | ||
None, | ||
self._route.format(map.id) | ||
) | ||
|
||
self.assertEquals( | ||
302, | ||
response.status_code | ||
) | ||
|
||
self.assertEquals( | ||
'/maps/' + str(map.id), | ||
response.url | ||
) | ||
|
||
@override_settings(SITE_MAINTENANCE=True) | ||
def test_route_shows_maintenance_page(self): | ||
map = MapsFactory() | ||
self.assert_is_maintenance( | ||
self.get( | ||
{}, | ||
self._route.format(map.id) | ||
), | ||
) | ||
|
||
def test_route_redirects_to_login_if_not_authed(self): | ||
map = MapsFactory() | ||
|
||
response = self.get( | ||
{}, | ||
self._route.format(map.id) | ||
) | ||
|
||
self.assertEquals( | ||
302, | ||
response.status_code | ||
) | ||
|
||
self.assertEquals( | ||
'/login/', | ||
response.url | ||
) | ||
|
||
def test_map_info_can_be_updated_by_map_uploader(self): | ||
user = UserFactory() | ||
|
||
map = MapsFactory( | ||
user=user | ||
) | ||
|
||
response = self.post_authed( | ||
{ | ||
'mapInfo': 'new map info', | ||
}, | ||
user, | ||
self._route.format(map.id) | ||
) | ||
|
||
map.refresh_from_db() | ||
|
||
self.assertEquals( | ||
'new map info', | ||
map.info | ||
) | ||
|
||
self.assertEquals( | ||
302, | ||
response.status_code | ||
) | ||
|
||
self.assertEquals( | ||
'/maps/' + str(map.id), | ||
response.url | ||
) | ||
|
||
def test_map_info_can_be_updated_by_a_superuser(self): | ||
user = UserFactory( | ||
is_superuser=True | ||
) | ||
|
||
map = MapsFactory() | ||
|
||
response = self.post_authed( | ||
{ | ||
'mapInfo': 'new map info', | ||
}, | ||
user, | ||
self._route.format(map.id) | ||
) | ||
|
||
map.refresh_from_db() | ||
|
||
self.assertEquals( | ||
'new map info', | ||
map.info | ||
) | ||
|
||
self.assertEquals( | ||
302, | ||
response.status_code | ||
) | ||
|
||
self.assertEquals( | ||
'/maps/' + str(map.id), | ||
response.url | ||
) | ||
|
||
def test_map_info_cannot_be_updated_by_other_users(self): | ||
user = UserFactory() | ||
|
||
map = MapsFactory() | ||
|
||
response = self.post_authed( | ||
{ | ||
'mapInfo': 'new map info', | ||
}, | ||
user, | ||
self._route.format(map.id) | ||
) | ||
|
||
map.refresh_from_db() | ||
|
||
self.assertNotEquals( | ||
'new map info', | ||
map.info | ||
) | ||
|
||
self.assertEquals( | ||
302, | ||
response.status_code | ||
) | ||
|
||
self.assertEquals( | ||
'/maps/' + str(map.id), | ||
response.url | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters