Example #1
0
 def test_delete_client_cascade(self) -> None:
     """Add a new user, client, and session. Remove user to clear client and session."""
     assert User.count() == 4 and Client.count() == 4 and Session.count(
     ) == 4
     user = User.add({
         'first_name': 'James',
         'last_name': 'Bond',
         'email': '*****@*****.**',
         'alias': '007',
         'data': {
             'user_type': 'amateur',
             'drink_of_choice': 'martini'
         }
     })
     assert User.count() == 5 and Client.count() == 4 and Session.count(
     ) == 4
     Client.new(user.id)
     assert User.count() == 5 and Client.count() == 5 and Session.count(
     ) == 4
     Session.new(user.id)
     assert User.count() == 5 and Client.count() == 5 and Session.count(
     ) == 5
     User.delete(user.id)
     assert User.count() == 4 and Client.count() == 4 and Session.count(
     ) == 4
Example #2
0
 def test_delete_facility_map_cascade(self) -> None:
     """Create a new user, with facility, then remove."""
     assert User.count() == 4 and Facility.count(
     ) == 4 and FacilityMap.count() == 4
     User.add({
         'first_name': 'James',
         'last_name': 'Bond',
         'email': '*****@*****.**',
         'alias': '007',
         'data': {
             'user_type': 'amateur',
             'drink_of_choice': 'martini'
         }
     })
     user = User.from_alias('007')
     Facility.add({
         'name': 'Bond_4m',
         'latitude': -25.5,
         'longitude': -69.25,
         'elevation': 5050,
         'limiting_magnitude': 17.5,
         'data': {
             'telescope_design': 'reflector'
         }
     })
     facility = Facility.from_name('Bond_4m')
     user.add_facility(facility.id)
     assert user.facilities()[0].to_dict() == facility.to_dict()
     assert User.count() == 5 and Facility.count(
     ) == 5 and FacilityMap.count() == 5
     User.delete(user.id)
     assert User.count() == 4 and Facility.count(
     ) == 5 and FacilityMap.count() == 4
     Facility.delete(facility.id)
     assert Facility.count() == 4
Example #3
0
 def test_delete(self) -> None:
     """Add a new session and remove it directly."""
     assert User.count() == 4 and Client.count() == 4 and Session.count(
     ) == 4
     user = User.add({
         'first_name': 'James',
         'last_name': 'Bond',
         'email': '*****@*****.**',
         'alias': '007',
         'data': {
             'user_type': 'amateur',
             'drink_of_choice': 'martini'
         }
     })
     assert User.count() == 5 and Client.count() == 4 and Session.count(
     ) == 4
     key, secret, client = Client.new(user.id)
     assert User.count() == 5 and Client.count() == 5 and Session.count(
     ) == 4
     Session.new(user.id)
     assert User.count() == 5 and Client.count() == 5 and Session.count(
     ) == 5
     Session.delete(Session.from_client(client.id).id)
     assert User.count() == 5 and Client.count() == 5 and Session.count(
     ) == 4
     User.delete(user.id)  # NOTE: deletes client
     assert User.count() == 4 and Client.count() == 4 and Session.count(
     ) == 4
Example #4
0
 def test_delete_user_cascade(self) -> None:
     """Add a new user and client record and then remove them."""
     assert User.count() == 4 and Client.count() == 4
     user = User.add({'first_name': 'James', 'last_name': 'Bond', 'email': '*****@*****.**',
                      'alias': '007', 'data': {'user_type': 'amateur', 'drink_of_choice': 'martini'}})
     assert User.count() == 5 and Client.count() == 4
     Client.new(user.id)
     assert User.count() == 5 and Client.count() == 5
     User.delete(user.id)
     assert User.count() == 4 and Client.count() == 4
Example #5
0
 def test_delete(self) -> None:
     """Add a new user and client. Remove the client directly."""
     assert User.count() == 4 and Client.count() == 4
     user = User.add({'first_name': 'James', 'last_name': 'Bond', 'email': '*****@*****.**',
                      'alias': '007', 'data': {'user_type': 'amateur', 'drink_of_choice': 'martini'}})
     assert User.count() == 5 and Client.count() == 4
     key, secret, client = Client.new(user.id)
     assert User.count() == 5 and Client.count() == 5
     Client.delete(client.id)
     assert User.count() == 5 and Client.count() == 4
     User.delete(user.id)
     assert User.count() == 4 and Client.count() == 4
Example #6
0
 def test_add_user(self) -> None:
     """Test adding a user and then removing it."""
     facility = Facility.from_name('Croft_4m')
     users = facility.users()
     assert len(users) == 1 and users[0].alias == 'tomb_raider'
     User.add({'first_name': 'James', 'last_name': 'Bond', 'email': '*****@*****.**',
               'alias': '007', 'data': {'user_type': 'amateur', 'drink_of_choice': 'martini'}})
     new_user = User.from_alias('007')
     facility.add_user(new_user.id)
     users = facility.users()
     assert len(users) == 2 and set(u.alias for u in users) == {'tomb_raider', '007'}
     User.delete(new_user.id)
     users = facility.users()
     assert len(users) == 1 and users[0].alias == 'tomb_raider'
Example #7
0
 def test_delete(self) -> None:
     """Add a new user record and then remove it."""
     assert User.count() == 4
     User.add({
         'first_name': 'James',
         'last_name': 'Bond',
         'email': '*****@*****.**',
         'alias': '007',
         'data': {
             'user_type': 'amateur',
             'drink_of_choice': 'martini'
         }
     })
     assert User.count() == 5
     assert User.from_alias('007').last_name == 'Bond'
     User.delete(User.from_alias('007').id)
     assert User.count() == 4
Example #8
0
 def test_delete_missing(self) -> None:
     """Test exception on attempt to delete non-existent user."""
     with pytest.raises(NotFound):
         User.delete(-1)